gpt4 book ai didi

javascript - 为什么 bitcore-lib 无法正确解码我的比特币交易十六进制?

转载 作者:行者123 更新时间:2023-12-03 01:50:01 26 4
gpt4 key购买 nike

我正在使用bitcore-lib解码以十六进制编码的交易,但我得到了一个奇怪的结果。为了进行比较,我使用了 bitcoinjs-lib它似乎工作得很好。

示例

交易

网络:比特币测试网

哈希值:1eadc4a09c6abc8f024f04031334941ee455cd4fb112850788214da5f631a3d5

交易十六进制:

01000000000101a0bc55f51d3da3c30b0e92cd37effff17264c3d89057e1e041644606d2a703b5010000001716001482681fa5f944a92d53deacb38850ebba2dd44d44ffffffff0240d2df03000000001976a9147ab6ee8c168f32077c1cc83facb49a91d7ee5dae88aca5a2ecae0800000017a914ca21182b9eca3c99175dd89ce548b72db3244db08702483045022100d4485d23e5d0d3d14a40f0fa9c404f24d55d3db77091bbfb96232610e6b3a5220220712e7736a4229ade64a69e712e842f0a3020cf8209b5f2641114c39a4e9a669201210236443d966162716f76a632e487db80511ce795b68e192e9890bc435ca3e50c1f00000000

在这里尝试十六进制代码:https://live.blockcypher.com/btc/decodetx/

片段:

const bitcore = require('bitcore-lib')
const bitcoinjs = require('bitcoinjs-lib')

const TX_HEX = '01000000000101a0bc55f51d3da3c30b0e92cd37effff17264c3d89057e1e041644606d2a703b5010000001716001482681fa5f944a92d53deacb38850ebba2dd44d44ffffffff0240d2df03000000001976a9147ab6ee8c168f32077c1cc83facb49a91d7ee5dae88aca5a2ecae0800000017a914ca21182b9eca3c99175dd89ce548b72db3244db08702483045022100d4485d23e5d0d3d14a40f0fa9c404f24d55d3db77091bbfb96232610e6b3a5220220712e7736a4229ade64a69e712e842f0a3020cf8209b5f2641114c39a4e9a669201210236443d966162716f76a632e487db80511ce795b68e192e9890bc435ca3e50c1f00000000'

const bitcoreTx = new bitcore.Transaction(Buffer.from(TX_HEX, 'hex'))
const bitcoinjsTx = bitcoinjs.Transaction.fromHex(Buffer.from(TX_HEX, 'hex'))

console.log(bitcoreTx.toJSON())
console.log(bitcoinjsTx)

结果

bitcore(不正确)

{ hash: '5f10810f9c514ab3f69b940c3dd7163af2f3a993a84e0e782fa5c39f5d0667a8',
version: 1,
inputs: [],
outputs:
[ { satoshis: 11762590741304222000,
script: '0b0e92cd37effff17264c3d89057e1e041644606d2a703b5010000001716001482681fa5f944a92d53deacb38850ebba2dd44d44ffffffff0240d2df03000000001976a9147ab6ee8c168f32077c1cc83facb49a91d7ee5dae88aca5a2ecae0800000017a914ca21182b9eca3c99175dd89ce548b72db3244db08702483045022100d4485d23e5d0d3d14a40f0fa9c404f24d55d3db77091bbfb96232610e6b3a5220220712e7736a4229ade64a69e712e842f0a3020cf8209b5f2641114c39a4e9a66' } ],
nLockTime: 35717522 }

bitcoinjs(正确)

Transaction {
version: 1,
locktime: 0,
ins:
[ { hash: <Buffer a0 bc 55 f5 1d 3d a3 c3 0b 0e 92 cd 37 ef ff f1 72 64 c3 d8 90 57 e1 e0 41 64 46 06 d2 a7 03 b5>,
index: 1,
script: <Buffer 16 00 14 82 68 1f a5 f9 44 a9 2d 53 de ac b3 88 50 eb ba 2d d4 4d 44>,
sequence: 4294967295,
witness: [Array] } ],
outs:
[ { value: 65000000,
script: <Buffer 76 a9 14 7a b6 ee 8c 16 8f 32 07 7c 1c c8 3f ac b4 9a 91 d7 ee 5d ae 88 ac> },
{ value: 37294482085,
script: <Buffer a9 14 ca 21 18 2b 9e ca 3c 99 17 5d d8 9c e5 48 b7 2d b3 24 4d b0 87> } ] }

最佳答案

您的交易是 segwit* 交易和 bitcorejs does not support it .

来自reddit :

SegWit input scriptSigs will have one of these patterns:

  • 0x160014<20 bytes> (P2WPKH)
  • 0x220020<32 bytes> (P2WSH)

在我看来,bitcorejs 的一个很好的替代方案是 bcoin :它具有相同的功能(运行完整 Node )以及 segwit 支持,并且具有类似的架构,因此很容易从 bitcore 迁移到它。

关于javascript - 为什么 bitcore-lib 无法正确解码我的比特币交易十六进制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50456055/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com