deconstruct variable declarations
MODIFY
HiddenWallet.ChaumianTumbler/Controllers/TumblerController.cs
HiddenWallet.ChaumianTumbler/Controllers/TumblerController.cs
@@ -462,18 +462,18 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
using (await SignatureProvidedAsyncLock.LockAsync())
{
Transaction coinJoin = Global.StateMachine.CoinJoin;
- foreach (var signatureModel in request.Signatures)
+ foreach (var (Witness, Index) in request.Signatures)
{
- var witness = new WitScript(signatureModel.Witness);
- if (coinJoin.Inputs.Count <= signatureModel.Index)
+ var witness = new WitScript(Witness);
+ if (coinJoin.Inputs.Count <= Index)
{
// round fails, ban alice
await Global.UtxoReferee.BanAliceAsync(alice);
Global.StateMachine.FallBackRound = true;
Global.StateMachine.UpdatePhase(TumblerPhase.InputRegistration);
- throw new ArgumentOutOfRangeException(nameof(signatureModel.Index));
+ throw new ArgumentOutOfRangeException(nameof(Index));
}
- if(!string.IsNullOrWhiteSpace(coinJoin.Inputs[signatureModel.Index]?.WitScript?.ToString()))
+ if(!string.IsNullOrWhiteSpace(coinJoin.Inputs[Index]?.WitScript?.ToString()))
{
// round fails, ban alice
await Global.UtxoReferee.BanAliceAsync(alice);
@@ -481,9 +481,9 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
Global.StateMachine.UpdatePhase(TumblerPhase.InputRegistration);
throw new InvalidOperationException("Input is already signed");
}
- coinJoin.Inputs[signatureModel.Index].WitScript = witness;
- var output = alice.Inputs.Single(x => x.OutPoint == coinJoin.Inputs[signatureModel.Index].PrevOut).Output;
- if(!Script.VerifyScript(output.ScriptPubKey, coinJoin, signatureModel.Index, output.Value, ScriptVerify.Standard, SigHash.All))
+ coinJoin.Inputs[Index].WitScript = witness;
+ var output = alice.Inputs.Single(x => x.OutPoint == coinJoin.Inputs[Index].PrevOut).Output;
+ if(!Script.VerifyScript(output.ScriptPubKey, coinJoin, Index, output.Value, ScriptVerify.Standard, SigHash.All))
{
// round fails, ban alice
await Global.UtxoReferee.BanAliceAsync(alice);

MODIFY
HiddenWallet.Daemon/Wrappers/WalletWrapper.cs
HiddenWallet.Daemon/Wrappers/WalletWrapper.cs
@@ -200,8 +200,8 @@ namespace HiddenWallet.Daemon.Wrappers
_historyResponseBob.History = hrb.ToArray();
// balances
- var getBalanceResult = await WalletJob.GetBalanceAsync(AliceAccount);
- var aa = getBalanceResult.Available;
+ var (Available, UnspentCoins) = await WalletJob.GetBalanceAsync(AliceAccount);
+ var aa = Available;
var getBalanceResult2 = await WalletJob.GetBalanceAsync(BobAccount);
var ab = getBalanceResult2.Available;
_availableAlice = aa.Confirmed;

MODIFY
HiddenWallet.FullSpvWallet/ChaumianCoinJoin/CoinJoinService.cs
HiddenWallet.FullSpvWallet/ChaumianCoinJoin/CoinJoinService.cs
@@ -301,13 +301,13 @@ namespace HiddenWallet.FullSpvWallet.ChaumianCoinJoin
StatusResponse status = statusJustAcquired ?? await TumblerClient.GetStatusAsync(cancel);
StatusResponse = status;
// TODO: only native segwit (p2wpkh) inputs are accepted by the tumbler (later wrapped segwit (p2sh-p2wpkh) will be accepted too)
- var getBalanceResult = await WalletJob.GetBalanceAsync(From);
- var balance = getBalanceResult.Available.Confirmed + getBalanceResult.Available.Unconfirmed;
+ var (Available, UnspentCoins) = await WalletJob.GetBalanceAsync(From);
+ var balance = Available.Confirmed + Available.Unconfirmed;
var feePerInputs = Money.Parse(status.FeePerInputs);
var feePerOutputs = Money.Parse(status.FeePerOutputs);
- var blindingResult = PubKey.Blind(Encoding.UTF8.GetBytes(ActiveOutput.ToString()));
- string blindedOutput = HexHelpers.ToString(blindingResult.BlindedData);
+ var (BlindingFactor, BlindedData) = PubKey.Blind(Encoding.UTF8.GetBytes(ActiveOutput.ToString()));
+ string blindedOutput = HexHelpers.ToString(BlindedData);
SigningKeys = new ConcurrentHashSet<BitcoinExtKey>();
Inputs = new ConcurrentHashSet<Coin>();
@@ -315,7 +315,7 @@ namespace HiddenWallet.FullSpvWallet.ChaumianCoinJoin
var i = 0;
var needSegwitify = false;
Money sumAmounts = Money.Zero;
- foreach (Coin coin in getBalanceResult.UnspentCoins
+ foreach (Coin coin in UnspentCoins
.OrderByDescending(x => x.Value) // look at confirmed ones first
.OrderByDescending(x => x.Key.Amount) // look at the biggest amounts first, TODO: this is sub-optimal (CCJ unconfirmed change should be the same category as confirmed and not CCJ change unconfirmed should not be here)
.Select(x => x.Key))
@@ -360,7 +360,7 @@ namespace HiddenWallet.FullSpvWallet.ChaumianCoinJoin
break;
}
- if (i == getBalanceResult.UnspentCoins.Count)
+ if (i == UnspentCoins.Count)
{
if(needSegwitify)
{
@@ -387,7 +387,7 @@ namespace HiddenWallet.FullSpvWallet.ChaumianCoinJoin
UniqueAliceId = response.UniqueId;
// unblind the signature
- var unblindedSignature = PubKey.UnblindSignature(HexHelpers.GetBytes(response.SignedBlindedOutput), blindingResult.BlindingFactor);
+ var unblindedSignature = PubKey.UnblindSignature(HexHelpers.GetBytes(response.SignedBlindedOutput), BlindingFactor);
// verify the original data is signed
if (!PubKey.Verify(unblindedSignature, Encoding.UTF8.GetBytes(ActiveOutput.ToString())))
{

MODIFY
HiddenWallet.FullSpvWallet/WalletJob.cs
HiddenWallet.FullSpvWallet/WalletJob.cs
@@ -560,10 +560,10 @@ public async Task StartAsync(CancellationToken ctsToken)
foreach (var spk in trackedScriptPubkeys)
{
- var result = await TryFindAllChainAndMemPoolTransactionsAsync(spk);
- var rec = result.ReceivedTransactions;
- var spent = result.SpentTransactions;
- if (result.Success)
+ var (Success, ReceivedTransactions, SpentTransactions) = await TryFindAllChainAndMemPoolTransactionsAsync(spk);
+ var rec = ReceivedTransactions;
+ var spent = SpentTransactions;
+ if (Success)
{
foreach (var tx in rec)
{

MODIFY
HiddenWallet.Tests/FullSpvWalletTests.cs
HiddenWallet.Tests/FullSpvWalletTests.cs
@@ -200,14 +200,14 @@ namespace HiddenWallet.Tests
HashSet<WalletHistoryRecord> qBitFoundItToo = new HashSet<WalletHistoryRecord>();
// Assert all record found by qbit also found by spv and they are identical
- foreach (var record in qBitHistoryRecords)
+ foreach (var (FirstSeen, Amount, Confirmations, TxId) in qBitHistoryRecords)
{
- WalletHistoryRecord found = fullSpvHistoryRecords.FirstOrDefault(x => x.TransactionId == record.TxId);
+ WalletHistoryRecord found = fullSpvHistoryRecords.FirstOrDefault(x => x.TransactionId == TxId);
Assert.NotEqual(default, found);
- Assert.Equal(record.FirstSeen, found.TimeStamp);
- Assert.Equal(record.Confirmations > 0, found.Confirmed);
- Assert.Equal(record.Amount, found.Amount);
+ Assert.Equal(FirstSeen, found.TimeStamp);
+ Assert.Equal(Confirmations > 0, found.Confirmed);
+ Assert.Equal(Amount, found.Amount);
qBitFoundItToo.Add(found);
}

deconstruct variable declarations