diff --git a/src/psbt.cpp b/src/psbt.cpp index 3ab0691a40..ad4346d9ba 100644 --- a/src/psbt.cpp +++ b/src/psbt.cpp @@ -398,3 +398,36 @@ uint32_t PartiallySignedTransaction::GetVersion() const } return 0; } + +void PartiallySignedTransaction::SetupFromTx(const CMutableTransaction& tx) +{ + tx_version = tx.nVersion; + fallback_locktime = tx.nLockTime; + + uint32_t i; + for (i = 0; i < tx.vin.size(); ++i) { + PSBTInput& input = inputs.at(i); + const CTxIn& txin = tx.vin.at(i); + + input.prev_txid = txin.prevout.hash; + input.prev_out = txin.prevout.n; + input.sequence = txin.nSequence; + } + + for (i = 0; i < tx.vout.size(); ++i) { + PSBTOutput& output = outputs.at(i); + const CTxOut& txout = tx.vout.at(i); + + output.amount = txout.nValue.GetAmount(); + output.script = txout.scriptPubKey; + } +} + +void PartiallySignedTransaction::CacheUnsignedTxPieces() +{ + // To make things easier, we split up the global unsigned transaction + // and use the PSBTv2 fields for PSBTv0. + if (tx != nullopt) { + SetupFromTx(*tx); + } +} diff --git a/src/psbt.h b/src/psbt.h index d54ebc6b69..b22e2c5343 100644 --- a/src/psbt.h +++ b/src/psbt.h @@ -738,6 +738,8 @@ struct PartiallySignedTransaction [[nodiscard]] bool Merge(const PartiallySignedTransaction& psbt); bool AddInput(const CTxIn& txin, PSBTInput& psbtin); bool AddOutput(const CTxOut& txout, const PSBTOutput& psbtout); + void SetupFromTx(const CMutableTransaction& tx); + void CacheUnsignedTxPieces(); PartiallySignedTransaction() {} explicit PartiallySignedTransaction(const CMutableTransaction& tx); /**