|
11 | 11 | "import util\n", |
12 | 12 | "from test_framework.address import program_to_witness\n", |
13 | 13 | "from test_framework.key import ECKey, ECPubKey, SECP256K1_ORDER, generate_key_pair, generate_schnorr_nonce\n", |
14 | | - "from test_framework.messages import CTxInWitness, sha256\n", |
| 14 | + "from test_framework.messages import COutPoint, CTxIn, CTxInWitness, CTxOut, sha256\n", |
15 | 15 | "from test_framework.musig import generate_musig_key, aggregate_schnorr_nonces, sign_musig, aggregate_musig_signatures\n", |
16 | | - "from test_framework.script import CTransaction, OP_RETURN, SIGHASH_ALL_TAPROOT, TaprootSignatureHash" |
| 16 | + "from test_framework.script import CScript, CTransaction, OP_RETURN, SIGHASH_ALL_TAPROOT, TaprootSignatureHash" |
17 | 17 | ] |
18 | 18 | }, |
19 | 19 | { |
|
509 | 509 | "\n", |
510 | 510 | "# Fetch the oldest unspent outpoint in the Bitcoin Core wallet\n", |
511 | 511 | "unspent_txid = node.listunspent(1)[-1][\"txid\"]\n", |
512 | | - "unspent_outpoint = [{\"txid\": unspent_txid, \"vout\": 0}]" |
| 512 | + "unspent_outpoint = COutPoint(int(unspent_txid,16), 0)" |
513 | 513 | ] |
514 | 514 | }, |
515 | 515 | { |
|
527 | 527 | "metadata": {}, |
528 | 528 | "outputs": [], |
529 | 529 | "source": [ |
530 | | - "# Construct the two outputs:\n", |
| 530 | + "# Construct transaction spending previously generated outpoint\n", |
| 531 | + "op_return_tx = CTransaction()\n", |
| 532 | + "op_return_tx.nVersion = 1\n", |
| 533 | + "op_return_tx.nLockTime = 0\n", |
| 534 | + "op_return_tx_in = CTxIn(outpoint=unspent_outpoint, nSequence=0)\n", |
| 535 | + "op_return_tx.vin = [op_return_tx_in]\n", |
| 536 | + "\n", |
531 | 537 | "# Output 0) Alice's destination address\n", |
532 | | - "# Output 1) OP_RETURN with Alice's commitment\n", |
533 | 538 | "address_alice = node.getnewaddress(address_type=\"bech32\")\n", |
534 | | - "outputs = [{address_alice: 1}, {\"data\": commitment_bytes.hex()}] \n", |
| 539 | + "p2wpkh_output_script = bytes.fromhex(node.getaddressinfo(address_alice)['scriptPubKey'])\n", |
| 540 | + "p2wpkh_output_amount_sat = 100_000_000\n", |
| 541 | + "p2wpkh_output = CTxOut(nValue=p2wpkh_output_amount_sat, scriptPubKey=p2wpkh_output_script)\n", |
| 542 | + "\n", |
| 543 | + "# Output 1) OP_RETURN with Alice's commitment\n", |
| 544 | + "op_return_output_script = CScript([OP_RETURN, commitment_bytes])\n", |
| 545 | + "op_return_output = CTxOut(nValue=0, scriptPubKey=op_return_output_script)\n", |
535 | 546 | "\n", |
536 | | - "# Construct and sign a transaction with the p2pkh and OP_RETURN outputs\n", |
537 | | - "op_return_tx_hex = node.createrawtransaction(inputs=unspent_outpoint, outputs=outputs)\n", |
538 | | - "op_return_tx_hex_signed = node.signrawtransactionwithwallet(hexstring=op_return_tx_hex)['hex']\n", |
| 547 | + "# Populate transaction with p2pkh and OP_RETURN outputs and add valid witness\n", |
| 548 | + "op_return_tx.vout = [p2wpkh_output, op_return_output]\n", |
| 549 | + "op_return_tx_hex_signed = node.signrawtransactionwithwallet(hexstring=op_return_tx.serialize().hex())['hex']\n", |
539 | 550 | "\n", |
540 | 551 | "# Confirm details of the OP_RETURN output\n", |
541 | 552 | "op_return_tx_decoded = node.decoderawtransaction(op_return_tx_hex_signed)\n", |
|
0 commit comments