Remove InputWitnessPair
We don't need multiple pairs, just an index and a witness (and in the future possibly a scriptSig).
MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/PostRequests/SignTransactionTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Backend/PostRequests/SignTransactionTests.cs
@@ -31,7 +31,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests
var aliceSignedCoinJoin = round.Assert<SigningState>().CreateUnsignedTransaction();
aliceSignedCoinJoin.Sign(key.GetBitcoinSecret(Network.Main), alice.Coin);
- var req = new TransactionSignaturesRequest(round.Id, new[] { new InputWitnessPair(0, aliceSignedCoinJoin.Inputs[0].WitScript) });
+ var req = new TransactionSignaturesRequest(round.Id, 0, aliceSignedCoinJoin.Inputs[0].WitScript);
await arena.SignTransactionAsync(req, CancellationToken.None);
Assert.True(round.Assert<SigningState>().IsFullySigned);
await arena.StopAsync(CancellationToken.None);
@@ -41,7 +41,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests
public async Task RoundNotFoundAsync()
{
using Arena arena = await WabiSabiFactory.CreateAndStartArenaAsync();
- var req = new TransactionSignaturesRequest(uint256.Zero, null!);
+ var req = new TransactionSignaturesRequest(uint256.Zero, 0, WitScript.Empty);
var ex = await Assert.ThrowsAsync<WabiSabiProtocolException>(async () => await arena.SignTransactionAsync(req, CancellationToken.None));
Assert.Equal(WabiSabiProtocolErrorCode.RoundNotFound, ex.ErrorCode);
await arena.StopAsync(CancellationToken.None);
@@ -55,7 +55,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests
await arena.TriggerAndWaitRoundAsync(TimeSpan.FromSeconds(21));
var round = arena.Rounds.First();
- var req = new TransactionSignaturesRequest(round.Id, null!);
+ var req = new TransactionSignaturesRequest(round.Id, 0, WitScript.Empty);
foreach (Phase phase in Enum.GetValues(typeof(Phase)))
{
if (phase != Phase.TransactionSigning)

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Models/SerializationTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Models/SerializationTests.cs
@@ -126,13 +126,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Models
{
using var key1 = new Key();
using var key2 = new Key();
- var message = new TransactionSignaturesRequest(
- BitcoinFactory.CreateUint256(),
- new[]
- {
- new InputWitnessPair(1, new WitScript(Op.GetPushOp(key1.PubKey.ToBytes())) ),
- new InputWitnessPair(17, new WitScript(Op.GetPushOp(key2.PubKey.ToBytes())) )
- });
+ var message = new TransactionSignaturesRequest(BitcoinFactory.CreateUint256(), 1, new WitScript(Op.GetPushOp(key1.PubKey.ToBytes())));
AssertSerialization(message);
}

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Models/TransactionSignaturesRequestTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Models/TransactionSignaturesRequestTests.cs
@@ -21,72 +21,40 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Models
// Request #1.
TransactionSignaturesRequest request1 = new(
RoundId: roundId,
- InputWitnessPairs: new InputWitnessPair[]
- {
- new InputWitnessPair(1, new WitScript(Op.GetPushOp(key1.PubKey.ToBytes())) ),
- new InputWitnessPair(17, new WitScript(Op.GetPushOp(key2.PubKey.ToBytes())) )
- }
- );
+ InputIndex: 1,
+ Witness: new WitScript(Op.GetPushOp(key1.PubKey.ToBytes())));
//// Request #2.
TransactionSignaturesRequest request2 = new(
RoundId: roundId,
- InputWitnessPairs: new InputWitnessPair[]
- {
- new InputWitnessPair(1, new WitScript(Op.GetPushOp(key1.PubKey.ToBytes())) ),
- new InputWitnessPair(17, new WitScript(Op.GetPushOp(key2.PubKey.ToBytes())) )
- }
- );
+ InputIndex: 1,
+ Witness: new WitScript(Op.GetPushOp(key1.PubKey.ToBytes())));
Assert.Equal(request1, request2);
//// Request #3.
TransactionSignaturesRequest request3 = new(
RoundId: BitcoinFactory.CreateUint256(), // Intentionally changed.
- InputWitnessPairs: new InputWitnessPair[]
- {
- new InputWitnessPair(1, new WitScript(Op.GetPushOp(key1.PubKey.ToBytes())) ),
- new InputWitnessPair(17, new WitScript(Op.GetPushOp(key2.PubKey.ToBytes())) )
- }
- );
+ InputIndex: 1,
+ Witness: new WitScript(Op.GetPushOp(key1.PubKey.ToBytes())));
Assert.NotEqual(request1, request3);
//// Request #4.
TransactionSignaturesRequest request4 = new(
RoundId: roundId,
- InputWitnessPairs: new InputWitnessPair[]
- {
- new InputWitnessPair(999, new WitScript(Op.GetPushOp(key1.PubKey.ToBytes())) ), // Intentionally changed.
- new InputWitnessPair(17, new WitScript(Op.GetPushOp(key2.PubKey.ToBytes())) )
- }
- );
+ InputIndex: 999,
+ Witness: new WitScript(Op.GetPushOp(key1.PubKey.ToBytes()))); // Intentionally changed.
Assert.NotEqual(request1, request4);
//// Request #5.
TransactionSignaturesRequest request5 = new(
RoundId: roundId,
- InputWitnessPairs: new InputWitnessPair[]
- {
- new InputWitnessPair(1, new WitScript(Op.GetPushOp(key2.PubKey.ToBytes())) ), // Intentionally changed.
- new InputWitnessPair(17, new WitScript(Op.GetPushOp(key2.PubKey.ToBytes())) )
- }
- );
+ InputIndex: 1,
+ Witness: new WitScript(Op.GetPushOp(key2.PubKey.ToBytes()))); // Intentionally changed.
Assert.NotEqual(request1, request5);
-
- //// Request #6.
- TransactionSignaturesRequest request6 = new(
- RoundId: roundId,
- InputWitnessPairs: new InputWitnessPair[]
- {
- new InputWitnessPair(1, new WitScript(Op.GetPushOp(key1.PubKey.ToBytes())) ),
- new InputWitnessPair(999, new WitScript(Op.GetPushOp(key2.PubKey.ToBytes())) ) // Intentionally changed.
- }
- );
-
- Assert.NotEqual(request1, request6);
}
}
}

MODIFY
WalletWasabi/WabiSabi/Backend/Rounds/Arena.Partial.cs
WalletWasabi/WabiSabi/Backend/Rounds/Arena.Partial.cs
@@ -239,11 +239,7 @@ namespace WalletWasabi.WabiSabi.Backend.Rounds
{
var round = GetRound(request.RoundId, Phase.TransactionSigning);
- var state = round.Assert<SigningState>();
- foreach (var inputWitnessPair in request.InputWitnessPairs)
- {
- state = state.AddWitness((int)inputWitnessPair.InputIndex, inputWitnessPair.Witness);
- }
+ var state = round.Assert<SigningState>().AddWitness((int)request.InputIndex, request.Witness);
// at this point all of the witnesses have been verified and the state can be updated
round.CoinjoinState = state;

MODIFY
WalletWasabi/WabiSabi/Client/ArenaClient.cs
WalletWasabi/WabiSabi/Client/ArenaClient.cs
@@ -200,8 +200,6 @@ namespace WalletWasabi.WabiSabi.Client
throw new InvalidOperationException($"Missing input.");
}
- List<InputWitnessPair> signatures = new();
-
signedCoinJoin.Sign(bitcoinSecret, coin);
if (!txInput.VerifyScript(coin, out var error))
@@ -209,9 +207,7 @@ namespace WalletWasabi.WabiSabi.Client
throw new InvalidOperationException($"Witness is missing. Reason {nameof(ScriptError)} code: {error}.");
}
- signatures.Add(new InputWitnessPair(txInput.Index, txInput.WitScript));
-
- await RequestHandler.SignTransactionAsync(new TransactionSignaturesRequest(roundId, signatures), cancellationToken).ConfigureAwait(false);
+ await RequestHandler.SignTransactionAsync(new TransactionSignaturesRequest(roundId, txInput.Index, txInput.WitScript), cancellationToken).ConfigureAwait(false);
}
public async Task<RoundState[]> GetStatusAsync(CancellationToken cancellationToken)

DELETE
WalletWasabi/WabiSabi/Models/InputWitnessPair.cs
-using NBitcoin;
-
-namespace WalletWasabi.WabiSabi.Models
-{
- public record InputWitnessPair(
- uint InputIndex,
- WitScript Witness
- );
-}

MODIFY
WalletWasabi/WabiSabi/Models/TransactionSignaturesRequest.cs
WalletWasabi/WabiSabi/Models/TransactionSignaturesRequest.cs
@@ -5,31 +5,5 @@ using System.Linq;
namespace WalletWasabi.WabiSabi.Models
{
- public record TransactionSignaturesRequest(uint256 RoundId, IEnumerable<InputWitnessPair> InputWitnessPairs)
- {
- public override int GetHashCode()
- {
- int hash = 0;
-
- foreach (InputWitnessPair item in InputWitnessPairs)
- {
- hash = (hash << 4) + item.GetHashCode();
- }
-
- return HashCode.Combine(RoundId, hash);
- }
-
- public virtual bool Equals(TransactionSignaturesRequest? other)
- {
- if (other is null)
- {
- return false;
- }
-
- bool isEqual = RoundId == other.RoundId
- && InputWitnessPairs.SequenceEqual(other.InputWitnessPairs);
-
- return isEqual;
- }
- }
+ public record TransactionSignaturesRequest(uint256 RoundId, uint InputIndex, WitScript Witness);
}

Remove InputWitnessPair

We don't need multiple pairs, just an index and a witness (and in the future possibly a scriptSig).