Interface IBlockPolicy<T>
An interface to determine if consecutive Block<T>s are valid, and to suggest how difficult a Nonce for a Block<T> to be mined.
Namespace: Libplanet.Blockchain.Policies
Assembly: Libplanet.dll
Syntax
public interface IBlockPolicy<T>
where T : IAction, new()
Type Parameters
Name | Description |
---|---|
T | An IAction type. It should match to Block<T>'s type parameter. |
Properties
| Improve this Doc View SourceBlockAction
A block action to execute and be rendered for every block.
Declaration
IAction BlockAction { get; }
Property Value
Type | Description |
---|---|
IAction |
MaxTransactionsPerBlock
The maximum number of Transactions that a Block<T> can accept. This value must not be negative and must be deterministic (i.e., must not change after an object is once instantiated).
Declaration
int MaxTransactionsPerBlock { get; }
Property Value
Type | Description |
---|---|
Int32 |
Remarks
If the value is less then 1, it's treated as 1.
Methods
| Improve this Doc View SourceDoesTransactionFollowsPolicy(Transaction<T>, BlockChain<T>)
A predicate that determines if the transaction follows the block policy.
Declaration
bool DoesTransactionFollowsPolicy(Transaction<T> transaction, BlockChain<T> blockChain)
Parameters
Type | Name | Description |
---|---|---|
Transaction<T> | transaction | A Transaction<T> to determine. |
BlockChain<T> | blockChain | A BlockChain<T> for given
|
Returns
Type | Description |
---|---|
Boolean |
|
GetMaxBlockBytes(Int64)
Gets the maximum length of a Block<T> in bytes. It can vary depending on
a given index
, but should be deterministic; for the same
index
, the same value must be returned.
Declaration
int GetMaxBlockBytes(long index)
Parameters
Type | Name | Description |
---|---|---|
Int64 | index | An Index of a block to mine or receive. |
Returns
Type | Description |
---|---|
Int32 | The maximum length of a Block<T> in bytes to accept. |
Remarks
If it returns less then 1, it is treated as 1, because there is no block taking 0 bytes or negative length of bytes.
GetNextBlockDifficulty(BlockChain<T>)
Determines a right Difficulty
for a new Block<T> to be mined
right after the given blocks
.
Declaration
long GetNextBlockDifficulty(BlockChain<T> blocks)
Parameters
Type | Name | Description |
---|---|---|
BlockChain<T> | blocks | Consecutive Block<T>s to be followed by a new Block<T> to be mined. |
Returns
Type | Description |
---|---|
Int64 | A right Difficulty for a new Block<T> to be mined. |
ValidateNextBlock(BlockChain<T>, Block<T>)
Checks if nextBlock
is invalid, and if that
returns the reason.
Note that it returns null
when
nextBlock
is valid.
Declaration
InvalidBlockException ValidateNextBlock(BlockChain<T> blocks, Block<T> nextBlock)
Parameters
Type | Name | Description |
---|---|---|
BlockChain<T> | blocks | Consecutive Block<T>s to
append |
Block<T> | nextBlock | The next block to append to
|
Returns
Type | Description |
---|---|
InvalidBlockException | The reason why the given |