Bitcoin-Core

解析getrawtransaction的輸出欄位,生成公共地址雜湊

  • January 1, 2022

考慮以下 coinbase 交易:

<https://www.blockchain.com/btc/tx/d70ae1131d433b655d0faeae1db4efa15bb4138f1e38e60a53073a58ea1dcc34>

我們如何檢索收件人地址,即1JAL1WRvwbJqWWd1Ktks4Q89zCeUYSQM12使用下面的 RPC 命令的輸出欄位:

bitcoin-cli getrawtransaction d70ae1131d433b655d0faeae1db4efa15bb4138f1e38e60a53073a58ea1dcc34 1


"vout": [
   {
     "value": 50.12000000,
     "n": 0,
     "scriptPubKey": {
       "asm": "0400d0ade32217e076945e0946ef7bed72d9aea035aa8891e4bf0749ae6e24f8a7d3ea56efafe472ac3943dbed3af7c093729720ac9ab04e8eba09286e3a00fe41 OP_CHECKSIG",
       "hex": "410400d0ade32217e076945e0946ef7bed72d9aea035aa8891e4bf0749ae6e24f8a7d3ea56efafe472ac3943dbed3af7c093729720ac9ab04e8eba09286e3a00fe41ac",
       "type": "pubkey"
     }
   }
 ],

對於非 coinbase 交易,輸出欄位包含地址的值。

bitcoin-cli getrawtransaction bd20f46a4337ab787f6fbd036e9f4d65c7ae67d21cc6f9013162e783384d877c 1

"vout": [
   {
     "value": 1.00000000,
     "n": 0,
     "scriptPubKey": {
       "asm": "OP_DUP OP_HASH160 53c32617316707bb8ba4e1546fa8c32bd212c86d OP_EQUALVERIFY OP_CHECKSIG",
       "hex": "76a91453c32617316707bb8ba4e1546fa8c32bd212c86d88ac",
       "address": "18dts6fXXA7jVKfYMBpsFqx7iZCELCfDpk",
       "type": "pubkeyhash"
     }
   },
   {
     "value": 58.97000000,
     "n": 1,
     "scriptPubKey": {
       "asm": "OP_DUP OP_HASH160 37fdd890381f9965d620fc3d0c9fa3e511cb1449 OP_EQUALVERIFY OP_CHECKSIG",
       "hex": "76a91437fdd890381f9965d620fc3d0c9fa3e511cb144988ac",
       "address": "1674G5SSZAb7h4unJMjdxfgNwo71vxgGQg",
       "type": "pubkeyhash"
     }
   }
 ],

觀察輸出的類型是:

“類型”:“公鑰”

Pay-to-Public-Key (P2PK) 輸出沒有地址。顧名思義,他們直接支付給公鑰而不是公鑰的雜湊值。比特幣地址對公鑰雜湊進行編碼,例如,以 a 開頭的地址1稱為 Pay-to-Public-Key-Hash (P2PKH) 地址,並對Ripemd-160(sha-256(public key)).

對於相同的問題,參閱我的其他答案。

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