-
Notifications
You must be signed in to change notification settings - Fork 3
/
SignedAccountTransaction.cs
49 lines (45 loc) · 1.93 KB
/
SignedAccountTransaction.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
42
43
44
45
46
47
48
49
using Concordium.Grpc.V2;
namespace Concordium.Sdk.Transactions;
/// <summary>
/// Represents a signed account transaction which is ready to be sent to the node.
///
/// A signed account transaction constitutes an <see cref="AccountTransactionHeader"/>, an
/// <see cref="AccountTransactionPayload"/> as well as an <see cref="AccountTransactionSignature"/>.
///
/// A <see cref="SignedAccountTransaction"/> can be created with the
/// <see cref="PreparedAccountTransaction.Sign"/> method with an implementer of
/// <see cref="ITransactionSigner"/>.
/// </summary>
/// <param name="Header">Header of the signed account transaction.</param>
/// <param name="Payload">Payload of the signed account transaction.</param>
/// <param name="Signature">Signature of the signed account transaction.</param>
public record SignedAccountTransaction(
AccountTransactionHeader Header,
AccountTransactionPayload Payload,
AccountTransactionSignature Signature
) : BlockItemType
{
/// <summary>Converts this type to the equivalent protocol buffer type.</summary>
public AccountTransaction ToProto() => new()
{
Header = this.Header.ToProto(),
Payload = this.Payload.ToProto(),
Signature = this.Signature.ToProto(),
};
internal static SignedAccountTransaction From(AccountTransaction accountTransaction)
{
var payload = AccountTransactionPayload.From(accountTransaction.Payload);
return new(
AccountTransactionHeader.From(accountTransaction.Header, payload.Size()),
payload,
AccountTransactionSignature.From(accountTransaction.Signature)
);
}
/// <summary>
/// Converts the signed account transaction to a protocol buffer
/// message instance which is compatible with
/// <see cref="Client.RawClient.SendBlockItem"/>.
/// </summary>
public SendBlockItemRequest ToSendBlockItemRequest() =>
new() { AccountTransaction = this.ToProto() };
}