From 256dc432f83415dac3ed4485e21ebc1ed0e045a8 Mon Sep 17 00:00:00 2001 From: Shannon Appelcline Date: Wed, 24 May 2017 13:40:55 -0700 Subject: [PATCH] Update 8_1_Understanding_the_Foundation_of_P2SH.md --- 8_1_Understanding_the_Foundation_of_P2SH.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/8_1_Understanding_the_Foundation_of_P2SH.md b/8_1_Understanding_the_Foundation_of_P2SH.md index a81ae22..27149b8 100644 --- a/8_1_Understanding_the_Foundation_of_P2SH.md +++ b/8_1_Understanding_the_Foundation_of_P2SH.md @@ -78,6 +78,18 @@ You create hexcode by stepping through your locking script and turning each elem * Larger constants are translated into 0x01 to 0x4e (OP_PUSHDATA, including a specification of how many bytes to push) * Operators are translated to the matching byte for that opcode +The constants are the most troublesome part. Often you'll need to translate decimals into hexidecimals. This can be done with the `printf` command: +``` +$ decimal=1546288031 +$ hex=(printf '%x\n' $decimal) +$ echo $hex +5c2a7b9f +``` +And you'll always need to know the size of your constants. You can just remember that every two hexidecimal characters is one byte. Or, you can use `echo -n` piped to `wc -c`, and divide that in two: +``` +user1@blockstream:~$ echo -n $hex | wc -c +8 +``` #### Create the Hex Code: A Multisig Example It may be easier to understand this by taking an existing hexcode and translating it back to Bitcoin Script. For example, look at the `redeemScript` that you used [ยง6.1](6_1_Sending_a_Transaction_to_a_Multisig.md):