Skip to content

Commit 95ce75f

Browse files
committed
Fix: Global Xpub were not properly serialized for PSBT2
1 parent 3dfe2ad commit 95ce75f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

NBitcoin/BIP174/PartiallySignedTransaction.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ public static PSBT Load(byte[] rawBytes, Network network)
210210

211211

212212
var maps = Maps.Load(stream);
213+
return Load(maps, network);
214+
}
215+
216+
private static PSBT Load(Maps maps, Network network)
217+
{
213218
if (maps.Global.TryRemove<int>(PSBTConstants.PSBT_GLOBAL_VERSION, out var psbtVersion) && psbtVersion == 0)
214219
throw new FormatException("PSBTv0 should not include PSBT_GLOBAL_VERSION");
215220
return psbtVersion switch
@@ -964,10 +969,9 @@ public byte[] ToBytes()
964969
/// <returns>A cloned PSBT</returns>
965970
public PSBT Clone()
966971
{
967-
var bytes = ToBytes();
968-
var psbt = PSBT.Load(bytes, Network);
969-
psbt.Settings = Settings.Clone();
970-
return psbt;
972+
var maps = new Maps();
973+
FillMaps(maps);
974+
return PSBT.Load(maps, Network);
971975
}
972976

973977
public string ToBase64() => Encoders.Base64.EncodeData(this.ToBytes());

NBitcoin/BIP370/PSBT2.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ protected override void WriteCore(JsonTextWriter jsonWriter)
220220

221221
internal override void FillMap(Map map)
222222
{
223+
base.FillMap(map);
223224
map.Add([PSBTConstants.PSBT_GLOBAL_VERSION], PSBT2Constants.PSBT2Version.ToBytes());
224225
map.Add([PSBT2Constants.PSBT_GLOBAL_TX_VERSION], TransactionVersion.ToBytes());
225226
if (FallbackLockTime != null)

0 commit comments

Comments
 (0)