使用Blockcypher,我在本地环境中创建了一个测试事务。我得到一个有效的Transaction Skeleton:
{"tx": {
"block_height": -1,
"block_index": -1,
"hash": "a478a382c4ea557f2e3f4f5433a8f50fe224492c5b85924e976d813d8b4666f5",
"addresses": [
"C2DpNVTebjiBtYN3PPcFzppPkfKNEhFm2y",
"C5T756EbvD821kQb2Sj1bXy4FJZtFM9j1W"
],
"total": 900400,
"fees": 99600,
"size": 119,
"preference": "high",
"relayed_by": "24.8.123.23",
"received": "2017-06-25T00:45:52.105239052Z",
"ver": 1,
"lock_time": 0,
"double_spend": false,
"vin_sz": 1,
"vout_sz": 2,
"confirmations": 0,
"inputs": [
{
"prev_hash": "f613eb400d7307f8f8390c71b89239bcc34042e642aea11fccf24b68f7030d88",
"output_index": 0,
"script": "",
"output_value": 1000000,
"sequence": 4294967295,
"addresses": [
"C5T756EbvD821kQb2Sj1bXy4FJZtFM9j1W"
],
"script_type": ""
}
],
"outputs": [
{
"value": 40000,
"script": "76a91463c4e90986533ea6c35c51273dee9ba7c42d591288ac",
"addresses": [
"C2DpNVTebjiBtYN3PPcFzppPkfKNEhFm2y"
],
"script_type": "pay-to-pubkey-hash"
},
{
"value": 860400,
"script": "76a9148730a2b733f313ba5ac285c919c7b9efc866048488ac",
"addresses": [
"C5T756EbvD821kQb2Sj1bXy4FJZtFM9j1W"
],
"script_type": "pay-to-pubkey-hash"
}
]
},
"tosign": [
"b570e00ecbd3198bf7dffe699397c61307af428d8cba9ad87abec58e6a08f5bf"
]}
然后我在本地节点服务器上使用以下JS签署事务:
body.pubkeys = []
body.signatures = body.tosign.map(function (tosign, n) {
body.pubkeys.push(keys.getPublicKeyBuffer().toString('hex'));
return keys.sign(new buffer.Buffer(tosign, 'hex')).toDER().toString('hex');
})
现在我们有了骨架事务,pubkeys和签名。
{"tx":{"block_height":-1,"block_index":-1,"hash":"3bfba8432ea76de5415aec4706cf4fcb877325bb7f15f772c1d4fb9b2b685e09","addresses":["CD1Fb77vTVWYqRMeHxfe7mFWHYDgEagLDT","C2DpNVTebjiBtYN3PPcFzppPkfKNEhFm2y"],"total":900400,"fees":99600,"size":119,"preference":"high","relayed_by":"24.8.123.23","received":"2017-06-25T00:59:46.041702738Z","ver":1,"lock_time":0,"double_spend":false,"vin_sz":1,"vout_sz":2,"confirmations":0,"inputs":[{"prev_hash":"bc2077225784ea06f3af4bf12a4b734b60aac07ae5d55b49f43a4438e070406a","output_index":0,"script":"","output_value":1000000,"sequence":4294967295,"addresses":["CD1Fb77vTVWYqRMeHxfe7mFWHYDgEagLDT"],"script_type":""}],"outputs":[{"value":40000,"script":"76a91463c4e90986533ea6c35c51273dee9ba7c42d591288ac","addresses":["C2DpNVTebjiBtYN3PPcFzppPkfKNEhFm2y"],"script_type":"pay-to-pubkey-hash"},{"value":860400,"script":"76a914da0defda66753f3103ec00ab3794f908a26f310f88ac","addresses":["CD1Fb77vTVWYqRMeHxfe7mFWHYDgEagLDT"],"script_type":"pay-to-pubkey-hash"}]},"tosign":["7d501b4ff7dd0172a627e75f939a0eabb47c98d029b46d0ec2c5fb31a49d9af3"],"pubkeys":["030d8d2063a5b133bfab264c12f226f0fc3406e79e18a310b0a787a47050c02abc"],"signatures":["3045022100a1cbd2eab76b62d6bb4f1e92891ac432321654d12327facdbd119d701545a57202203aa607758126eeb05785ac740b020b5c714eb1946968eceae6401472dbe83f4f"]}
当我将新骨架发送到API时,我得到:
"error": "Error validating transaction: Error running script for input 0 referencing bc2077225784ea06f3af4bf12a4b734b60aac07ae5d55b49f43a4438e070406a at 0: Script was NOT verified successfully."
我是比特币交易的新手,但根据我的理解并查看Blockcyper文档中的示例,这应该有效。谁能看到我做错了什么?我在找错了地方吗?如果需要,我很乐意发布更多代码。
在JS中,keys
如下:
{d:
BigInteger {
'0': 4904643,
'1': 37774770,
'2': 14042397,
'3': 27112697,
'4': 353344,
'5': 65571317,
'6': 42482502,
'7': 56129290,
'8': 2398634,
'9': 2911344,
t: 10,
s: 0 },
compressed: true,
network:
{ messagePrefix: '\u0018Bitcoin Signed Message:\n',
bip32: { public: 76067358, private: 76066276 },
pubKeyHash: 0,
scriptHash: 5,
wif: 128 } }
提前感谢您抽出宝贵时间阅读此问题。 - W