Bitcoin-Core

生成一個 P2SH-P2WSH 地址並將輸出發送給它

  • December 23, 2017

我正在嘗試生成一個P2SH-P2WSH地址,然後將輸出發送到該地址,但是當我嘗試簽名時,我收到來自bitcoind (v0.15.1.0)的Invalid private key錯誤。那麼我哪裡出錯了,我不完全確定我是否正確生成了地址,或者bitcoind rpc 方法是否正確支持 segwit 簽名操作。如果有人能確認地址是否正確生成,或者我在簽名階段以某種方式失敗,我將不勝感激。如果需要,我可以提供生成程式碼(用 Java 編寫)。

這是我想出的:

2 個多重簽名中的第 2 個地址生成:

Private hex Key c3accc350d70d1981c4366fd6fd86d9cc311048ae8620dac0b3dc9d18ce415fa
Public Key 320ce424c6d61f352ccfea60d209651672cfb03b2dc77d1d64d3ba519aec756ae

Private hex Key 1093e97f3c01bd766473cc51441d443e9325a59387421a9e2fb69b7f9587d915
Public Key 20b020e27e49f049eac10010506499a84e1d59a500cd3680e9ded580df9a107b0

Witness program=2 PUSHDATA(33)[020b020e27e49f049eac10010506499a84e1d59a500cd3680e9ded580df9a107b0] PUSHDATA(33)[0320ce424c6d61f352ccfea60d209651672cfb03b2dc77d1d64d3ba519aec756ae] 2 CHECKMULTISIG
Witness hex=5221020b020e27e49f049eac10010506499a84e1d59a500cd3680e9ded580df9a107b0210320ce424c6d61f352ccfea60d209651672cfb03b2dc77d1d64d3ba519aec756ae52ae

redeemScript program=0 PUSHDATA(32)[16a91e58e02069f95ea6defba7436199658573c34d384c69779779f4500d7cac]
redeemScript hex=002016a91e58e02069f95ea6defba7436199658573c34d384c69779779f4500d7cac

scriptPubKey program=HASH160 PUSHDATA(20)[035e0a0739eec3c195f9dc0d8b85e6e3f6ae1ece] EQUAL
scriptPubKey hex=a914035e0a0739eec3c195f9dc0d8b85e6e3f6ae1ece87

TestNetAddress=2MsZ2fpGKUydzY62v6trPHR8eCx5JTy1Dpa

我使用 bitcoinj 庫創建了這些,我完全確定這是正確的,但從外觀上看,它似乎是比特幣核心在 segwit 開髮指南中描述的。

我用這個 TX = 122831a5cc3d3875cadd89e2a2690c2e5bc9e703d177385e1a3318a44675b6d6 發送到這個地址測試幣(Testnet3 )的****資金存款

創建原始交易

Created transaction hex (using bitcoin rpc) = 
{
   "jsonrpc": "1.0",
   "id": "reqId1",
   "method": "createrawtransaction",
   "params": [
       [
           {
               "txid": "122831a5cc3d3875cadd89e2a2690c2e5bc9e703d177385e1a3318a44675b6d6",
               "vout": 1
           }
       ],
       {
           "mmZFY7b7NArkrnri43RwxL58m6TZUqty4t": "0.09999"
       },
       0
   ]
}
Response hex = 0200000001d6b67546a418331a5e3877d103e7c95b2e0c69a2e289ddca75383dcca53128120100000000ffffffff0198929800000000001976a914423ffad905158d1d472f5fcd5fbc6916c2fb031f88ac00000000

簽署原始交易

SignRaw transaction request (using bitcoin rpc) = {"jsonrpc":"1.0","id":"signrawtransaction_1510651375833","method":"signrawtransaction","params":["0200000001d6b67546a418331a5e3877d103e7c95b2e0c69a2e289ddca75383dcca53128120100000000ffffffff0198929800000000001976a914423ffad905158d1d472f5fcd5fbc6916c2fb031f88ac00000000",[{"txid":"122831a5cc3d3875cadd89e2a2690c2e5bc9e703d177385e1a3318a44675b6d6","vout":1,"scriptPubKey":"a914035e0a0739eec3c195f9dc0d8b85e6e3f6ae1ece87","redeemScript":"002016a91e58e02069f95ea6defba7436199658573c34d384c69779779f4500d7cac","amount":"0.10000000"}],["c3accc350d70d1981c4366fd6fd86d9cc311048ae8620dac0b3dc9d18ce415fa","1093e97f3c01bd766473cc51441d443e9325a59387421a9e2fb69b7f9587d915"]]}
{
   "jsonrpc": "1.0",
   "id": "reqId2",
   "method": "signrawtransaction",
   "params": [
       "0200000001d6b67546a418331a5e3877d103e7c95b2e0c69a2e289ddca75383dcca53128120100000000ffffffff0198929800000000001976a914423ffad905158d1d472f5fcd5fbc6916c2fb031f88ac00000000",
       [
           {
               "txid": "122831a5cc3d3875cadd89e2a2690c2e5bc9e703d177385e1a3318a44675b6d6",
               "vout": 1,
               "scriptPubKey": "a914035e0a0739eec3c195f9dc0d8b85e6e3f6ae1ece87",
               "redeemScript": "002016a91e58e02069f95ea6defba7436199658573c34d384c69779779f4500d7cac",
               "amount": "0.10000000"
           }
       ],
       [
           "cN8vhcMrmcf3fUkWeTrRNt6mmiBoqnKmuce3yNcWkUjjNNskbjbg",
           "cU94urfRuwnEpGtJiiKyGsBqbC7woGazxST1HbGYWMgfVdafKmgu"
       ]
   ]
}

Result = Error{code=-5, message='Invalid private key', data='null'}

bitcoin-clisignrawtransaction預計會有一些爭論。您大部分都正確,但忘記添加用於兌換實際 p2wsh 部分的詳細資訊。特別是對於 p2sh(p2wsh),您需要同時提供:

$ bitcoin-cli -tesnet signrawtransaction \
0200000001d6b67546a418331a5e3877d103e7c95b2e0c69a2e289ddca75383dcca53128120100000000ffffffff0198929800000000001976a914423ffad905158d1d472f5fcd5fbc6916c2fb031f88ac00000000 \
'[{"txid":"122831a5cc3d3875cadd89e2a2690c2e5bc9e703d177385e1a3318a44675b6d6","vout":1,"scriptPubKey":"A914035E0A0739EEC3C195F9DC0D8B85E6E3F6AE1ECE87","redeemScript":"002016A91E58E02069F95EA6DEFBA7436199658573C34D384C69779779F4500D7CAC","amount":0.1},{"txid":"122831a5cc3d3875cadd89e2a2690c2e5bc9e703d177385e1a3318a44675b6d6","vout":1,"scriptPubKey":"A914035E0A0739EEC3C195F9DC0D8B85E6E3F6AE1ECE87","redeemScript":"5221020B020E27E49F049EAC10010506499A84E1D59A500CD3680E9DED580DF9A107B0210320CE424C6D61F352CCFEA60D209651672CFB03B2DC77D1D64D3BA519AEC756AE52AE","amount":0.1}]' \
'["cU94urfRuwnEpGtJiiKyGsBqbC7woGazxST1HbGYWMgfVdafKmgu","cN8vhcMrmcf3fUkWeTrRNt6mmiBoqnKmuce3yNcWkUjjNNskbjbg"]'
{
 "hex": "02000000000101d6b67546a418331a5e3877d103e7c95b2e0c69a2e289ddca75383dcca5312812010000002322002016a91e58e02069f95ea6defba7436199658573c34d384c69779779f4500d7cacffffffff0198929800000000001976a914423ffad905158d1d472f5fcd5fbc6916c2fb031f88ac04004730440220783b89197a238a9300bc30b55b926848dfb8d94016930c050a037c9420c7e2c70220542fa6b3cbd34e32cdc7ea13c00410735c546a6e390e6de2be87c3a9314e67f80147304402206d25c1b31c405fef9aef5dc3bf30ccea2760d59bc25787c7de9fd87a4ade39490220612e9d5fc283a5fd11ac690dc006a914af88c31d0c5d4eb07d38cc4b66e5a1cf01475221020b020e27e49f049eac10010506499a84e1d59a500cd3680e9ded580df9a107b0210320ce424c6d61f352ccfea60d209651672cfb03b2dc77d1d64d3ba519aec756ae52ae00000000",
 "complete": true
}

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