我的代码如下,用于生成原始交易的简单脚本。
var path = require('path').dirname(require.main.filename)
var bitcore = require('bitcore-lib')
var fs = require('fs')
var UnspentOutput = bitcore.Transaction.UnspentOutput
const blockchain = require('blockchain.info')
var json = fs.readFileSync(path + '/' + '1MPP77eCzAsCKMjtWzdcNw4XMUxb5ePBeA.json');
obj = JSON.parse(json)
var address = "1C3xRrMetAdz2VSnbuDTnwHj3Dyeo9auk2"
var amount = 1000000 //satoshis
var privkeySet = bitcore.PrivateKey.fromWIF(obj["priv"]);
var cAddr = "1MPP77eCzAsCKMjtWzdcNw4XMUxb5ePBeA"
blockchain.blockexplorer.getUnspentOutputs(cAddr).then(outputs => {
var utxo = new UnspentOutput({
"txid" : outputs['unspent_outputs'][0]['tx_hash'],
"vout" : outputs['unspent_outputs'][0]['tx_output_n'],
"address" : cAddr,
"script" : outputs['unspent_outputs'][0]['script'],
"satoshis" : outputs['unspent_outputs'][0]['value']
})
var utxos = [utxo]
var tx = new bitcore.Transaction()
.from(utxos)
.to(address, amount)
.change(cAddr)
.fee(10000)
.sign(privkeySet);
console.log("transaction = " + tx.verify());
console.log("Signature = " + tx.isFullySigned());
console.log(tx)
});
但是,当我通过 blockchain.info 广播原始交易时,我得到以下信息......
Missing parents for 62ce2eacfb96368dc7751e023d0890eae2e700c46dce1bd91192be27db6e97e7 while inserting: [872f22da56a21f500b87db1a6361ca228cca6b75913faeb4cb9ce2d19133a185]
两者都verify
返回isFullySigned
true。原始交易如下...
010000000185a13391d1e29ccbb4ae3f91756bca8c22ca61631adb870b501fa256da222f87000000006b483045022100d713fbef655d7962731cc672b84a29db25fb274494a783f0d6507a683fd91301022044881127ec59d291d7f0dcf12bc7163be5bcf0d64808d5e8f5fac897e0c40d9401210327efda0447312e9bf7daff4788aa721302cc14778bcbdfb4e679229e985357b9ffffffff0240420f00000000001976a91479387c223f297cad674c523bd44403c1caf666ca88ac7ae90300000000001976a914df9e1e985d57beaafa44c6cafe712f05cddc2db188ac00000000
完全不知道出了什么问题。交易正在签名,未使用的输出很好,等等。感谢任何帮助,谢谢!