Как получить значение для wakeUtxo при создании транзакции с bitcoinjs-lib

Я пытаюсь создать транзакцию с библиотекой Bitcoinlib-js. Я застрял при подписании транзакции, как кажется witnessUtxoтребуется, и я не понимаю, как получить это значение или откуда его взять. Для segwit поставил последний scriptPubKeyв UTXO vout, но я получаю сообщение об ошибке ниже.

Для non-segwit я просто передаю UTXO rawTransaction.

Вот ошибка, которую я получил

      scriptPubKey = ************************************
(node:17) UnhandledPromiseRejectionWarning: Error: Can not sign for this input with the key ************************************************
    at checkScriptForPubkey (/app/node_modules/bitcoinjs-lib/src/psbt.js:800:11)
    at getHashAndSighashType (/app/node_modules/bitcoinjs-lib/src/psbt.js:927:3)
    at Psbt.signInput (/app/node_modules/bitcoinjs-lib/src/psbt.js:522:35)
    at Handshake.<anonymous> (/app/main.js:104:12)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)

И вот код.

      const utxoTransaction = (await axios.get(`https://url/${utxos[j].txid}`)).data;

const scriptPubKey = utxoTransaction.vout[utxoTransaction.vout.length - 1].scriptPubKey.hex;

const isSegwit = utxoTransaction.hex.substring(8, 12) === '0001';
if (isSegwit) {
  psbt.addInput({
    hash: utxos[j].txid,
    index: utxos[j].vout,
    witnessUtxo: {
      script: Buffer.from(scriptPubKey, 'hex'),
      value: utxos[j].amount * 100000000 // value in satoshi
    },
  })
} else {
  // add non-segwit transaction input
  psbt.addInput({
    hash: utxos[j].txid,
    index: utxos[j].vout,
    nonWitnessUtxo: Buffer.from(utxoTransaction.hex, 'hex'),
  })
}

0 ответов

Другие вопросы по тегам