-1

我必须在下面给出十六进制的测试网上签署原始交易,我尝试在交易生成部分对所有内容进行硬编码,它正在正确广播。但我必须分别实现交易和签名部分。我正在使用 bitcore-lib-cash 包

const bitcore = require('bitcore-lib-cash') const txhex = 010000000139a7e6578a862a10151bdbe0ed4a833cd615273b0cd0ecda1616ee8407d7d8040000000000ffffffff0241010000000000001976a914f0ac6825bd05b406d5224eab0be73852a487e06c88ac94dc0100000000001976a914185ec62d62510d40795109e6484e0487c28a3caf88ac00000000

const private_key = 'private key here' 
let transaction = new bitcore.Transaction(txbuffer).sign(private_key)
console.log(private_key)

{
"errorMessage": "Invalid state: Not all utxo information is available to sign the transaction.",
"errorType": "bitcore.ErrorInvalidState",
"stackTrace": [
    "Error",
    "new NodeError (/var/task/node_modules/bitcore-lib-cash/lib/errors/index.js:20:41)",
    "Object.checkState (/var/task/node_modules/bitcore-lib-cash/lib/util/preconditions.js:9:13)",
    "Transaction.sign (/var/task/node_modules/bitcore-lib-cash/lib/transaction/transaction.js:1077:5)",
    "/var/task/src/custody/utils/biputils.js:155:12",
    "sign_transaction (/var/task/src/custody/utils/biputils.js:167:6)",
    "Object.generate_signature (/var/task/src/custody/assets/bitcoincash.js:220:23)",
    "<anonymous>",
    "process._tickDomainCallback (internal/process/next_tick.js:228:7)"
]

}

4

1 回答 1

-1

更新

我刚刚检查了 bitcore-lib-cash 的源代码,在调用toStringortoBuffer函数时,它们不会对input.

这是编码过程的一部分input

Input.prototype.toBufferWriter = function(writer) {
  if (!writer) {
    writer = new BufferWriter();
  }
  writer.writeReverse(this.prevTxId);
  writer.writeUInt32LE(this.outputIndex);
  var script = this._scriptBuffer;
  writer.writeVarintNum(script.length);
  writer.write(script);
  writer.writeUInt32LE(this.sequenceNumber);
  return writer;
};

所以我认为您必须重写此toBufferWriter函数或解析 txhex 中的每个字段并再次重建事务。


您的 txhex 无效。

解码 txhex 后,它应该output在每个 UTXO 输入对象中都有一个字段,这就是错误的来源。

于 2019-11-07T09:05:12.427 回答