Adding extra credrequest if required.
MODIFY
WalletWasabi/WabiSabi/Client/SmartRequestNode.cs
WalletWasabi/WabiSabi/Client/SmartRequestNode.cs
@@ -30,28 +30,54 @@ namespace WalletWasabi.WabiSabi.Client
public async Task StartAsync(BobClient bobClient, IEnumerable<long> amounts, IEnumerable<long> vsizes, CancellationToken cancellationToken)
{
await Task.WhenAll(InputAmountCredentialTasks.Concat(InputVsizeCredentialTasks)).ConfigureAwait(false);
-
- IEnumerable<Credential> inputAmountCredentials = InputAmountCredentialTasks.Select(x => x.Result);
- IEnumerable<Credential> inputVsizeCredentials = InputVsizeCredentialTasks.Select(x => x.Result);
+ IEnumerable<Credential> inputAmountCredentials = InputAmountCredentialTasks.Select(x => x.Result).Where(x => x is { });
+ IEnumerable<Credential> inputVsizeCredentials = InputVsizeCredentialTasks.Select(x => x.Result).Where(x => x is { });
+ (var amount1, var amount2) = AddExtraCredential(amounts, inputAmountCredentials);
+ (var vsize1, var vsize2) = AddExtraCredential(vsizes, inputVsizeCredentials);
(Credential[] RealAmountCredentials, Credential[] RealVsizeCredentials) result = await bobClient.ReissueCredentialsAsync(
- amounts.First(),
- amounts.Last(),
- vsizes.First(),
- vsizes.Last(),
+ amount1,
+ amount2,
+ vsize1,
+ vsize2,
inputAmountCredentials,
inputVsizeCredentials,
cancellationToken).ConfigureAwait(false);
-
foreach ((TaskCompletionSource<Credential> tcs, Credential credential) in OutputAmountCredentialTasks.Zip(result.RealAmountCredentials))
{
tcs.SetResult(credential);
}
-
foreach ((TaskCompletionSource<Credential> tcs, Credential credential) in OutputVsizeCredentialTasks.Zip(result.RealVsizeCredentials))
{
tcs.SetResult(credential);
}
}
+
+ private (long value1, long value2) AddExtraCredential(IEnumerable<long> valuesToRequest, IEnumerable<Credential> presentedCredentials)
+ {
+ if (!valuesToRequest.Any())
+ {
+ throw new ArgumentException("No values to request.", nameof(valuesToRequest));
+ }
+
+ if (valuesToRequest.Where(v => v > 0).Count() == 2)
+ {
+ return (valuesToRequest.ElementAt(0), valuesToRequest.ElementAt(1));
+ }
+
+ List<long> result = new();
+ var v = valuesToRequest.First(v => v > 0);
+ result.Add(v);
+ var missing = presentedCredentials.Sum(cr => (long)cr.Amount.ToUlong()) - valuesToRequest.Sum();
+ if (missing > 0)
+ {
+ result.Add(missing);
+ }
+ else
+ {
+ result.Add(0);
+ }
+ return (result[0], result[1]);
+ }
}
}

Adding extra credrequest if required.