@@ -45,17 +45,16 @@ $ b-reg -named createwallet \
4545
4646== Fund P2QRH UTXO
4747
48- . View (hard-coded) tapscript used in single leaf taptree :
48+ . OPTIONAL: Define number of leaves in tap tree as well as the tap leaf to later use as the unlocking script :
4949+
5050-----
51- $ b-reg decodescript 206d4ddc0e47d2e8f82cbe2fc2d0d749e7bd3338112cecdc76d8f831ae6620dbe0ac | jq -r '.asm'
52-
53- 6d4ddc0e47d2e8f82cbe2fc2d0d749e7bd3338112cecdc76d8f831ae6620dbe0 OP_CHECKSIG
51+ $ export TOTAL_LEAF_COUNT=5 \
52+ && export LEAF_OF_INTEREST=4
5453-----
5554+
56- NOTE: Notice that this script commits to a Schnorr 32-byte x-only public key.
55+ NOTE: Defaults are 4 leaves with the first leaf (leaf 0 ) as the script to later use as the unlocking script.
5756
58- . Generate a P2QRH scripPubKey and address given a taptree as defined in link:https://learnmeabitcoin.com/technical/upgrades/taproot/#example-3-script-path-spend-signature[learnmeabitcoin tutorial] :
57+ . Generate a P2QRH scripPubKey with multi-leaf taptree :
5958+
6059-----
6160$ export BITCOIN_NETWORK=regtest \
@@ -67,13 +66,25 @@ NOTE: In `regtest`, you can expect a P2QRH address that starts with: `bcrt1r` .
6766+
6867NOTE: In the context of P2QRH, the _tree_root_hex_ from the response is in reference to the _quantum_root_ used in this tutorial.
6968
70- . Set some env vars (for use in later steps in this tutorial) based on previous result:
69+ . Set some env vars (for use in later steps in this tutorial) based on previous result:
70+ +
71+ -----
72+ $ export QUANTUM_ROOT=$( echo $BITCOIN_ADDRESS_INFO | jq -r '.taptree_return.tree_root_hex' ) \
73+ && export LEAF_SCRIPT_PRIV_KEY_HEX=$( echo $BITCOIN_ADDRESS_INFO | jq -r '.taptree_return.leaf_script_priv_key_hex' ) \
74+ && export LEAF_SCRIPT_HEX=$( echo $BITCOIN_ADDRESS_INFO | jq -r '.taptree_return.leaf_script_hex' ) \
75+ && export CONTROL_BLOCK_HEX=$( echo $BITCOIN_ADDRESS_INFO | jq -r '.taptree_return.control_block_hex' ) \
76+ && export FUNDING_SCRIPT_PUBKEY=$( echo $BITCOIN_ADDRESS_INFO | jq -r '.utxo_return.script_pubkey_hex' ) \
77+ && export P2QRH_ADDR=$( echo $BITCOIN_ADDRESS_INFO | jq -r '.utxo_return.bech32m_address' )
78+ -----
79+
80+ . View tapscript used in target leaf of taptree:
7181+
7282-----
73- $ export QUANTUM_ROOT=$( echo $BITCOIN_ADDRESS_INFO | jq -r '.tree_root_hex' ) \
74- && export FUNDING_SCRIPT_PUBKEY=$( echo $BITCOIN_ADDRESS_INFO | jq -r '.script_pubkey_hex' ) \
75- && export P2QRH_ADDR=$( echo $BITCOIN_ADDRESS_INFO | jq -r '.bech32m_address' )
83+ $ b-reg decodescript $LEAF_SCRIPT_HEX | jq -r '.asm'
7684-----
85+ +
86+ NOTE: Notice that this script commits to a Schnorr 32-byte x-only public key.
87+
7788
7889. fund this P2QRH address with the coinbase reward of a newly generated block:
7990+
@@ -122,34 +133,43 @@ $ export FUNDING_UTXO_AMOUNT_SATS=$(echo $FUNDING_UTXO | jq -r '.value' | awk '{
122133 && echo $FUNDING_UTXO_AMOUNT_SATS
123134-----
124135
125- . Referencing the funding tx (via $FUNDING_TX_ID and $FUNDING_UTXO_INDEX), create the spending tx:
136+ . Generate additional blocks.
137+ +
138+ This is necessary if you have only previously generated less than 100 blocks.
126139+
127140-----
128- $ export RAW_P2QRH_SPEND_TX=$( cargo run --example p2qrh_spend | jq -r '.tx_hex' ) \
129- && echo $RAW_P2QRH_SPEND_TX
141+ $ b-reg -generate 110
130142-----
143+ +
144+ Otherwise, you may see an error from bitcoin core such as the following when attempting to spend:
145+ +
146+ _bad-txns-premature-spend-of-coinbase, tried to spend coinbase at depth 1_
131147
132- . Inspect the spending tx:
148+
149+ . Referencing the funding tx (via $FUNDING_TX_ID and $FUNDING_UTXO_INDEX), create the spending tx:
133150+
134151-----
135- $ b-reg decoderawtransaction $RAW_P2QRH_SPEND_TX
136- -----
152+ $ export SPEND_DETAILS=$( cargo run --example p2qrh_spend )
137153
138- . Test standardness of the spending tx by sending to local mempool of p2qrh enabled Bitcoin Core:
154+ $ export RAW_P2QRH_SPEND_TX=$( echo $SPEND_DETAILS | jq -r '.tx_hex' ) \
155+ && echo "RAW_P2QRH_SPEND_TX = $RAW_P2QRH_SPEND_TX" \
156+ && export SIG_HASH=$( echo $SPEND_DETAILS | jq -r '.sighash' ) \
157+ && echo "SIG_HASH = $SIG_HASH" \
158+ && export SIG_BYTES=$( echo $SPEND_DETAILS | jq -r '.sig_bytes' ) \
159+ && echo "SIG_BYTES = $SIG_BYTES"
160+ -----
139161
140- .. Generate additional blocks.
141- +
142- This is necessary if you have only previously generated 1 block.
162+ . Inspect the spending tx:
143163+
144164-----
145- $ b-reg -generate 110
165+ $ b-reg decoderawtransaction $RAW_P2QRH_SPEND_TX
146166-----
147167+
148- Otherwise, you may see an error from bitcoin core such as the following:
149- +
150- _bad-txns-premature-spend-of-coinbase, tried to spend coinbase at depth 1_
168+ Pay particular attention to the `vin.txinwitness` field.
169+ Do the three elements (script input, script and control block) of the witness stack for this script path spend make sense ?
170+ What do you observe as the first byte of the `control block` element ?
151171
152- .. Execute :
172+ . Test standardness of the spending tx by sending to local mempool of p2qrh enabled Bitcoin Core :
153173+
154174-----
155175$ b-reg testmempoolaccept '["'''$RAW_P2QRH_SPEND_TX'''"]'
0 commit comments