Skip to content

Commit

Permalink
Add more merged properties for PSBT2
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDorier committed Mar 3, 2025
1 parent 24d59cc commit 7026afd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion NBitcoin/BIP174/PSBTInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public void UpdateFromCoin(ICoin coin)
/// Import informations contained by <paramref name="other"/> into this instance.
/// </summary>
/// <param name="other"></param>
public void UpdateFrom(PSBTInput other)
public virtual void UpdateFrom(PSBTInput other)
{
if (other == null)
throw new ArgumentNullException(nameof(other));
Expand Down
2 changes: 1 addition & 1 deletion NBitcoin/BIP174/PartiallySignedTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public PSBT Combine(PSBT other)
/// </summary>
/// <param name="other">Another PSBT to takes information from</param>
/// <returns>This instance</returns>
public PSBT UpdateFrom(PSBT other)
public virtual PSBT UpdateFrom(PSBT other)
{
if (other == null)
{
Expand Down
11 changes: 11 additions & 0 deletions NBitcoin/BIP370/PSBT2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ public PSBT2Output AddOutput(Money value, Script scriptPubKey)
txOut.ScriptPubKey = scriptPubKey;
return new PSBT2Output(value, scriptPubKey, this, (uint)Inputs.Count);
}
public override PSBT UpdateFrom(PSBT other)
{
if (other is PSBT2 o)
{
if (o.FallbackLockTime is { } fallbackLockTime)
FallbackLockTime = fallbackLockTime;
if (o.ModifiableFlags is { } modifiableFlags)
ModifiableFlags = modifiableFlags;
}
return base.UpdateFrom(other);
}

protected override void WriteCore(JsonTextWriter jsonWriter)
{
Expand Down
14 changes: 14 additions & 0 deletions NBitcoin/BIP370/PSBT2Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ internal static void FillMap(Map m, TxIn input)
m.Add([PSBT2Constants.PSBT_IN_PREVIOUS_TXID], input.PrevOut.Hash.ToBytes());
}

public override void UpdateFrom(PSBTInput other)
{
if (other is PSBT2Input o)
{
if (o.Sequence != Sequence.Final)
Sequence = o.Sequence;
if (o.LockTime is { } lockTime)
LockTime = lockTime;
if (o.LockTimeHeight is { } lockTimeHeight)
LockTimeHeight = lockTimeHeight;
}
base.UpdateFrom(other);
}

DateTimeOffset? _LockTime;
public DateTimeOffset? LockTime
{
Expand Down

0 comments on commit 7026afd

Please sign in to comment.