Transactions

p2sh-multisig 的開發人員範例看到 sendrawtransaction 始終返回“non-mandatory-script-verify-flag”錯誤 [已解決]

  • December 15, 2018

概述

以下交易:0200000000010121c787a1ca54292403d4200d6953ee0edcd4a1d33721a09938f5d5e067e9c70600000000232200205d577278a6dfefffaa4e04ef23fd1172e923f9e7b4949f991b3d7f2af89abb83ffffffff01993a00000000000017a9144920d433d073267b904ae23df3b15ea47aec950387040047304402202c9946f1d50a974f3b7cf24a99002f3f3ca18af7b54939bf2ec1acf6f5528b07022029aaa63fde914735b8e92c202ce3d4b02ea8ded1d2b47821670dd3c6d8dcb02b0147304402201e5e933e674f7e4597c1066b48cdb4ca1c7382235b53d411608c2e3a22a31df7022022fc673d696987146effcbb9ce43265ab9ee19da05eaef0bb35ced729fe9592501695221036ef3ee62456676a49b3087df3f0d804eb09bfcfa95ca606465bee5cfeab4da98210386518595790f10fa1915bb119a0b41d96a380eeb3f3a76ae0694acc9fd2fb333210371d090dd98316a9f8f63c1d925b42cf157f265d1eff84b65620629914b43019c53ae00000000

當傳遞給 時sendrawtransaction(),會產生以下錯誤:

error code: -26 error message: non-mandatory-script-verify-flag (Signature must be zero for failed CHECK(MULTI)SIG operation) (code 64)

比特幣來源似乎表明該交易因非標準而被拒絕:我的交易基於<https://bitcoin.org/en/developer-examples#p2sh-multisig>上的開發人員範例,我認為這是標準的,並且測試網上發生錯誤,我認為相關的 isStandard() 檢查已關閉。

我正在尋找我在哪裡出錯的洞察力!

詳細資訊:程式碼、輸出、conf 文件、版本、交易解碼、贖回腳本解碼

我已將開發人員範例重寫為一個獨立的 bash 腳本,它將 regtest 重置為已知狀態,然後通過程式碼片段執行,或嘗試在 testnet 上執行。如有必要,已調整呼叫以反映 API 更改,例如 signtransactionwithkey 與 signtransaction:

#!/bin/bash
#
# This code to implement p2sh-multisig example as worked through at
# https://bitcoin.org/en/developer-examples#p2sh-multisig
#
echo "[Setting up run ...]"
DEBUG=true
USE_REGTEST=false  # If false, use testnet
ADDRESS_TYPE="p2sh-segwit"
BITCOIND_HOMEDIR="/home/bitcoind"
BITCOIND_CONFDIR=$BITCOIND_HOMEDIR"/.bitcoin"
if [[ "$USE_REGTEST" = "true" ]]
then
   AMOUNT0="49.99900000"
   AMOUNT1="10.00000000"  # Differs from example to forestall float and rounding issues
   AMOUNT2="9.99800000"
   REGTEST_PARAM="-regtest"
   REGTEST_DIR=$BITCOIND_CONFDIR"/regtest"
   BITCOIND_CONFFILE=$BITCOIND_CONFDIR"/regtest.conf"
   TEST_SPEND_FROM_NONCOINBASE=true  # Test if it matters that funds were generational
else
   AMOUNT0="49.99900000"  # Unused on testnet
   AMOUNT1="0.00030001"
   AMOUNT2="0.00015001"
   REGTEST_PARAM=""
   REGTEST_DIR="/dev/null"
   BITCOIND_CONFFILE=$BITCOIND_CONFDIR"/testnet.conf"
   TEST_SPEND_FROM_NONCOINBASE=false
fi
TXFEE="0.00013000"
BITCOIN_CLI="/usr/local/bin/bitcoin-cli -conf="$BITCOIND_CONFFILE" "$REGTEST_PARAM
BITCOIN_DAEMON="/usr/local/bin/bitcoind -conf="$BITCOIND_CONFFILE" "$REGTEST_PARAM" -daemon"
TEST_PUBLIC_KEYS_ONLY=true  # Public keys vs Addresses test

#
# Get regtest network back to a known state: stop if going, unlink regtest directories,
# restart, and generate first 101 blocks to get 50btc in funds. Give a short period
# to allow cleaning up etc. The 101 is important as it limits our balance to 50btc
if [[ "$USE_REGTEST" = "true" ]]
then
   $BITCOIN_CLI stop
   sleep 1
   rm -rf $REGTEST_DIR && $BITCOIN_DAEMON
   sleep 2
   $BITCOIN_CLI generate 101 &gt;/dev/null
fi

#
# I see references such as at https://github.com/bitcoin/bitcoin/issues/7277
# that one cannot send funds from coinbase to p2sh addresses over regtest.
# This code to send almost whole balance over such that a later spend to
# fund p2sh address cannot but come from a non-coinbase address
# Ignored on testnet
if [[ "$TEST_SPEND_FROM_NONCOINBASE" = "true" ]]
then
   NONCOINBASE_ADDRESS=`$BITCOIN_CLI getnewaddress $ADDRESS_TYPE`
   TXID=`$BITCOIN_CLI sendtoaddress $NONCOINBASE_ADDRESS $AMOUNT0`
   if $DEBUG
   then
   echo "Sending coinbase funds to new key"
   echo "[NONCOINBASE_ADDRESS]: "$NONCOINBASE_ADDRESS
   echo "[TXID               ]: "$TXID
   echo "-----"
   fi
fi

echo "[...Create and fund a 2-of-3 multisig transaction...]"
#
# Create the addresses we will use
NEW_ADDRESS1=`$BITCOIN_CLI getnewaddress $ADDRESS_TYPE`
NEW_ADDRESS2=`$BITCOIN_CLI getnewaddress $ADDRESS_TYPE`
NEW_ADDRESS3=`$BITCOIN_CLI getnewaddress $ADDRESS_TYPE`
if [[ "$DEBUG" = "true" ]]
then
   # Example says addresses start with m, this code sees them start
   # with 2. Problem?
   echo "Creating new addresses:"
   echo "[NEW_ADDRESS1]: "$NEW_ADDRESS1
   echo "[NEW_ADDRESS2]: "$NEW_ADDRESS2
   echo "[NEW_ADDRESS3]: "$NEW_ADDRESS3
   echo "-----"
fi

#
# Obtain one public key - not sure why. To prove we can
# use either address or public key to create the
# multisigaddress? To show how to obtain the data for
# passing on to others? ("all of which will be converted
# to public keys in the redeem script.")
# NB: validateaddress in example superceded by getaddressinfo
if [[ "$TEST_PUBLIC_KEYS_ONLY" = "true" ]]
then
   RV=`$BITCOIN_CLI getaddressinfo $NEW_ADDRESS1`
   NEW_ADDRESS1_PUBLIC_KEY=`echo $RV | sed 's/^.*"pubkey": "//' | 
                     sed 's/".*$//'`  # Checked
   RV=`$BITCOIN_CLI getaddressinfo $NEW_ADDRESS2`
   NEW_ADDRESS2_PUBLIC_KEY=`echo $RV | sed 's/^.*"pubkey": "//' | 
                     sed 's/".*$//'`  # Checked
fi
RV=`$BITCOIN_CLI getaddressinfo $NEW_ADDRESS3`
NEW_ADDRESS3_PUBLIC_KEY=`echo $RV | sed 's/^.*"pubkey": "//' | 
                 sed 's/".*$//'`  # Checked
if [[ "$DEBUG" = "true" ]]
then
   echo "Obtain public key per address:"
   if [[ "$TEST_PUBLIC_KEYS_ONLY" = "true" ]]
   then
   echo "[NEW_ADDRESS1_PUBLIC_KEY]: "$NEW_ADDRESS1_PUBLIC_KEY
   echo "[NEW_ADDRESS2_PUBLIC_KEY]: "$NEW_ADDRESS2_PUBLIC_KEY
   fi
   echo "[NEW_ADDRESS3_PUBLIC_KEY]: "$NEW_ADDRESS3_PUBLIC_KEY
   echo "-----"
fi

#
# Obtain the address and redeem script needed to obtain the funds.
# NB: createmultisig in example superceded by addmultisigaddress
if [[ "$TEST_PUBLIC_KEYS_ONLY" = "true" ]]
then
   RV=`$BITCOIN_CLI addmultisigaddress 2 '''
     [
      "'$NEW_ADDRESS1_PUBLIC_KEY'",
      "'$NEW_ADDRESS2_PUBLIC_KEY'", 
      "'$NEW_ADDRESS3_PUBLIC_KEY'"
     ]'''`
else
   RV=`$BITCOIN_CLI addmultisigaddress 2 '''
   [
     "'$NEW_ADDRESS1'",
     "'$NEW_ADDRESS2'", 
     "'$NEW_ADDRESS3_PUBLIC_KEY'"
   ]'''`
fi
P2SH_ADDRESS=`echo $RV | sed 's/^.*"address": "//' | 
          sed 's/".*$//'`  # Checked
P2SH_REDEEM_SCRIPT=`echo $RV | sed 's/^.*"redeemScript": "//' | 
            sed 's/".*$//'`  # Checked
if [[ "$DEBUG" = "true" ]]
then
   echo "Obtain p2sh address and redeemScript:"
   echo "[P2SH_ADDRESS      ]: "$P2SH_ADDRESS
   echo "[P2SH_REDEEM_SCRIPT]: "$P2SH_REDEEM_SCRIPT
   echo "-----"
fi

#
# On regtest, send funds from the first 50btc block we can spend
# to the p2sh_address determined above.
# On testnet, send part of our balance
if [[ "$USE_REGTEST" != "true" ]]
then
   RV=`$BITCOIN_CLI settxfee $TXFEE`
fi
UTXO_TXID=`$BITCOIN_CLI sendtoaddress $P2SH_ADDRESS $AMOUNT1`
if [[ "$DEBUG" = "true" ]]
then
   echo "Fund p2sh address"
   echo "[UTXO_TXID]: "$UTXO_TXID
   echo "-----"
fi

#
# Get everything thus far into a block
# $BITCOIN_CLI generate 1 &gt;/dev/null

#
#

echo "[...Redeem the 2-of-3 transaction]"
#
# Obtain details about the funded transaction. We want whichever output
# was the 10btc output even though the example suggests there is only
# one output.
# NB: second parameter in example superceded after v0.14.0
RV=`$BITCOIN_CLI getrawtransaction $UTXO_TXID true`
UTXO2_VALUE=`echo $RV | sed 's/^.*"value": //' | sed 's/,.*$//'`  # Checked
UTXO2_VOUT=`echo $RV | sed 's/^.*"n": //' | sed 's/,.*$//'`  # Checked
UTXO2_OUTPUT_SCRIPT=`echo $RV | sed 's/^.*"scriptPubKey"//' | sed 's/"reqSigs".*$//' | 
             sed 's/^.*"hex": "//' | sed 's/".*$//'`  # Checked
UTXO1_VALUE=`echo $RV | sed 's/"addresses":.*//' | sed 's/^.*"value": //' | 
         sed 's/,.*$//'`  # Checked
UTXO1_VOUT=`echo $RV | sed 's/"addresses":.*//' | sed 's/^.*"n": //' | 
        sed 's/,.*$//'`  # Checked
UTXO1_OUTPUT_SCRIPT=`echo $RV | sed 's/"addresses":.*//' | sed 's/^.*"scriptPubKey"//' | 
             sed 's/"reqSigs".*$//' | sed 's/^.*"hex": "//' | 
             sed 's/".*$//'`  # Checked
if [[ "$UTXO1_VALUE" = "$AMOUNT1" ]]
then
   # Use first output (change is the second output)
   UTXO_VOUT=$UTXO1_VOUT
   UTXO_OUTPUT_SCRIPT=$UTXO1_OUTPUT_SCRIPT
else
   # Use second output (changes was the first output)
   UTXO_VOUT=$UTXO2_VOUT
   UTXO_OUTPUT_SCRIPT=$UTXO2_OUTPUT_SCRIPT
fi
if [[ "$DEBUG" = "true" ]]
then
   echo "Capture which outputs we'll use:"
   echo "[1 VALUE            ]: "$UTXO1_VALUE
   echo "[1 VOUT             ]: "$UTXO1_VOUT
   echo "[1 OUTPUT_SCRIPT    ]: "$UTXO1_OUTPUT_SCRIPT
   echo "[2 VALUE            ]: "$UTXO2_VALUE
   echo "[2 VOUT             ]: "$UTXO2_VOUT
   echo "[2 OUTPUT_SCRIPT    ]: "$UTXO2_OUTPUT_SCRIPT
   echo "Vout and Output script chosen:"
   echo "[UTXO_VOUT          ]: "$UTXO_VOUT
   echo "[UTXO_OUTPUT_SCRIPT ]: "$UTXO_OUTPUT_SCRIPT
   echo "-----"
fi

#
# Now create the address redeemed to
NEW_ADDRESS4=`$BITCOIN_CLI getnewaddress $ADDRESS_TYPE`
if [[ "$DEBUG" = "true" ]]
then
   echo "Create redeem-to address:"
   echo "[NEW_ADDRESS4]: "$NEW_ADDRESS4
   echo "-----"
fi

#
# Create a new transaction, slightly less value to accomodate mining fee
RAW_TX=`$BITCOIN_CLI createrawtransaction '''
  [
     {
       "txid": "'$UTXO_TXID'",
       "vout": '$UTXO_VOUT'
     }
  ]
  ''' '''
  {
    "'$NEW_ADDRESS4'": '$AMOUNT2'
  }'''`
RAW_TX_SZ=${#RAW_TX}
if [[ "$DEBUG" = "true" ]]
then
   echo "Generate unsigned transaction:"
   echo "[RAW_TX]: "$RAW_TX
   echo "-----"
fi

#
# Get 2 of the 3 private keys
NEW_ADDRESS1_PRIVATE_KEY=`$BITCOIN_CLI dumpprivkey $NEW_ADDRESS1`
NEW_ADDRESS3_PRIVATE_KEY=`$BITCOIN_CLI dumpprivkey $NEW_ADDRESS3`
if [[ "$DEBUG" = "true" ]]
then
   echo "Capture private keys for use in signing:"
   echo "[NEW_ADDRESS1_PRIVATE_KEY]: "$NEW_ADDRESS1_PRIVATE_KEY
   echo "[NEW_ADDRESS3_PRIVATE_KEY]: "$NEW_ADDRESS3_PRIVATE_KEY
   echo "-----"
fi

#
# 1 of 3 sign off the transaction
# NB: signrawtransaction in example superceded by signrawtransactionwithkey
# NB: order of parameters reverse, and amount becomes mandatory
RV=`$BITCOIN_CLI signrawtransactionwithkey $RAW_TX '''
   [
     "'$NEW_ADDRESS1_PRIVATE_KEY'"
   ]
   ''' '''
   [
     {
       "txid": "'$UTXO_TXID'", 
       "vout": '$UTXO_VOUT', 
       "scriptPubKey": "'$UTXO_OUTPUT_SCRIPT'", 
       "redeemScript": "'$P2SH_REDEEM_SCRIPT'",
   "amount": '$AMOUNT2'
     }
   ]'''`
PARTLY_SIGNED_RAW_TX=`echo $RV | sed 's/^.*"hex": "//' | sed 's/".*//'`
PARTLY_SIGNED_RAW_TX_SZ=${#PARTLY_SIGNED_RAW_TX}
if [[ $PARTLY_SIGNED_RAW_TX_SZ -eq $RAW_TX_SZ ]]
then
   echo "Transaction didn't change size at PARTLY_SIGNED_RAW_TX_SZ. Eh?"
   exit
fi
if [[ $PARTLY_SIGNED_RAW_TX_SZ -eq 0 ]]
then
   echo "Failed at PARTLY_SIGNED_RAW_TX"
   echo "Response: "
   echo "[RAW_TX                  ]: "$RAW_TX
   echo "[UTXO_TXID               ]: "$UTXO_TXID
   echo "[UTXO_VOUT               ]: "$UTXO_VOUT
   echo "[UTXO_OUTPUT_SCRIPT      ]: "$UTXO_OUTPUT_SCRIPT
   echo "[P2SH_REDEEM_SCRIPT      ]: "$P2SH_REDEEM_SCRIPT
   echo "[NEW_ADDRESS1_PRIVATE_KEY]: "$NEW_ADDRESS1_PRIVATE_KEY
   exit
fi
if [[ "$DEBUG" = "true" ]]
then
   echo "Transaction after first signature:"
   echo "[PARTLY_SIGNED_RAW_TX    ]: "$PARTLY_SIGNED_RAW_TX
   echo "-----"
fi

#
# 2 of 3 signs off the transaction
RV=`$BITCOIN_CLI signrawtransactionwithkey $PARTLY_SIGNED_RAW_TX '''
   [
     "'$NEW_ADDRESS3_PRIVATE_KEY'"
   ]
   ''' '''
   [
     {
       "txid": "'$UTXO_TXID'", 
       "vout": '$UTXO_VOUT', 
       "scriptPubKey": "'$UTXO_OUTPUT_SCRIPT'", 
       "redeemScript": "'$P2SH_REDEEM_SCRIPT'",
   "amount": '$AMOUNT2'
     }
   ]'''`
SIGNED_RAW_TX=`echo $RV | sed 's/^.*"hex": "//' | sed 's/".*//'`  # Checked
SIGNED_RAW_TX_SZ=${#SIGNED_RAW_TX}
COMPLETE=`echo $RV | sed 's/^.*"complete": //' | sed 's/\W.*//'`  # Checked
if [[ "$COMPLETE" != "true" ]]
then
   echo "Second signature did not lead to completed transaction. Eh?"
   echo $RV
   exit
fi
if [[ "$DEBUG" = "true" ]]
then
   echo "Transaction after second signature:" 
   echo "[SIGNED_RAW_TX]: "$SIGNED_RAW_TX
   echo "-----"
fi

#
# And now broadcast it
TXID=`$BITCOIN_CLI sendrawtransaction $SIGNED_RAW_TX`
if [[ ${#TXID} -eq 0 ]]
then
   echo "Broadcast has gone wrong. Eh?"
fi
if [[ "$DEBUG" = "true" ]]
then
   echo "TXID from broadcasting:"
   echo "[TXID]: "$TXID
   echo "-----"
fi

上面的程式碼在測試網執行時生成了以下輸出:

$ ./p2sh-multisig.sh
[Setting up run ...]
[...Create and fund a 2-of-3 multisig transaction...]
Creating new addresses:
[NEW_ADDRESS1]: 2NAWwgmSnPcXFshHX41ewLHaN4nYLTzEdHn
[NEW_ADDRESS2]: 2NAoFjMziphkxULu7p4dtcBKLXicnvvcX53
[NEW_ADDRESS3]: 2Mu3S24XuasYheQsinhKAabDnGnH6eakm2X
-----
Obtain public key per address:
[NEW_ADDRESS1_PUBLIC_KEY]: 036ef3ee62456676a49b3087df3f0d804eb09bfcfa95ca606465bee5cfeab4da98
[NEW_ADDRESS2_PUBLIC_KEY]: 0386518595790f10fa1915bb119a0b41d96a380eeb3f3a76ae0694acc9fd2fb333
[NEW_ADDRESS3_PUBLIC_KEY]: 0371d090dd98316a9f8f63c1d925b42cf157f265d1eff84b65620629914b43019c
-----
Obtain p2sh address and redeemScript:
[P2SH_ADDRESS      ]: 2N3G8rhzkMBmfRp54A4rfpW5jTcd65m7hCs
[P2SH_REDEEM_SCRIPT]: 5221036ef3ee62456676a49b3087df3f0d804eb09bfcfa95ca606465bee5cfeab4da98210386518595790f10fa1915bb119a0b41d96a380eeb3f3a76ae0694acc9fd2fb333210371d090dd98316a9f8f63c1d925b42cf157f265d1eff84b65620629914b43019c53ae
-----
Fund p2sh address
[UTXO_TXID]: 06c7e967e0d5f53899a02137d3a1d4dc0eee53690d20d403242954caa187c721
-----
[...Redeem the 2-of-3 transaction]
Capture which outputs we'll use:
[1 VALUE            ]: 0.00030001
[1 VOUT             ]: 0
[1 OUTPUT_SCRIPT    ]: a9146ddd64168434e4e7cf8f7a2a2b485fa1fc8f987e87
[2 VALUE            ]: 0.00005412
[2 VOUT             ]: 1
[2 OUTPUT_SCRIPT    ]: a9146ecbcb78f6ab60ebe53cc69532407a32973af9aa87
Vout and Output script chosen:
[UTXO_VOUT          ]: 0
[UTXO_OUTPUT_SCRIPT ]: a9146ddd64168434e4e7cf8f7a2a2b485fa1fc8f987e87
-----
Create redeem-to address:
[NEW_ADDRESS4]: 2MyuteHEFmxvG2rX8r817DTKhqj8f2ncsmt
-----
Generate unsigned transaction:
[RAW_TX]: 020000000121c787a1ca54292403d4200d6953ee0edcd4a1d33721a09938f5d5e067e9c7060000000000ffffffff01993a00000000000017a9144920d433d073267b904ae23df3b15ea47aec95038700000000
-----
Capture private keys for use in signing:
[NEW_ADDRESS1_PRIVATE_KEY]: cVT8F8PGF9HJSeBgQir5ZHj5Ng4upSPAJHyVnk2puYw6Zs5GdbyR
[NEW_ADDRESS3_PRIVATE_KEY]: cSakmVL2kdR5jTukCFNBPCifcmg3jjQ6eGEvtagnsAoSdDWcu4fT
-----
Transaction after first signature:
[PARTLY_SIGNED_RAW_TX    ]: 0200000000010121c787a1ca54292403d4200d6953ee0edcd4a1d33721a09938f5d5e067e9c70600000000232200205d577278a6dfefffaa4e04ef23fd1172e923f9e7b4949f991b3d7f2af89abb83ffffffff01993a00000000000017a9144920d433d073267b904ae23df3b15ea47aec950387040047304402202c9946f1d50a974f3b7cf24a99002f3f3ca18af7b54939bf2ec1acf6f5528b07022029aaa63fde914735b8e92c202ce3d4b02ea8ded1d2b47821670dd3c6d8dcb02b0100695221036ef3ee62456676a49b3087df3f0d804eb09bfcfa95ca606465bee5cfeab4da98210386518595790f10fa1915bb119a0b41d96a380eeb3f3a76ae0694acc9fd2fb333210371d090dd98316a9f8f63c1d925b42cf157f265d1eff84b65620629914b43019c53ae00000000
-----
Transaction after second signature:
[SIGNED_RAW_TX]: 0200000000010121c787a1ca54292403d4200d6953ee0edcd4a1d33721a09938f5d5e067e9c70600000000232200205d577278a6dfefffaa4e04ef23fd1172e923f9e7b4949f991b3d7f2af89abb83ffffffff01993a00000000000017a9144920d433d073267b904ae23df3b15ea47aec950387040047304402202c9946f1d50a974f3b7cf24a99002f3f3ca18af7b54939bf2ec1acf6f5528b07022029aaa63fde914735b8e92c202ce3d4b02ea8ded1d2b47821670dd3c6d8dcb02b0147304402201e5e933e674f7e4597c1066b48cdb4ca1c7382235b53d411608c2e3a22a31df7022022fc673d696987146effcbb9ce43265ab9ee19da05eaef0bb35ced729fe9592501695221036ef3ee62456676a49b3087df3f0d804eb09bfcfa95ca606465bee5cfeab4da98210386518595790f10fa1915bb119a0b41d96a380eeb3f3a76ae0694acc9fd2fb333210371d090dd98316a9f8f63c1d925b42cf157f265d1eff84b65620629914b43019c53ae00000000
-----
error code: -26
error message:
non-mandatory-script-verify-flag (Signature must be zero for failed CHECK(MULTI)SIG operation) (code 64)
Broadcast has gone wrong. Eh?
TXID from broadcasting:
[TXID]: 
-----
$

使用的 regtest 和 testnet conf 文件(憑證已編輯):

$ cat regtest.conf 
regtest=1
server=1
rpcuser=xxx
rpcpassword=xxx
rpcallowip=127.0.0.1
deprecatedrpc=createmultisig
deprecatedrpc=generate
debug=1
[regtest]
rpcport=18443

$ cat testnet.conf 
testnet=1
server=1
rpcuser=xxx
rpcpassword=xxx
rpcallowip=127.0.0.1
rpcport=18332

使用的版本:

掌握:
比特幣核心守護程序版本 v0.17.99.0-g6d0a14703e288d72ff19d4d89defbc853233899f
比特幣核心 RPC 客戶端版本 v0.17.99.0-g6d0a14703e288d72ff19d4d89defbc853233899f
v0.17:
比特幣核心守護程序版本 v0.17.1.0-gef70f9b52b851c7997a9f1a0834714e3eebc1fd8
比特幣核心 RPC 客戶端版本 v0.17.1.0-gef70f9b52b851c7997a9f1a0834714e3eebc1fd8

交易解碼:

{
“txid”:“e875677a43c3ea91f7ed5790f3133d130fdcbb9e0cc51f098971bb79517c7103”,
“雜湊”:“8d0701cf48cbf48823ede2250832311cea93b6ea0ab116f9e6b4f40c64153027”,
“版本”:2,
“尺寸”:372,
“vsize”:182,
“重量”:726,
“鎖定時間”:0,
“文”:[
{
“txid”:“06c7e967e0d5f53899a02137d3a1d4dc0eee53690d20d403242954caa187c721”,
“投票”:0,
“腳本簽名”:{
"asm": "00205d577278a6dfefffaa4e04ef23fd1172e923f9e7b4949f991b3d7f2af89abb83",
“十六進制”:“2200205d577278a6dfefffaa4e04ef23fd1172e923f9e7b4949f991b3d7f2af89abb83”
},
“txinwitness”:[
"",
"304402202c9946f1d50a974f3b7cf24a99002f3f3ca18af7b54939bf2ec1acf6f5528b07022029aaa63fde914735b8e92c202ce3d4b02ea8ded1d2b47821601dd3c6d8dcb02",b
“304402201e5e933e674f7e4597c1066b48cdb4ca1c7382235b53d411608c2e3a22a31df7022022fc673d696987146effcbb9ce43265ab9ee19da05eaef0bb35ced729fe9592501”
“5221036ef3ee62456676a49b3087df3f0d804eb09bfcfa95ca606465bee5cfeab4da98210386518595790f10fa1915bb119a0b41d96a380eeb3f3a76ae0694acc9fd2fb333210371d090dd98316a9f8f63c1d925b42cf157f265d1eff84b65620629914b43019c53ae”
],
“序列”:4294967295
}
],
“投票”:[
{
“價值”:0.00015001,
“n”:0,
"scriptPubKey": {
"asm": "OP_HASH160 4920d433d073267b904ae23df3b15ea47aec9503 OP_EQUAL",
“十六進制”:“a9144920d433d073267b904ae23df3b15ea47aec950387”,
“reqSigs”:1,
“類型”:“腳本雜湊”,
“地址”:[
“2MyuteHEFmxvG2rX8r817DTKhqj8f2ncsmt”
]
}
}
]
}

兌換腳本解碼為:

{
“ASM”:“2 036ef3ee62456676a49b3087df3f0d804eb09bfcfa95ca606465bee5cfeab4da98 0386518595790f10fa1915bb119a0b41d96a380eeb3f3a76ae0694acc9fd2fb333 0371d090dd98316a9f8f63c1d925b42cf157f265d1eff84b65620629914b43019c 3 OP_CHECKMULTISIG”,
“reqSigs”:2,
“類型”:“多重簽名”,
“地址”:[
"mpZQSfgndvkjqcoXdvofNsE3aJeRAXjrvM",
"mz9eLLofqQKQcuhwGjHxxNhSVxvoYWZDrY",
“mkZv5XqarsoFMoTWSgMfqE9yihvUu8AHAY”
],
"p2sh": "2MxYTNmXWUFwv8miRAcoCsqAr7MduFCjEAV",
“關注”:{
“asm”:“0 5d577278a6dfefffaa4e04ef23fd1172e923f9e7b4949f991b3d7f2af89abb83”,
“十六進制”:“00205d577278a6dfefffaa4e04ef23fd1172e923f9e7b4949f991b3d7f2af89abb83”,
“reqSigs”:1,
“類型”:“見證_v0_scripthash”,
“地址”:[
“tb1qt4thy79xmlhll2jwqnhj8lg3wt5j8708kj2flxgm84lj47y6hwps0je8zu”
],
“p2sh-followed”:“2N3G8rhzkMBmfRp54A4rfpW5jTcd65m7hCs”
}
}

非常感謝你能走到這一步。你很棒!顯然我誤解了一些東西。但是什麼?

看起來signrawtransactionwithkey您正在將要簽署的金額設置為:

"amount": '$AMOUNT2'

如果我正確地遵循了您的流程,那就是您想要通過兌換 utxo*發送的金額。*如果是這樣,這是不正確的。您需要簽署 utxo 本身的金額(資金交易中的金額)。

@arubi 已發布正確答案,非常感謝他。

對於未來的其他人,我的錯誤是在上述兩個signrawtransactionwithkey()呼叫中,當參數要求發送到地址的金額時,我使用了我想從 p2sh 地址發送的金額。仔細想想,這應該很明顯:第二個參數中的所有其他值都是輸入,而我正在添加一個輸出。

我已將更正後的程式碼以及 regtest 和 testnet 執行的輸出上傳到<https://github.com/Csi18nAlistairMann/bitcoin-p2sh-multisig-example>

引用自:https://bitcoin.stackexchange.com/questions/81919