/
InvalidTxNonceException.cs
57 lines (54 loc) · 2.11 KB
/
InvalidTxNonceException.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
using System;
using System.Diagnostics.CodeAnalysis;
using Libplanet.Blockchain;
namespace Libplanet.Tx
{
/// <summary>
/// The exception that is thrown when the <see cref="Transaction{T}.Nonce"/>
/// is different from <see cref="BlockChain{T}.GetNextTxNonce"/> result of
/// the <see cref="Transaction{T}.Signer"/>.
/// </summary>
[Serializable]
public sealed class InvalidTxNonceException : InvalidTxException
{
/// <summary>
/// Initializes a new instance of the
/// <see cref="InvalidTxNonceException"/> class.
/// </summary>
/// <param name="message">The message that describes the error.</param>
/// <param name="txid">The invalid <see cref="Transaction{T}"/>'s
/// <see cref="Transaction{T}.Id"/>. It is automatically included to
/// the <see cref="Exception.Message"/> string.</param>
/// <param name="expectedNonce"><see cref="BlockChain{T}.GetNextTxNonce"/>
/// result of the <see cref="Transaction{T}.Signer"/>.</param>
/// <param name="improperNonce">The actual
/// <see cref="Transaction{T}.Nonce"/>.</param>
[SuppressMessage(
"Microsoft.StyleCop.CSharp.ReadabilityRules",
"SA1118",
Justification = "A long error message should be multiline.")]
public InvalidTxNonceException(
string message,
TxId txid,
long expectedNonce,
long improperNonce)
: base(
$"{message}\n" +
$"Expected nonce: {expectedNonce}\n" +
$"Improper nonce: {improperNonce}",
txid)
{
ExpectedNonce = expectedNonce;
ImproperNonce = improperNonce;
}
/// <summary>
/// <see cref="BlockChain{T}.GetNextTxNonce"/> result of the
/// <see cref="Transaction{T}.Signer"/>.
/// </summary>
public long ExpectedNonce { get; }
/// <summary>
/// The actual <see cref="Transaction{T}.Nonce"/>, which is improper.
/// </summary>
public long ImproperNonce { get; }
}
}