Skip to content

Commit

Permalink
refactor: ♻️ rename RawSignedTransaction -> SignedTransaction
Browse files Browse the repository at this point in the history
BREAKING CHANGE: renamed `RawSignedTransaction` -> `SignedTransaction`
  • Loading branch information
jasonboukheir committed Oct 29, 2021
1 parent b3c4129 commit 787b160
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public void SignedTransactionShouldBeVerifiable()
public void SizeOfSignedTransactionShouldBeUnder4KB()
{
const int MAX_BYTES = 4000;
var size = UnsafeUtility.SizeOf<RawSignedTransaction>();
UnityEngine.Debug.Log($"Size of {nameof(RawSignedTransaction)}: {size}");
var size = UnsafeUtility.SizeOf<SignedTransaction>();
UnityEngine.Debug.Log($"Size of {nameof(SignedTransaction)}: {size}");
Assert.IsTrue(size <= MAX_BYTES);
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Transaction Transaction
}

[AlgoApiField("sig", "sig")]
public Signature Sig
public Sig Sig
{
get => signedTxn.Sig;
set => signedTxn.Sig = value;
Expand Down Expand Up @@ -43,14 +43,14 @@ public LogicSig LogicSig
[AlgoApiField("rs", "rs")]
public ulong Rs;

RawSignedTransaction signedTxn;
SignedTransaction signedTxn;

public bool Equals(BlockTransaction other)
{
return signedTxn.Equals(other.signedTxn);
}

public static implicit operator RawSignedTransaction(BlockTransaction blockTxn)
public static implicit operator SignedTransaction(BlockTransaction blockTxn)
{
return blockTxn.signedTxn;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public struct PendingTransaction
[AlgoApiField("sender-rewards", null)]
public ulong SenderRewards;
[AlgoApiField("txn", null)]
public RawSignedTransaction Transaction;
public SignedTransaction Transaction;

public bool Equals(PendingTransaction other)
{
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static SignedTransaction<TTransaction> Sign<TTransaction>(
where TTransaction : struct, ITransaction, IEquatable<TTransaction>
{
using var message = transaction.ToSignatureMessage(Allocator.Temp);
Signature signature = secretKey.Sign(message);
Sig signature = secretKey.Sign(message);
return new SignedTransaction<TTransaction>(in signature, in transaction);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct LogicSig
public FixedList128Bytes<byte>[] Args;

[AlgoApiField(null, "sig")]
public Signature Sig;
public Sig Sig;

[AlgoApiField(null, "msig")]
public MultiSig MultiSig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

namespace AlgoSdk
{
[AlgoApiFormatter(typeof(ByteArrayFormatter<Signature>))]
public struct Signature
[AlgoApiFormatter(typeof(ByteArrayFormatter<Sig>))]
public struct Sig
: ISignature
, IEquatable<Signature>
, IEquatable<Sig>
, IByteArray
{
Ed25519.Signature sig;
Expand All @@ -19,7 +19,7 @@ public struct Signature

public byte this[int index] { get => sig[index]; set => sig[index] = value; }

public Signature(in Ed25519.Signature sig)
public Sig(in Ed25519.Signature sig)
{
this.sig = sig;
}
Expand All @@ -30,22 +30,22 @@ public bool Verify<TMessage>(TMessage message, Ed25519.PublicKey pk)
return sig.Verify(message, pk);
}

public static implicit operator Ed25519.Signature(Signature signature)
public static implicit operator Ed25519.Signature(Sig signature)
{
return signature.sig;
}

public static implicit operator Signature(Ed25519.Signature sig)
public static implicit operator Sig(Ed25519.Signature sig)
{
return new Signature(in sig);
return new Sig(in sig);
}

public static bool operator ==(in Signature x, in Signature y)
public static bool operator ==(in Sig x, in Sig y)
{
return x.sig == y.sig;
}

public static bool operator !=(in Signature x, in Signature y)
public static bool operator !=(in Sig x, in Sig y)
{
return x.sig != y.sig;
}
Expand All @@ -59,13 +59,13 @@ public override bool Equals(object obj)
{
switch (obj)
{
case Signature signature: return this == signature;
case Sig signature: return this == signature;
case Ed25519.Signature edSig: return sig == edSig;
default: return false;
}
}

public bool Equals(Signature other)
public bool Equals(Sig other)
{
return this.sig.Equals(other.sig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,44 @@ public interface ISignedTransaction
ITransaction Transaction { get; }
bool Verify();

public void CopyTo(ref RawSignedTransaction data);
public void CopyFrom(in RawSignedTransaction data);
public void CopyTo(ref SignedTransaction data);
public void CopyFrom(in SignedTransaction data);
}

[AlgoApiObject]
public struct SignedTransaction
: IEquatable<SignedTransaction>
{
[AlgoApiField("txn", "txn")]
public Transaction Transaction;

[AlgoApiField("sig", "sig")]
public Sig Sig
{
get => Transaction.Signature.Sig;
set => Transaction.Signature.Sig = value;
}

[AlgoApiField("msig", "msig")]
public MultiSig MultiSig
{
get => Transaction.Signature.MultiSig;
set => Transaction.Signature.MultiSig = value;
}

[AlgoApiField("lsig", "lsig")]
public LogicSig LogicSig
{
get => Transaction.Signature.LogicSig;
set => Transaction.Signature.LogicSig = value;
}

public bool Equals(SignedTransaction other)
{
return Transaction.Equals(other.Transaction)
&& Transaction.Signature.Equals(other.Transaction.Signature)
;
}
}

[AlgoApiFormatter(typeof(SignedTransactionFormatter<Transaction.Payment>))]
Expand All @@ -25,11 +61,11 @@ public struct SignedTransaction<TTransaction>
, IEquatable<SignedTransaction<TTransaction>>
where TTransaction : struct, ITransaction, IEquatable<TTransaction>
{
public Signature Signature;
public Sig Signature;
public TTransaction Transaction;

public SignedTransaction(
in Signature signature,
in Sig signature,
in TTransaction transaction
)
{
Expand All @@ -41,21 +77,21 @@ in TTransaction transaction

ITransaction ISignedTransaction.Transaction => Transaction;

public void CopyFrom(in RawSignedTransaction data)
public void CopyFrom(in SignedTransaction data)
{
Signature = data.Sig;
Transaction.CopyFrom(data.Transaction);
}

public void CopyTo(ref RawSignedTransaction data)
public void CopyTo(ref SignedTransaction data)
{
data.Sig = Signature;
Transaction.CopyTo(ref data.Transaction);
}

public RawSignedTransaction ToRaw()
public SignedTransaction ToRaw()
{
RawSignedTransaction result = new RawSignedTransaction();
SignedTransaction result = new SignedTransaction();
CopyTo(ref result);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;

namespace AlgoSdk
{
public struct TransactionSignature
: IEquatable<TransactionSignature>
{
[AlgoApiField("logicsig", null, readOnly: true)]
public LogicSig LogicSig;

[AlgoApiField("multisig", null, readOnly: true)]
public MultiSig MultiSig;

[AlgoApiField("sig", null, readOnly: true)]
public Sig Sig;

public bool Equals(TransactionSignature other)
{
return LogicSig.Equals(other.LogicSig)
&& MultiSig.Equals(other.MultiSig)
&& Sig.Equals(other.Sig)
;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public partial struct Transaction
[AlgoApiField("keyreg-transaction", null, readOnly: true)]
public KeyRegistration.Params KeyRegistrationParams;

[AlgoApiField("signature", null, readOnly: true)]
public TransactionSignature Signature;

public bool Equals(Transaction other)
{
return HeaderParams.Equals(other.HeaderParams)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public async UniTask<AlgoApiResponse<DryrunResults>> TealDryrun(Optional<DryrunR
: await PostAsync(endpoint);
}

public async UniTask<AlgoApiResponse<TransactionId>> SendTransaction(RawSignedTransaction rawTxn)
public async UniTask<AlgoApiResponse<TransactionId>> SendTransaction(SignedTransaction rawTxn)
{
using var data = new NativeList<byte>(Allocator.Persistent);
AlgoApiSerializer.SerializeMessagePack(rawTxn, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ UniTask<AlgoApiResponse<TransactionId>> RegisterParticipationKeys(
UniTask<AlgoApiResponse<Status>> GetStatusAfterWaitingForRound(ulong round);
UniTask<AlgoApiResponse<TealCompilationResult>> TealCompile(string source);
UniTask<AlgoApiResponse<DryrunResults>> TealDryrun(Optional<DryrunRequest> request = default);
UniTask<AlgoApiResponse<TransactionId>> SendTransaction(RawSignedTransaction rawTxn);
UniTask<AlgoApiResponse<TransactionId>> SendTransaction(SignedTransaction rawTxn);
UniTask<AlgoApiResponse<TransactionParams>> GetTransactionParams();
UniTask<AlgoApiResponse<Version>> GetVersions();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ public sealed class SignedTransactionFormatter<T>
{
public SignedTransaction<T> Deserialize(ref JsonReader reader)
{
var raw = AlgoApiFormatterCache<RawSignedTransaction>.Formatter.Deserialize(ref reader);
var raw = AlgoApiFormatterCache<SignedTransaction>.Formatter.Deserialize(ref reader);
SignedTransaction<T> result = default;
result.CopyFrom(in raw);
return result;
}

public SignedTransaction<T> Deserialize(ref MessagePackReader reader)
{
var raw = AlgoApiFormatterCache<RawSignedTransaction>.Formatter.Deserialize(ref reader);
var raw = AlgoApiFormatterCache<SignedTransaction>.Formatter.Deserialize(ref reader);
SignedTransaction<T> result = default;
result.CopyFrom(in raw);
return result;
}

public void Serialize(ref JsonWriter writer, SignedTransaction<T> value)
{
RawSignedTransaction raw = default;
SignedTransaction raw = default;
value.CopyTo(ref raw);
AlgoApiFormatterCache<RawSignedTransaction>.Formatter.Serialize(ref writer, raw);
AlgoApiFormatterCache<SignedTransaction>.Formatter.Serialize(ref writer, raw);
}

public void Serialize(ref MessagePackWriter writer, SignedTransaction<T> value)
{
RawSignedTransaction raw = default;
SignedTransaction raw = default;
value.CopyTo(ref raw);
AlgoApiFormatterCache<RawSignedTransaction>.Formatter.Serialize(ref writer, raw);
AlgoApiFormatterCache<SignedTransaction>.Formatter.Serialize(ref writer, raw);
}
}
}

0 comments on commit 787b160

Please sign in to comment.