From c4bde44466fff3147bc235a442358f1cb8ff5663 Mon Sep 17 00:00:00 2001 From: rasmus-kirk Date: Tue, 28 Nov 2023 10:03:33 +0100 Subject: [PATCH] Self-review --- .../GetBlockPendingUpdates/GetBlocks.csproj | 18 --------------- src/Exceptions/DeserialException.cs | 2 +- src/Helpers/Deserialization.cs | 14 +----------- src/Transactions/AccountTransactionHeader.cs | 2 +- src/Transactions/AccountTransactionPayload.cs | 22 ------------------- src/Transactions/TransferWithMemo.cs | 6 ++++- src/Types/AccountAddress.cs | 7 ++++-- src/Types/CcdAmount.cs | 4 ++-- src/Types/OnChainData.cs | 4 ++-- src/Types/VersionedModuleSource.cs | 7 +++++- 10 files changed, 23 insertions(+), 63 deletions(-) delete mode 100644 examples/GetBlockPendingUpdates/GetBlocks.csproj diff --git a/examples/GetBlockPendingUpdates/GetBlocks.csproj b/examples/GetBlockPendingUpdates/GetBlocks.csproj deleted file mode 100644 index f9d1b111..00000000 --- a/examples/GetBlockPendingUpdates/GetBlocks.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - Exe - net6.0 - enable - enable - - - - - - - - - - - diff --git a/src/Exceptions/DeserialException.cs b/src/Exceptions/DeserialException.cs index 9813ce7a..c5cef779 100644 --- a/src/Exceptions/DeserialException.cs +++ b/src/Exceptions/DeserialException.cs @@ -1,7 +1,7 @@ namespace Concordium.Sdk.Exceptions; /// -/// Thrown when a matched enum value could not be handled in a switch statement. +/// Thrown when deserialization fails and is explicitly meant not to. /// public sealed class DeserialException : Exception { diff --git a/src/Helpers/Deserialization.cs b/src/Helpers/Deserialization.cs index e351991a..7c89cce8 100644 --- a/src/Helpers/Deserialization.cs +++ b/src/Helpers/Deserialization.cs @@ -48,7 +48,7 @@ public static bool TryDeserialU32(byte[] input, int offset, out (uint? Uint, str } /// - /// Creates a uint from a byte array. + /// Creates a ulong from a byte array. /// public static bool TryDeserialU64(byte[] input, int offset, out (ulong? Ulong, string? Error) output) { @@ -66,18 +66,6 @@ public static bool TryDeserialU64(byte[] input, int offset, out (ulong? Ulong, s output = (BinaryPrimitives.ReadUInt64BigEndian(bytes), null); return true; } - - // TODO: Debug tool remove - public static void PrintBytes(string msg, byte[] bytes) - { - Console.WriteLine(msg); - foreach (var b in bytes) - { - Console.Write(b); - Console.Write(" "); - } - Console.Write("\n"); - } } diff --git a/src/Transactions/AccountTransactionHeader.cs b/src/Transactions/AccountTransactionHeader.cs index 4ca90f5b..43777492 100644 --- a/src/Transactions/AccountTransactionHeader.cs +++ b/src/Transactions/AccountTransactionHeader.cs @@ -89,7 +89,7 @@ public Grpc.V2.AccountTransactionHeader ToProto() => }; /// - /// Converts the account transaction header to its corresponding protocol buffer message instance. + /// Creates an account transaction header from its corresponding protocol buffer message instance. /// internal static AccountTransactionHeader From(Grpc.V2.AccountTransactionHeader accountTransactionHeader) => new( AccountAddress.From(accountTransactionHeader.Sender), diff --git a/src/Transactions/AccountTransactionPayload.cs b/src/Transactions/AccountTransactionPayload.cs index de1bbb07..8eb8a785 100644 --- a/src/Transactions/AccountTransactionPayload.cs +++ b/src/Transactions/AccountTransactionPayload.cs @@ -123,27 +123,5 @@ private static AccountTransactionPayload ParseRawPayload(Google.Protobuf.ByteStr } return parsedPayload.Item1; } - - /// - /// Prepares the account transaction payload for signing. Will throw an - /// exception if AccountTransaction is of subtype RawPayload. Should only - /// be used for testing. - /// - /// Address of the sender of the transaction. - /// Account sequence number to use for the transaction. - /// Expiration time of the transaction. - internal PreparedAccountTransaction PrepareWithException( - AccountAddress sender, - AccountSequenceNumber sequenceNumber, - Expiry expiry - ) => this switch - { - Transfer transfer => transfer.Prepare(sender, sequenceNumber, expiry), - TransferWithMemo transferWithMemo => transferWithMemo.Prepare(sender, sequenceNumber, expiry), - DeployModule deployModule => deployModule.Prepare(sender, sequenceNumber, expiry), - RegisterData registerData => registerData.Prepare(sender, sequenceNumber, expiry), - _ => throw new NotImplementedException(), - }; - } diff --git a/src/Transactions/TransferWithMemo.cs b/src/Transactions/TransferWithMemo.cs index 6b582d16..65a534f2 100644 --- a/src/Transactions/TransferWithMemo.cs +++ b/src/Transactions/TransferWithMemo.cs @@ -47,7 +47,11 @@ Expiry expiry /// Memo to include with the transaction. private static byte[] Serialize(CcdAmount amount, AccountAddress receiver, OnChainData memo) { - using var memoryStream = new MemoryStream((int)(sizeof(TransactionType) + CcdAmount.BytesLength + AccountAddress.BytesLength + OnChainData.MaxLength)); + using var memoryStream = new MemoryStream((int)( + sizeof(TransactionType) + + CcdAmount.BytesLength + + AccountAddress.BytesLength + + OnChainData.MaxLength)); memoryStream.WriteByte(TransactionType); memoryStream.Write(receiver.ToBytes()); memoryStream.Write(memo.ToBytes()); diff --git a/src/Types/AccountAddress.cs b/src/Types/AccountAddress.cs index bc5dc4e0..a07f199f 100644 --- a/src/Types/AccountAddress.cs +++ b/src/Types/AccountAddress.cs @@ -11,6 +11,9 @@ namespace Concordium.Sdk.Types; /// public sealed record AccountAddress : IEquatable, IAddress, IAccountIdentifier { + /// + /// The serialized length of the account address. + /// public const uint BytesLength = 32; /// @@ -217,9 +220,9 @@ public Grpc.V2.AccountIdentifierInput ToAccountIdentifierInput() => new() { Address = this.ToProto() }; /// - /// Create an account address from a serialized as bytes. + /// Create an account address from a byte array. /// - /// The account address as bytes. + /// The serialized account address. /// Where to write the result of the operation. public static bool TryDeserial(byte[] bytes, out (AccountAddress? accountAddress, string? Error) output) { diff --git a/src/Types/CcdAmount.cs b/src/Types/CcdAmount.cs index 166a4357..6b4943bd 100644 --- a/src/Types/CcdAmount.cs +++ b/src/Types/CcdAmount.cs @@ -111,9 +111,9 @@ public static CcdAmount FromCcd(ulong ccd) } /// - /// Create a CCD amount from a serialized as bytes. + /// Create a CCD amount from a byte array. /// - /// The CCD amount as bytes. + /// The serialized CCD amount. /// Where to write the result of the operation. public static bool TryDeserial(byte[] bytes, out (CcdAmount? accountAddress, string? Error) output) { diff --git a/src/Types/OnChainData.cs b/src/Types/OnChainData.cs index 87d1946b..eb2f6fbd 100644 --- a/src/Types/OnChainData.cs +++ b/src/Types/OnChainData.cs @@ -136,9 +136,9 @@ public byte[] ToBytes() public override string ToString() => Convert.ToHexString(this._value).ToLowerInvariant(); /// - /// Create an account address from a serialized as bytes. + /// Create an "OnChainData" from a byte array. /// - /// The account address as bytes. + /// The serialized "OnChainData". /// Where to write the result of the operation. public static bool TryDeserial(byte[] bytes, out (OnChainData? accountAddress, string? Error) output) { diff --git a/src/Types/VersionedModuleSource.cs b/src/Types/VersionedModuleSource.cs index 7430c8f1..67a86337 100644 --- a/src/Types/VersionedModuleSource.cs +++ b/src/Types/VersionedModuleSource.cs @@ -48,7 +48,12 @@ internal static VersionedModuleSource From(Grpc.V2.VersionedModuleSource version .ModuleCase) }; - internal static bool TryDeserial(byte[] bytes, out (VersionedModuleSource? VersionedModuleSource, string? Error) output) + /// + /// Create a versioned module schema from a byte array. + /// + /// The serialized schema. + /// Where to write the result of the operation. + public static bool TryDeserial(byte[] bytes, out (VersionedModuleSource? VersionedModuleSource, string? Error) output) { var versionSuccess = Deserial.TryDeserialU32(bytes, 0, out var version);