Fix change labeling.
MODIFY
WalletWasabi/Models/TransactionBuilding/PaymentIntent.cs
WalletWasabi/Models/TransactionBuilding/PaymentIntent.cs
@@ -62,16 +62,11 @@ namespace WalletWasabi.Models.TransactionBuilding
Count = requests.Count();
}
- public DestinationRequest GetCustomChange()
+ public bool TryGetCustomChange(out DestinationRequest customChange)
{
- if (ChangeStrategy != ChangeStrategy.Custom)
- {
- throw new InvalidOperationException($"{nameof(ChangeStrategy)} must be {ChangeStrategy.Custom}");
- }
- else
- {
- return Requests.Single(x => x.Amount.Type == MoneyRequestType.AllRemaining);
- }
+ customChange = Requests.FirstOrDefault(x => x.Amount.Type == MoneyRequestType.AllRemaining);
+
+ return customChange != null;
}
}
}

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -977,6 +977,11 @@ namespace WalletWasabi.Services
}
HdPubKey changeHdPubKey = null;
+ if (payments.TryGetCustomChange(out DestinationRequest custChange))
+ {
+ changeHdPubKey = KeyManager.GetKeyForScriptPubKey(custChange.Destination.ScriptPubKey);
+ }
+
try
{
// We try building without change, in some case, it is not needed
@@ -994,9 +999,7 @@ namespace WalletWasabi.Services
}
else if (payments.ChangeStrategy == ChangeStrategy.Custom)
{
- IDestination customDestination = payments.GetCustomChange().Destination;
- builder.SetChange(customDestination);
- changeHdPubKey = KeyManager.GetKeyForScriptPubKey(customDestination.ScriptPubKey);
+ builder.SetChange(custChange.Destination);
}
else
{

Fix change labeling.