From 7026afdab339da31c1f45823844f4ec6eefc4511 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Mon, 3 Mar 2025 18:20:36 +0900 Subject: [PATCH] Add more merged properties for PSBT2 --- NBitcoin/BIP174/PSBTInput.cs | 2 +- NBitcoin/BIP174/PartiallySignedTransaction.cs | 2 +- NBitcoin/BIP370/PSBT2.cs | 11 +++++++++++ NBitcoin/BIP370/PSBT2Input.cs | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/NBitcoin/BIP174/PSBTInput.cs b/NBitcoin/BIP174/PSBTInput.cs index aed5a4787..bf8e50ab1 100644 --- a/NBitcoin/BIP174/PSBTInput.cs +++ b/NBitcoin/BIP174/PSBTInput.cs @@ -271,7 +271,7 @@ public void UpdateFromCoin(ICoin coin) /// Import informations contained by into this instance. /// /// - public void UpdateFrom(PSBTInput other) + public virtual void UpdateFrom(PSBTInput other) { if (other == null) throw new ArgumentNullException(nameof(other)); diff --git a/NBitcoin/BIP174/PartiallySignedTransaction.cs b/NBitcoin/BIP174/PartiallySignedTransaction.cs index 9d38964d9..38b526a79 100644 --- a/NBitcoin/BIP174/PartiallySignedTransaction.cs +++ b/NBitcoin/BIP174/PartiallySignedTransaction.cs @@ -367,7 +367,7 @@ public PSBT Combine(PSBT other) /// /// Another PSBT to takes information from /// This instance - public PSBT UpdateFrom(PSBT other) + public virtual PSBT UpdateFrom(PSBT other) { if (other == null) { diff --git a/NBitcoin/BIP370/PSBT2.cs b/NBitcoin/BIP370/PSBT2.cs index 0e7f96676..68f4a3c88 100644 --- a/NBitcoin/BIP370/PSBT2.cs +++ b/NBitcoin/BIP370/PSBT2.cs @@ -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) { diff --git a/NBitcoin/BIP370/PSBT2Input.cs b/NBitcoin/BIP370/PSBT2Input.cs index 5c8424418..c36aee590 100644 --- a/NBitcoin/BIP370/PSBT2Input.cs +++ b/NBitcoin/BIP370/PSBT2Input.cs @@ -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 {