-
Notifications
You must be signed in to change notification settings - Fork 139
/
InsufficientBalanceException.cs
61 lines (55 loc) · 2.13 KB
/
InsufficientBalanceException.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
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Runtime.Serialization;
using Libplanet.Assets;
using Libplanet.Serialization;
namespace Libplanet.Action
{
/// <summary>
/// The exception that is thrown when a sender has less <see cref="Balance"/> than amount to
/// transfer or an owner has less <see cref="Balance"/> than amount to burn.
/// </summary>
/// <seealso cref="IAccountStateDelta.TransferAsset"/>
/// <seealso cref="IAccountStateDelta.BurnAsset"/>
[Serializable]
public sealed class InsufficientBalanceException : Exception
{
/// <summary>
/// Creates a new <see cref="InsufficientBalanceException"/> object.
/// </summary>
/// <param name="message">Specifies a <see cref="Exception.Message"/>.</param>
/// <param name="address">The owner of the insufficient <paramref name="balance"/>.
/// Corresponds to the <see cref="Address"/> property.</param>
/// <param name="balance">The account's current balance.
/// Corresponds to the <see cref="Balance"/> property.</param>
public InsufficientBalanceException(
string? message,
Address address,
FungibleAssetValue balance
)
: base(message)
{
Address = address;
Balance = balance;
}
private InsufficientBalanceException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Address = info.GetValue<Address>(nameof(Address));
Balance = info.GetValue<FungibleAssetValue>(nameof(Balance));
}
/// <summary>
/// The owner of the insufficient <see cref="Balance"/>.
/// </summary>
public Address Address { get; }
/// <summary>
/// The account's current balance.
/// </summary>
public FungibleAssetValue Balance { get; }
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue(nameof(Address), Address);
info.AddValue(nameof(Balance), Balance);
}
}
}