Bitcoin: getrawtransaction(verbose) 和decodeawtransaction 的同一个事务返回不同的txid

创建于 2019-04-23  ·  3评论  ·  资料来源: bitcoin/bitcoin


对于交易f4dedd64c9841d53bbda8beeda52235ec986f1400606812d9c033ac34105532c ,调用 [getrawtransaction(verbose)] 和 [getrawtransaction(hex) +decodeawtransaction] 的结果完全不同,包括 txid。

重现问题的步骤:

  • 使用getrawtransaction(hex) +decodeawtransaction
curl --user yourAuth --data-binary '{"jsonrpc": "1.0","id":"curltest","method":"getrawtransaction", "params": ["f4dedd64c9841d53bbda8beeda52235ec986f1400606812d9c033ac34105532c"] }' -H 'content-type: text/plain;' http://yourEndPoint

返回:

{
    "result": "0100000000010115a16270d3ee7ccc58a0757c1d8e1763790f223d4e4c3823948fb3dfdf9865180100000000ffffffff023f3256000000000017a9142915a7db6c6df171fd0436c7cec0042195dad01c8738ee4647000000001600140aad95e932ba045c2daf31a04c36683d39efe91002473044022002537539ac9586fdd8b5947fa0a47dc002ebe57502608433e103efe2740f93d4022023b1ade7bdf0f002a8fdc4ec6d534588d2132ab88850ac426ea413b4adb465260121031ef964af6923a2111e4916afcc87c73a8980322cc761dd3648714dfda99e72c400000000",
    "error": null,
    "id": null
}

使用decodeawtransaction 解码

curl --user yourAuth  --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "decoderawtransaction", "params": ["0100000000010115a16270d3ee7ccc58a0757c1d8e1763790f223d4e4c3823948fb3dfdf9865180100000000ffffffff023f3256000000000017a9142915a7db6c6df171fd0436c7cec0042195dad01c8738ee4647000000001600140aad95e932ba045c2daf31a04c36683d39efe91002473044022002537539ac9586fdd8b5947fa0a47dc002ebe57502608433e103efe2740f93d4022023b1ade7bdf0f002a8fdc4ec6d534588d2132ab88850ac426ea413b4adb465260121031ef964af6923a2111e4916afcc87c73a8980322cc761dd3648714dfda99e72c400000000"] }' -H 'content-type: text/plain;' http://yourEndPoint

返回:

{
    "result": {
        "txid": "0b637b18840d8fc978a657a3422df3c246c86e4c4046d90e63bf0f86b179b403",
        "hash": "0b637b18840d8fc978a657a3422df3c246c86e4c4046d90e63bf0f86b179b403",
        "version": 1,
        "size": 223,
        "vsize": 223,
        "locktime": 0,
        "vin": [

        ],
        "vout": [
            {
                "value": 90023651848.04721921,
                "n": 0,
                "scriptPubKey": {
                    "asm": "8 OP_GREATERTHAN OP_DROP OP_SWAP 8e1763790f223d4e4c3823948fb3dfdf9865180100000000ffffffff02 3256000000000017a9142915a7db6c6df171fd0436c7cec0042195dad01c8738ee4647000000001600140aad95e932ba045c2daf31a04c36683d39efe91002 3044022002537539ac9586fdd8b5947fa0a47dc002ebe57502608433e103efe2740f93d4022023b1ade7bdf0f002a8fdc4ec6d534588d2132ab88850ac426ea413b4adb4652601 031ef964af6923a2111e4916afcc87c73a8980322cc761dd3648714dfda99e72c4",
                    "hex": "58a0757c1d8e1763790f223d4e4c3823948fb3dfdf9865180100000000ffffffff023f3256000000000017a9142915a7db6c6df171fd0436c7cec0042195dad01c8738ee4647000000001600140aad95e932ba045c2daf31a04c36683d39efe91002473044022002537539ac9586fdd8b5947fa0a47dc002ebe57502608433e103efe2740f93d4022023b1ade7bdf0f002a8fdc4ec6d534588d2132ab88850ac426ea413b4adb465260121031ef964af6923a2111e4916afcc87c73a8980322cc761dd3648714dfda99e72c4",
                    "type": "nonstandard"
                }
            }
        ]
    },
    "error": null,
    "id": null
}

“txid”或“hash”都不等于我最初给它的哈希值( f4dedd64c9841d53bbda8beeda52235ec986f1400606812d9c033ac34105532c )。

  • 使用getrawtransaction (详细):
curl --user yourAuth --data-binary '{"jsonrpc": "1.0","id":"curltest","method":"getrawtransaction", "params": ["f4dedd64c9841d53bbda8beeda52235ec986f1400606812d9c033ac34105532c",true] }' -H 'content-type: text/plain;' http://yourEndPoint

这返回:

{
    "result": {
        "txid": "f4dedd64c9841d53bbda8beeda52235ec986f1400606812d9c033ac34105532c",
        "hash": "0b637b18840d8fc978a657a3422df3c246c86e4c4046d90e63bf0f86b179b403",
        "version": 1,
        "size": 223,
        "vsize": 142,
        "locktime": 0,
        "vin": [
            {
                "txid": "186598dfdfb38f9423384c4e3d220f7963178e1d7c75a058cc7ceed37062a115",
                "vout": 1,
                "scriptSig": {
                    "asm": "",
                    "hex": ""
                },
                "txinwitness": [
                    "3044022002537539ac9586fdd8b5947fa0a47dc002ebe57502608433e103efe2740f93d4022023b1ade7bdf0f002a8fdc4ec6d534588d2132ab88850ac426ea413b4adb4652601",
                    "031ef964af6923a2111e4916afcc87c73a8980322cc761dd3648714dfda99e72c4"
                ],
                "sequence": 4294967295
            }
        ],
        "vout": [
            {
                "value": 0.05648959,
                "n": 0,
                "scriptPubKey": {
                    "asm": "OP_HASH160 2915a7db6c6df171fd0436c7cec0042195dad01c OP_EQUAL",
                    "hex": "a9142915a7db6c6df171fd0436c7cec0042195dad01c87",
                    "reqSigs": 1,
                    "type": "scripthash",
                    "addresses": [
                        "35SFa5Aev3bjP7gfvfY959GSdWUrSdzoJn"
                    ]
                }
            },
            {
                "value": 11.95830840,
                "n": 1,
                "scriptPubKey": {
                    "asm": "0 0aad95e932ba045c2daf31a04c36683d39efe910",
                    "hex": "00140aad95e932ba045c2daf31a04c36683d39efe910",
                    "reqSigs": 1,
                    "type": "witness_v0_keyhash",
                    "addresses": [
                        "bc1qp2ket6fjhgz9ctd0xxsycdng85u7l6gs2x4dgh"
                    ]
                }
            }
        ],
        "hex": "0100000000010115a16270d3ee7ccc58a0757c1d8e1763790f223d4e4c3823948fb3dfdf9865180100000000ffffffff023f3256000000000017a9142915a7db6c6df171fd0436c7cec0042195dad01c8738ee4647000000001600140aad95e932ba045c2daf31a04c36683d39efe91002473044022002537539ac9586fdd8b5947fa0a47dc002ebe57502608433e103efe2740f93d4022023b1ade7bdf0f002a8fdc4ec6d534588d2132ab88850ac426ea413b4adb465260121031ef964af6923a2111e4916afcc87c73a8980322cc761dd3648714dfda99e72c400000000",
        "blockhash": "00000000000000000011ca3164ee629216de2e5dae09ffb099815319f6e35a71",
        "confirmations": 1459,
        "time": 1555100160,
        "blocktime": 1555100160
    },
    "error": null,
    "id": null
}

它具有正确的交易 ID(txid)。

他们应该返回相同的交易,至少返回相同的 txid。

我的节点信息:

{
  "result": {
    "version": 170100,
    "subversion": "/Satoshi:0.17.1/",
    "protocolversion": 70015,
    "localservices": "000000000000040d",
    "localrelay": true,
    "timeoffset": 10,
    "networkactive": true,
    "connections": 8,
    "networks": [
      {
        "name": "ipv4",
        "limited": false,
        "reachable": true,
        "proxy": "",
        "proxy_randomize_credentials": false
      },
      {
        "name": "ipv6",
        "limited": false,
        "reachable": true,
        "proxy": "",
        "proxy_randomize_credentials": false
      },
      {
        "name": "onion",
        "limited": true,
        "reachable": false,
        "proxy": "",
        "proxy_randomize_credentials": false
      }
    ],
    "relayfee": 0.00001000,
    "incrementalfee": 0.00001000,
    "localaddresses": [

    ],
    "warnings": ""
  },
  "error": null,
  "id": "curltest"
}

最有用的评论

这是(不幸的是)预期的行为。 getrawtransaction正确, decoderawtransaction不正确。

出现此问题是因为该交易是一个隔离见证交易,它可能会被decoderawtransaction误认为是 0 输入交易,这需要解码 0 输入交易。 用于区分decoderawtransaction使用的 0 输入和隔离见证交易的启发式方法并非万无一失,仍然存在一些误报,例如您的交易。 getrawtransaction不会混淆,因为它正在获取网络上存在的交易的详细信息,因此不能是 0 输入交易。 decoderawtransaction给出了错误的 txid,因为它不应该在 txid 中包含隔离见证数据。

decoderawtransaction有一个可选参数iswitness ,用于指示是否应该将交易视为隔离见证交易并对其进行解码。 如果将其设置为 true(即bitcoin-cli decoderawtransaction <raw tx> true ),您应该得到正确的结果(与getrawtransaction相同)。

所有3条评论

这是(不幸的是)预期的行为。 getrawtransaction正确, decoderawtransaction不正确。

出现此问题是因为该交易是一个隔离见证交易,它可能会被decoderawtransaction误认为是 0 输入交易,这需要解码 0 输入交易。 用于区分decoderawtransaction使用的 0 输入和隔离见证交易的启发式方法并非万无一失,仍然存在一些误报,例如您的交易。 getrawtransaction不会混淆,因为它正在获取网络上存在的交易的详细信息,因此不能是 0 输入交易。 decoderawtransaction给出了错误的 txid,因为它不应该在 txid 中包含隔离见证数据。

decoderawtransaction有一个可选参数iswitness ,用于指示是否应该将交易视为隔离见证交易并对其进行解码。 如果将其设置为 true(即bitcoin-cli decoderawtransaction <raw tx> true ),您应该得到正确的结果(与getrawtransaction相同)。

@achow101谢谢你的解释,我的问题解决了。

这将是一个有用的堆栈交换问题/答案!

此页面是否有帮助?
0 / 5 - 0 等级