mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
Add PSBT::ComputeLockTime()
Function to compute the lock time for the transaction
This commit is contained in:
parent
bb4da6631e
commit
e27e795445
2 changed files with 36 additions and 0 deletions
35
src/psbt.cpp
35
src/psbt.cpp
|
@ -47,6 +47,41 @@ bool PartiallySignedTransaction::Merge(const PartiallySignedTransaction& psbt)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool PartiallySignedTransaction::ComputeTimeLock(uint32_t& locktime) const
|
||||
{
|
||||
std::optional<uint32_t> time_lock{0};
|
||||
std::optional<uint32_t> height_lock{0};
|
||||
for (const PSBTInput& input : inputs) {
|
||||
if (input.time_locktime != std::nullopt && input.height_locktime == std::nullopt) {
|
||||
height_lock.reset(); // Transaction can no longer have a height locktime
|
||||
if (time_lock == std::nullopt) {
|
||||
return false;
|
||||
}
|
||||
} else if (input.time_locktime == std::nullopt && input.height_locktime != std::nullopt) {
|
||||
time_lock.reset(); // Transaction can no longer have a time locktime
|
||||
if (height_lock == std::nullopt) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (input.time_locktime && time_lock != std::nullopt) {
|
||||
time_lock = std::max(time_lock, input.time_locktime);
|
||||
}
|
||||
if (input.height_locktime && height_lock != std::nullopt) {
|
||||
height_lock = std::max(height_lock, input.height_locktime);
|
||||
}
|
||||
}
|
||||
if (height_lock != std::nullopt && *height_lock > 0) {
|
||||
locktime = *height_lock;
|
||||
return true;
|
||||
}
|
||||
if (time_lock != std::nullopt && *time_lock > 0) {
|
||||
locktime = *time_lock;
|
||||
return true;
|
||||
}
|
||||
locktime = fallback_locktime.value_or(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PartiallySignedTransaction::AddInput(const CTxIn& txin, PSBTInput& psbtin)
|
||||
{
|
||||
if (std::find(tx->vin.begin(), tx->vin.end(), txin) != tx->vin.end()) {
|
||||
|
|
|
@ -1327,6 +1327,7 @@ struct PartiallySignedTransaction
|
|||
bool AddOutput(const CTxOut& txout, const PSBTOutput& psbtout);
|
||||
void SetupFromTx(const CMutableTransaction& tx);
|
||||
void CacheUnsignedTxPieces();
|
||||
bool ComputeTimeLock(uint32_t& locktime) const;
|
||||
PartiallySignedTransaction() = default;
|
||||
explicit PartiallySignedTransaction(const CMutableTransaction& tx);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue