Here are all my steps, starting from a fresh wallet :
1. Get wallet address, public key, and private key, mine some blocks to it:
Code:
ADRESS=bitcoin-cli getnewaddress
PUBKEY=parse(bitcoin-cli getaddressinfo $ADRESS) //gets result.pubkey from command result
PRIVKEY=bitcoin-cli dumpprivkey $ADDRESS
bitcoin-cli dumpprivkey $ADDRESS
2. Grab an unspent output from "bitcoin-cli listunspent" and create a P2WSH output transaction:
Code:
UTX= //grab here
TX=bitcoin-tx -create in=$UTX:0 outscript=49.99:"0x21 0x$PUBKEY OP_CHECKSIGVERIFY":W
3. Sign and broadcast:
Code:
bitcoin-cli signrawtransactionwithkey "$TX" '["$PRIVKEY"]'
NEWTX=bitcoin-cli sendrawtransaction [/* the hex from the output of the above command */]
4. Create a transaction spending from NEWTX (still sending to myself):
Code:
SECONDTX=bitcoin-tx -create in=$NEWTX:0 outscript=49.98:"0x21 0x$PUBKEY OP_CHECKSIGVERIFY":W
5. Attempt to sign it:
Code:
SERIALISEDSCRIPT=//serialse it into 21$PUBKEYad - verify with bitcoin-cli decodescript
bitcoin-cli signrawtransactionwithkey $SECONDTX '["$PRIVKEY"]' '[{"txid": "$NEWTX", "vout": 0, "scriptPubKey": "/* the scriptpubkey from NEWTX */", "witnessScript":"$SERIALISEDSCRIPT", "amount": 49.99}]'
At this point I'm getting the error
Code:
redeemScript/witnessScript does not match scriptPubKey
I cannot figure out why it wouldn't match. My serialisation would be the obvious culprit, but decodescript confirms it is correct. I have found https://bitcointalk.org/index.php?topic=5236818.0, but that bug was apparently fixed in Bitcoin Core 0.20, and I am on the latest release (0.20.1).
Any pointers would be greatly appreciated.
Here's the standard support template, if necessary:
Bitcoin Client Software and Version Number: 0.20.1
Operating System: Linux 64-bit
System Hardware Specs: N/A
Description of Problem: See above
Any Related Addresses: N/A (regtest network)
Any Related Transaction IDs: N/A
Screenshot of the problem: N/A
Log Files from the Bitcoin Client: N/A