Class VolatileStagePolicy<T>
An in memory implementation of the IStagePolicy<T>.
This implementation holds on to every unconfirmed Transaction<T> except for the following reasons:
- A Transaction<T> has been specifically marked to be ignored due to Transaction<T> not being valid.
- A Transaction<T> has expired due to its staleness.
Additionally, any Transaction<T> with a lower nonce than that of returned by the BlockChain<T> is masked and filtered by default.
Implements
Namespace: Libplanet.Blockchain.Policies
Assembly: Libplanet.dll
Syntax
public class VolatileStagePolicy<T> : object, IStagePolicy<T> where T : IAction, new()
Type Parameters
| Name | Description |
|---|---|
| T | An IAction type. It should match the BlockChain<T>'s type parameter. |
Constructors
| Improve this Doc View SourceVolatileStagePolicy()
Creates a new VolatileStagePolicy<T> instance. By default, Lifetime is configured to 3 hours.
Declaration
public VolatileStagePolicy()
VolatileStagePolicy(TimeSpan)
Creates a new VolatileStagePolicy<T> instance.
Declaration
public VolatileStagePolicy(TimeSpan lifetime)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | lifetime | Volatilizes staged transactions older than this
|
Properties
| Improve this Doc View SourceLifetime
Lifespan for Transaction<T>s. Any Transaction<T> older
than this
Declaration
public TimeSpan Lifetime { get; }
Property Value
| Type | Description |
|---|---|
| TimeSpan |
Remarks
Expired Transaction<T>s cannot be staged.
Methods
| Improve this Doc View SourceGet(BlockChain<T>, TxId, Boolean)
Retrieves a staged Transaction<T> by its id.
Declaration
public Transaction<T> Get(BlockChain<T> blockChain, TxId id, bool filtered = true)
Parameters
| Type | Name | Description |
|---|---|---|
| BlockChain<T> | blockChain | The BlockChain<T> that the stage belongs to. |
| TxId | id | The Id to get. |
| Boolean | filtered | Whether to filter masked staged Transaction<T>s
or not. Set to |
Returns
| Type | Description |
|---|---|
| Transaction<T> | The staged Transaction<T> associated with |
GetNextTxNonce(BlockChain<T>, Address)
Calculates the next nonce according for given address.
Declaration
public long GetNextTxNonce(BlockChain<T> blockChain, Address address)
Parameters
| Type | Name | Description |
|---|---|---|
| BlockChain<T> | blockChain | The BlockChain<T> that the stage belongs to. |
| Address | address | The Address to calculate the next nonce for. |
Returns
| Type | Description |
|---|---|
| Int64 | The next appropriate nonce for |
Ignore(BlockChain<T>, TxId)
Marks given id as ignored.
Declaration
public void Ignore(BlockChain<T> blockChain, TxId id)
Parameters
| Type | Name | Description |
|---|---|---|
| BlockChain<T> | blockChain | The BlockChain<T> that the stage belongs to. |
| TxId | id | The Id to ignore. |
Remarks
If the Transaction<T> associated with id is already
staged, this also unstages the Transaction<T>.
Ignores(BlockChain<T>, TxId)
Checks if given id is marked as ignored.
Declaration
public bool Ignores(BlockChain<T> blockChain, TxId id)
Parameters
| Type | Name | Description |
|---|---|---|
| BlockChain<T> | blockChain | The BlockChain<T> that the stage belongs to. |
| TxId | id | The Id to check. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Iterate(BlockChain<T>, Boolean)
Enumerates all staged Transaction<T>s.
Declaration
public IEnumerable<Transaction<T>> Iterate(BlockChain<T> blockChain, bool filtered = true)
Parameters
| Type | Name | Description |
|---|---|---|
| BlockChain<T> | blockChain | The BlockChain<T> that the stage belongs to. |
| Boolean | filtered | Whether to filter masked staged Transaction<T>s
or not. Set to |
Returns
| Type | Description |
|---|---|
| IEnumerable<Transaction<T>> | All staged transactions. No ordering is guaranteed. |
Stage(BlockChain<T>, Transaction<T>)
Stages a transaction.
Declaration
public bool Stage(BlockChain<T> blockChain, Transaction<T> transaction)
Parameters
| Type | Name | Description |
|---|---|---|
| BlockChain<T> | blockChain | The BlockChain<T> that the stage belongs to. |
| Transaction<T> | transaction | The Transaction<T> to be staged. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Remarks
This does not throw any exception regardless of whether transaction
was successfully staged or not.
If the Id of transaction is marked
as ignored, transaction will not be staged.
Unstage(BlockChain<T>, TxId)
Unstages a transaction id.
Declaration
public bool Unstage(BlockChain<T> blockChain, TxId id)
Parameters
| Type | Name | Description |
|---|---|---|
| BlockChain<T> | blockChain | The BlockChain<T> that the stage belongs to. |
| TxId | id | The Id to unstage. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Remarks
This does not throw any exception regardless of whether id was
successfully unstaged or not.