-
Notifications
You must be signed in to change notification settings - Fork 138
/
IBlockPolicy.cs
58 lines (54 loc) · 2.48 KB
/
IBlockPolicy.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
using Libplanet.Action;
using Libplanet.Blocks;
using Libplanet.Tx;
namespace Libplanet.Blockchain.Policies
{
/// <summary>
/// An interface to determine if consecutive <see cref="Block{T}"/>s are
/// valid, and to suggest how difficult a <see cref="Block{T}.Nonce"/>
/// for a <see cref="Block{T}"/> to be mined.
/// </summary>
/// <typeparam name="T">An <see cref="IAction"/> type. It should match
/// to <see cref="Block{T}"/>'s type parameter.</typeparam>
public interface IBlockPolicy<T>
where T : IAction, new()
{
/// <summary>
/// A block action to execute and be rendered for every block.
/// </summary>
IAction BlockAction { get; }
/// <summary>
/// A predicate that determines if the transaction follows the block policy.
/// </summary>
/// <param name="transaction">A <see cref="Transaction{T}"/> to determine.</param>
/// <returns><c>true</c> if <paramref name="transaction"/>is valid; otherwise, <c>false</c>.
/// </returns>
bool DoesTransactionFollowsPolicy(Transaction<T> transaction);
/// <summary>
/// Checks if <paramref name="nextBlock"/> is invalid, and if that
/// returns the reason.
/// <para>Note that it returns <c>null</c> when
/// <paramref name="nextBlock"/> is <em>valid</em>.</para>
/// </summary>
/// <param name="blocks">Consecutive <see cref="Block{T}"/>s to
/// append <paramref name="nextBlock"/>.</param>
/// <param name="nextBlock">The next block to append to
/// <paramref name="blocks"/>.</param>
/// <returns>The reason why the given <paramref name="blocks"/> are
/// <em>invalid</em>, or <c>null</c> if <paramref name="blocks"/> are
/// <em>valid</em>.</returns>
InvalidBlockException ValidateNextBlock(
BlockChain<T> blocks,
Block<T> nextBlock);
/// <summary>
/// Determines a right <see cref="Block{T}.Difficulty"/>
/// for a new <see cref="Block{T}"/> to be mined
/// right after the given <paramref name="blocks"/>.
/// </summary>
/// <param name="blocks">Consecutive <see cref="Block{T}"/>s to be
/// followed by a new <see cref="Block{T}"/> to be mined.</param>
/// <returns>A right <see cref="Block{T}.Difficulty"/>
/// for a new <see cref="Block{T}"/> to be mined.</returns>
long GetNextBlockDifficulty(BlockChain<T> blocks);
}
}