/
IActionContext.cs
118 lines (106 loc) · 4.27 KB
/
IActionContext.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System.Diagnostics.Contracts;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Types.Blocks;
using Libplanet.Types.Tx;
namespace Libplanet.Action
{
/// <summary>
/// Contextual data determined by a transaction and a block.
/// Passed to <see cref="IAction.Execute(IActionContext)"/> method.
/// </summary>
public interface IActionContext
{
/// <summary>
/// The <see cref="Transaction.Signer"/> of the <see cref="Transaction"/> that contains
/// the <see cref="IAction"/> to be executed. If the <see cref="IAction"/> is
/// not part of a <see cref="Transaction"/>, e.g. <see cref="IBlockPolicy.BlockAction"/>,
/// this is set to <see cref="Block.Miner"/> instead.
/// </summary>
[Pure]
Address Signer { get; }
/// <summary>
/// The <see cref="Transaction.Id"/> of the <see cref="Transaction"/> that contains
/// the <see cref="IAction"/>. If the <see cref="IAction"/> is not part of
/// a <see cref="Transaction"/>, e.g. <see cref="IBlockPolicy.BlockAction"/>,
/// this is set to <see langword="null"/>.
/// </summary>
[Pure]
TxId? TxId { get; }
/// <summary>
/// The <see cref="Block.Miner"/> of the <see cref="Block"/> that contains
/// the <see cref="IAction"/>.
/// </summary>
[Pure]
Address Miner { get; }
/// <summary>
/// The <see cref="Block.Index"/> of the <see cref="Block"/> that contains
/// the <see cref="IAction"/>.
/// </summary>
[Pure]
long BlockIndex { get; }
/// <summary>
/// The <see cref="Block.ProtocolVersion"/> of the <see cref="Block"/> that contains
/// the <see cref="IAction"/>.
/// </summary>
[Pure]
int BlockProtocolVersion { get; }
/// <summary>
/// A null delta of states, which means it represents the states
/// before <see cref="IAction"/> executes.
/// <para>Although a <see cref="IAccount"/> instance is
/// immutable, it has several manipulative methods that returns
/// new <see cref="IAccount"/> instances with some "dirty"
/// states. These kinds of dirty <see cref="IWorld"/>
/// instances can be returned by <see
/// cref="IAction.Execute(IActionContext)"/> method.</para>
/// </summary>
[Pure]
IWorld PreviousState { get; }
/// <summary>
/// The random seed to use for pseudorandom number generator. This value
/// is determined by various block properties, the signature of the transaction
/// containing the action to execute, and index of the action to execute, which is
/// deterministic so that every node can replay the same action and
/// then reproduce the same result, while neither a single block miner
/// nor a single transaction signer can predict the result and cheat.
/// </summary>
/// <seealso cref="GetRandom"/>
int RandomSeed { get; }
/// <summary>
/// Whether this action is executed as a block action.
/// <see langword="false"/> if it belongs to a transaction.
/// </summary>
[Pure]
bool BlockAction { get; }
/// <summary>
/// Consumes the specified amount of gas.
/// </summary>
/// <param name="gas">
/// The amount of gas to consume.
/// </param>
void UseGas(long gas);
/// <summary>
/// Returns a newly initialized <see cref="IRandom"/> using <see cref="RandomSeed"/>
/// as its seed value.
/// </summary>
/// <returns>A newly initialized <see cref="IRandom"/> using <see cref="RandomSeed"/>
/// as its seed value.</returns>
[Pure]
IRandom GetRandom();
/// <summary>
/// Returns the total gas used by the current action.
/// </summary>
/// <returns>The total gas used by the current action.</returns>
[Pure]
long GasUsed();
/// <summary>
/// Returns the limit gas of the current action.
/// </summary>
/// <returns>
/// The limit gas of the current action.
/// </returns>
[Pure]
long GasLimit();
}
}