-
Notifications
You must be signed in to change notification settings - Fork 3
/
TransactionHash.cs
41 lines (35 loc) · 1.56 KB
/
TransactionHash.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
namespace Concordium.Sdk.Types;
/// <summary>
/// Represents a transaction hash.
/// </summary>
public sealed record TransactionHash : Hash
{
private TransactionHash(string transactionHashAsBase16String)
: base(transactionHashAsBase16String) { }
private TransactionHash(byte[] transactionHashAsBytes)
: base(transactionHashAsBytes) { }
/// <summary>
/// Creates an instance from a transaction hash represented by a length-64 encoded string.
/// </summary>
/// <param name="transactionHashAsBase16String">The transaction hash represented by a length-64 encoded string.</param>
public static TransactionHash From(string transactionHashAsBase16String) =>
new(transactionHashAsBase16String);
/// <summary>
/// Creates an instance from a transaction hash represented by a length-32 byte array.
/// </summary>
/// <param name="transactionHashAsBytes">The transaction hash represented by a length-32 byte array</param>
public static TransactionHash From(byte[] transactionHashAsBytes) =>
new(transactionHashAsBytes);
internal static TransactionHash From(Grpc.V2.TransactionHash proto) =>
new(proto.Value.ToArray());
/// <summary>
/// Converts the transaction hash to its corresponding protocol buffer message instance.
///
/// This can be used as the input for class methods of <see cref="Client.RawClient"/>.
/// </summary>
public Grpc.V2.TransactionHash ToProto() =>
new()
{
Value = Google.Protobuf.ByteString.CopyFrom(this.ToBytes())
};
}