mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-18 13:17:55 +02:00
Add PSBT::CacheUnsignedTxPieces
Fetches the PSBTv2 fields from PSBTv0's global unsigned tx. This allows us to pretend everything internally is a PSBTv2 and makes things easier to work with.
This commit is contained in:
parent
457b6bd44b
commit
c32950e02b
2 changed files with 35 additions and 0 deletions
33
src/psbt.cpp
33
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue