Skip to content

Commit

Permalink
Self-review
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmus-kirk committed Nov 28, 2023
1 parent 7404cb6 commit 30838ed
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 63 deletions.
18 changes: 0 additions & 18 deletions examples/GetBlockPendingUpdates/GetBlocks.csproj

This file was deleted.

2 changes: 1 addition & 1 deletion src/Exceptions/DeserialException.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Concordium.Sdk.Exceptions;

/// <summary>
/// Thrown when a matched enum value could not be handled in a switch statement.
/// Thrown when deserialization fails and is explicitly meant not to.
/// </summary>
public sealed class DeserialException : Exception
{
Expand Down
14 changes: 1 addition & 13 deletions src/Helpers/Deserialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static bool TryDeserialU32(byte[] input, int offset, out (uint? Uint, str
}

/// <summary>
/// Creates a uint from a byte array.
/// Creates a ulong from a byte array.
/// </summary>
public static bool TryDeserialU64(byte[] input, int offset, out (ulong? Ulong, string? Error) output)
{
Expand All @@ -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");
}
}


2 changes: 1 addition & 1 deletion src/Transactions/AccountTransactionHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public Grpc.V2.AccountTransactionHeader ToProto() =>
};

/// <summary>
/// Converts the account transaction header to its corresponding protocol buffer message instance.
/// Creates an account transaction header from its corresponding protocol buffer message instance.
/// </summary>
internal static AccountTransactionHeader From(Grpc.V2.AccountTransactionHeader accountTransactionHeader) => new(
AccountAddress.From(accountTransactionHeader.Sender),
Expand Down
22 changes: 0 additions & 22 deletions src/Transactions/AccountTransactionPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,5 @@ private static AccountTransactionPayload ParseRawPayload(Google.Protobuf.ByteStr
}
return parsedPayload.Item1;
}

/// <summary>
/// Prepares the account transaction payload for signing. Will throw an
/// exception if AccountTransaction is of subtype RawPayload. Should only
/// be used for testing.
/// </summary>
/// <param name="sender">Address of the sender of the transaction.</param>
/// <param name="sequenceNumber">Account sequence number to use for the transaction.</param>
/// <param name="expiry">Expiration time of the transaction.</param>
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(),
};

}

6 changes: 5 additions & 1 deletion src/Transactions/TransferWithMemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ Expiry expiry
/// <param name="memo">Memo to include with the transaction.</param>
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());
Expand Down
7 changes: 5 additions & 2 deletions src/Types/AccountAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ namespace Concordium.Sdk.Types;
/// </summary>
public sealed record AccountAddress : IEquatable<AccountAddress>, IAddress, IAccountIdentifier
{
/// <summary>
/// The serialized length of the account address.
/// </summary>
public const uint BytesLength = 32;

/// <summary>
Expand Down Expand Up @@ -217,9 +220,9 @@ public Grpc.V2.AccountIdentifierInput ToAccountIdentifierInput() =>
new() { Address = this.ToProto() };

/// <summary>
/// Create an account address from a serialized as bytes.
/// Create an account address from a byte array.
/// </summary>
/// <param name="bytes">The account address as bytes.</param>
/// <param name="bytes">The serialized account address.</param>
/// <param name="output">Where to write the result of the operation.</param>
public static bool TryDeserial(byte[] bytes, out (AccountAddress? accountAddress, string? Error) output)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Types/CcdAmount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ public static CcdAmount FromCcd(ulong ccd)
}

/// <summary>
/// Create a CCD amount from a serialized as bytes.
/// Create a CCD amount from a byte array.
/// </summary>
/// <param name="bytes">The CCD amount as bytes.</param>
/// <param name="bytes">The serialized CCD amount.</param>
/// <param name="output">Where to write the result of the operation.</param>
public static bool TryDeserial(byte[] bytes, out (CcdAmount? accountAddress, string? Error) output)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Types/OnChainData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ public byte[] ToBytes()
public override string ToString() => Convert.ToHexString(this._value).ToLowerInvariant();

/// <summary>
/// Create an account address from a serialized as bytes.
/// Create an "OnChainData" from a byte array.
/// </summary>
/// <param name="bytes">The account address as bytes.</param>
/// <param name="bytes">The serialized "OnChainData".</param>
/// <param name="output">Where to write the result of the operation.</param>
public static bool TryDeserial(byte[] bytes, out (OnChainData? accountAddress, string? Error) output)
{
Expand Down
7 changes: 6 additions & 1 deletion src/Types/VersionedModuleSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
/// <summary>
/// Create a versioned module schema from a byte array.
/// </summary>
/// <param name="bytes">The serialized schema.</param>
/// <param name="output">Where to write the result of the operation.</param>
public static bool TryDeserial(byte[] bytes, out (VersionedModuleSource? VersionedModuleSource, string? Error) output)
{
var versionSuccess = Deserial.TryDeserialU32(bytes, 0, out var version);

Expand Down

0 comments on commit 30838ed

Please sign in to comment.