From 173ae6cdc6cfbc27849d6ea327d6d63b224a8e41 Mon Sep 17 00:00:00 2001 From: Shannon Appelcline Date: Fri, 26 May 2017 15:54:08 -0700 Subject: [PATCH] Update 8_1_Understanding_the_Foundation_of_P2SH.md --- 8_1_Understanding_the_Foundation_of_P2SH.md | 69 +-------------------- 1 file changed, 1 insertion(+), 68 deletions(-) diff --git a/8_1_Understanding_the_Foundation_of_P2SH.md b/8_1_Understanding_the_Foundation_of_P2SH.md index 602028b..c3812f9 100644 --- a/8_1_Understanding_the_Foundation_of_P2SH.md +++ b/8_1_Understanding_the_Foundation_of_P2SH.md @@ -89,73 +89,6 @@ Whereas you can't easily create a P2SH transaction, you should be able to easily ## Summary: Understanding the Foundation of P2SH -Arbitrary Bitcoin Scripts are non-standard in Bitcoin. However, you can incorporate them into standard transactions by using the P2SH address type. You just hash your script as part of the locking script, then you reveal and run it as part of the unlocking script. As long as you can also satisfy the script, the UTXO can be spent. Mind you, this is all somewhat more theoretical than previous sections, because it isn't easy to create redeemScripts by hand, nor is it possible to incorporate them into transactions using `bitcoin-cli`. +Arbitrary Bitcoin Scripts are non-standard in Bitcoin. However, you can incorporate them into standard transactions by using the P2SH address type. You just hash your script as part of the locking script, then you reveal and run it as part of the unlocking script. As long as you can also satisfy the script, the UTXO can be spent. _What is the power of P2SH?_ You already know the power of Bitcoin Script, which allows you to create more complex Smart Contracts of all sorts. P2SH is what actually unleashes that power by letting you include arbitrary Bitcoin Script in standard Bitcoin transactions. - -## Appendix: The Integer Conversion Script - -The following script collects the complete methodology for changing an integer between -2147483647 and 2147483647 to a little-endian signed-magnitude representation: -``` -file: integer2lehex.sh -#!/bin/bash - -if [ -z $1 ]; -then - echo "You must include an integer as an argument."; - exit; -fi - -if (( $1 > "2147483647" )) || (( $1 < "-2147483647" )); -then - echo "Your number ($1) may not be between -2147483647 and 2147483647"; - exit; -fi - -if [ $1 -lt 0 ]; -then - integer=$(echo $((-$1))); - negative=1; -else - integer=$1; - negative=0; -fi - -hex=$(printf '%08x\n' $integer | sed 's/^\(00\)*//'); - -hexfirst=$(echo $hex | cut -c1) -[[ 0x$hexfirst -gt 0x7 ]] && hex="00"$hex - -lehex=$(echo $hex | tac -rs .. | echo "$(tr -d '\n')"); - -if [ "$negative" -eq "1" ]; -then - lehex=$(printf '%x\n' $((0x$lehex | 0x80))) -fi - -size=$(echo -n $lehex | wc -c | awk '{print $1/2}'); -hexcodeprefix=$(printf '%02x\n' $size); - -echo "Integer: $1"; -echo "LE Hex: $lehex"; -echo "Length: $size bytes"; -echo "Hexcode: $hexcodeprefix$lehex"; -``` -Be sure the permissions on the script are right: -``` -$ chmod 755 integer2lehex.sh -``` -You can then run the script as follows: -``` -$ ./integer2lehex.sh 1546288031 -Integer: 1546288031 -LE Hex: 9f7b2a5c -Length: 4 bytes -Hexcode: 049f7b2a5c - -$ ./integer2lehex.sh -1546288031 -Integer: -1546288031 -LE Hex: 9f7b2adc -Length: 4 bytes -Hexcode: 049f7b2adc -```