Show / Hide Table of Contents

Class DelayedActionRenderer<T>

An IActionRenderer<T> version of DelayedRenderer<T>.

Decorates an IActionRenderer<T> instance and delays the events until blocks are confirmed the certain number of blocks. When blocks are recognized the delayed events relevant to these blocks are relayed to the decorated IActionRenderer<T>.

Inheritance
Object
DelayedRenderer<T>
DelayedActionRenderer<T>
Implements
IActionRenderer<T>
IRenderer<T>
Inherited Members
DelayedRenderer<T>.Renderer
DelayedRenderer<T>.CanonicalChainComparer
DelayedRenderer<T>.Store
DelayedRenderer<T>.HashAlgorithmGetter
DelayedRenderer<T>.Confirmations
DelayedRenderer<T>.Tip
DelayedRenderer<T>.Logger
DelayedRenderer<T>.Confirmed
DelayedRenderer<T>.DiscoverBlock(Block<T>, Block<T>)
Namespace: Libplanet.Blockchain.Renderers
Assembly: Libplanet.dll
Syntax
public class DelayedActionRenderer<T> : DelayedRenderer<T>, IActionRenderer<T>, IRenderer<T> where T : IAction, new()
Type Parameters
Name Description
T

An IAction type. It should match to BlockChain<T>'s type parameter.

Examples
IStore store = GetStore();
IBlockPolicy<ExampleAction> policy = GetPolicy();
IActionRenderer<ExampleAction> actionRenderer = new SomeActionRenderer();
// Wraps the actionRenderer with DelayedActionRenderer; the SomeActionRenderer instance
// becomes to receive event messages only after the relevent blocks are confirmed
// by 3+ blocks.
actionRenderer = new DelayedActionRenderer<ExampleAction>(
   actionRenderer,
   policy,
   store,
   confirmations: 3);
// You must pass the same policy & store to the BlockChain<T>() constructor:
var chain = new BlockChain<ExampleAction>(
   ...,
   policy: policy,
   store: store,
   renderers: new[] { actionRenderer });

Constructors

| Improve this Doc View Source

DelayedActionRenderer(IActionRenderer<T>, IComparer<IBlockExcerpt>, IStore, HashAlgorithmGetter, Int32, Int64)

Creates a new DelayedActionRenderer<T> instance decorating the given renderer.

Declaration
public DelayedActionRenderer(IActionRenderer<T> renderer, IComparer<IBlockExcerpt> canonicalChainComparer, IStore store, HashAlgorithmGetter hashAlgorithmGetter, int confirmations, long reorgResistantHeight = null)
Parameters
Type Name Description
IActionRenderer<T> renderer

The renderer to decorate which has the actual implementations and receives delayed events.

IComparer<IBlockExcerpt> canonicalChainComparer

The same canonical chain comparer to Policy.

IStore store

The same store to what BlockChain<T> uses.

HashAlgorithmGetter hashAlgorithmGetter

The function to determine hash algorithm used for proof-of-work mining.

Int32 confirmations

The required number of confirmations to recognize a block. See also the Confirmations property.

Int64 reorgResistantHeight

Configures the height of blocks to maintain the ActionEvaluation buffer. Buffered ActionEvaluations that belong to blocks older than this height from the tip are gone. If zero, which is a default value, is passed the buffer is not cleared.

Properties

| Improve this Doc View Source

ActionRenderer

The inner action renderer which has the actual implementations and receives delayed events.

Declaration
public IActionRenderer<T> ActionRenderer { get; }
Property Value
Type Description
IActionRenderer<T>

Methods

| Improve this Doc View Source

OnTipChanged(Block<T>, Block<T>, Block<T>)

The callback method which is invoked when the new Tip is recognized and changed.

Declaration
protected override void OnTipChanged(Block<T> oldTip, Block<T> newTip, Block<T> branchpoint)
Parameters
Type Name Description
Block<T> oldTip

The previously recognized topmost block.

Block<T> newTip

The topmost block recognized this time.

Block<T> branchpoint

A branchpoint between oldTip and newTip if the tip change is a reorg. Otherwise null.

Overrides
Libplanet.Blockchain.Renderers.DelayedRenderer<T>.OnTipChanged(Libplanet.Blocks.Block<T>, Libplanet.Blocks.Block<T>, Libplanet.Blocks.Block<T>)
| Improve this Doc View Source

RenderAction(IAction, IActionContext, IAccountStateDelta)

Does things that should be done right after an action is executed and applied to the blockchain.

Declaration
public void RenderAction(IAction action, IActionContext context, IAccountStateDelta nextStates)
Parameters
Type Name Description
IAction action

An executed action.

IActionContext context

The equivalent context object to an object passed to the action's Execute(IActionContext) method. That means PreviousStates are the states right before this action executed. For the states after this action executed, use the nextStates argument instead.

IAccountStateDelta nextStates

The states right after this action executed, which means it is equivalent to the states action's Execute(IActionContext) method returned.

Remarks

It is guaranteed to be called only once for an action, and only after applied to the blockchain, unless an exception is thrown during executing the action (in that case RenderActionError(IAction, IActionContext, Exception) is called instead) or once the action has been unrendered.

Also note that this method is invoked after RenderBlock(Block<T>, Block<T>) method is called (where its second parameter newTip contains a transaction the action belongs to).

The reason why the parameter action takes IAction instead of T is because it can take block actions (BlockAction) besides transaction actions (Actions).

| Improve this Doc View Source

RenderActionError(IAction, IActionContext, Exception)

Does the similar things to RenderAction(IAction, IActionContext, IAccountStateDelta), except that this method is invoked when action has terminated with an exception.

Declaration
public void RenderActionError(IAction action, IActionContext context, Exception exception)
Parameters
Type Name Description
IAction action

An action which threw an exception during execution.

IActionContext context

The equivalent context object to an object passed to the action's Execute(IActionContext) method. That means PreviousStates are the states right before this action executed.

Exception exception

The exception thrown during executing the action.

Remarks

Also note that this method is invoked after RenderBlock(Block<T>, Block<T>) method is called (where its second parameter newTip contains a transaction the action belongs to).

The reason why the parameter action takes IAction instead of T is because it can take block actions (BlockAction) besides transaction actions (Actions).

| Improve this Doc View Source

RenderBlock(Block<T>, Block<T>)

Does things that should be done right after a new Block<T> is appended to a BlockChain<T> (so that its Tip has changed).

Declaration
public override void RenderBlock(Block<T> oldTip, Block<T> newTip)
Parameters
Type Name Description
Block<T> oldTip

The previous Tip.

Block<T> newTip

The current Tip.

Overrides
Libplanet.Blockchain.Renderers.DelayedRenderer<T>.RenderBlock(Libplanet.Blocks.Block<T>, Libplanet.Blocks.Block<T>)
Remarks

It is guaranteed to be called only once for a block, and only after applied to the blockchain, unless it has been stale due to reorg (for that case, RenderReorg(Block<T>, Block<T>, Block<T>) is called in advance).

| Improve this Doc View Source

RenderBlockEnd(Block<T>, Block<T>)

Does things that should be done right all actions in a new Block<T> are rendered.

Declaration
public void RenderBlockEnd(Block<T> oldTip, Block<T> newTip)
Parameters
Type Name Description
Block<T> oldTip

The previous Tip.

Block<T> newTip

The current Tip.

Remarks

It is guaranteed to be called only once for a block.

| Improve this Doc View Source

RenderReorg(Block<T>, Block<T>, Block<T>)

Does things that should be done right before reorg happens to a BlockChain<T>.

Declaration
public override void RenderReorg(Block<T> oldTip, Block<T> newTip, Block<T> branchpoint)
Parameters
Type Name Description
Block<T> oldTip

The Tip right before reorg.

Block<T> newTip

The Tip after reorg.

Block<T> branchpoint

The highest common Block<T> between oldTip and newTip.

Overrides
Libplanet.Blockchain.Renderers.DelayedRenderer<T>.RenderReorg(Libplanet.Blocks.Block<T>, Libplanet.Blocks.Block<T>, Libplanet.Blocks.Block<T>)
Remarks

For every call to this method, calls to RenderBlock(Block<T>, Block<T>) and RenderReorgEnd(Block<T>, Block<T>, Block<T>) methods with the same newTip is made too. Note that this method is guaranteed to be called before RenderBlock(Block<T>, Block<T>) method for the same newTip.

| Improve this Doc View Source

RenderReorgEnd(Block<T>, Block<T>, Block<T>)

Does things that should be done right after reorg happens to a BlockChain<T>.

Declaration
public override void RenderReorgEnd(Block<T> oldTip, Block<T> newTip, Block<T> branchpoint)
Parameters
Type Name Description
Block<T> oldTip

The Tip right before reorg.

Block<T> newTip

The Tip after reorg.

Block<T> branchpoint

The highest common Block<T> between oldTip and newTip.

Overrides
Libplanet.Blockchain.Renderers.DelayedRenderer<T>.RenderReorgEnd(Libplanet.Blocks.Block<T>, Libplanet.Blocks.Block<T>, Libplanet.Blocks.Block<T>)
Remarks

Note that this method is guaranteed to be called after RenderReorg(Block<T>, Block<T>, Block<T>) and RenderBlock(Block<T>, Block<T>) methods for the same newTip.

| Improve this Doc View Source

UnrenderAction(IAction, IActionContext, IAccountStateDelta)

Does things that should be undone right after the given action is invalidated (mostly due to reorg, i.e., a block which the action has belonged to becomes considered stale).

This method takes the equivalent arguments to RenderAction(IAction, IActionContext, IAccountStateDelta) method.

Declaration
public void UnrenderAction(IAction action, IActionContext context, IAccountStateDelta nextStates)
Parameters
Type Name Description
IAction action

A stale action.

IActionContext context

The equivalent context object to an object passed to the action's Execute(IActionContext) method. That means PreviousStates are the states right before this action executed. For the states after this action executed, use the nextStates argument instead.

IAccountStateDelta nextStates

The states right after this action executed, which means it is equivalent to the states action's Execute(IActionContext) method returned.

Remarks

As a rule of thumb, this should be the inverse of RenderAction(IAction, IActionContext, IAccountStateDelta) method with redrawing the graphics on the display at the finish.

| Improve this Doc View Source

UnrenderActionError(IAction, IActionContext, Exception)

Does the similar things to UnrenderAction(IAction, IActionContext, IAccountStateDelta), except that this method is invoked when action has terminated with an exception.

This method takes the equivalent arguments to RenderActionError(IAction, IActionContext, Exception) method.

Declaration
public void UnrenderActionError(IAction action, IActionContext context, Exception exception)
Parameters
Type Name Description
IAction action

An action which threw an exception during execution.

IActionContext context

The equivalent context object to an object passed to the action's Execute(IActionContext) method. That means PreviousStates are the states right before this action executed.

Exception exception

The exception thrown during executing the action.

Remarks

The reason why the parameter action takes IAction instead of T is because it can take block actions (BlockAction) besides transaction actions (Actions).

Implements

IActionRenderer<T>
IRenderer<T>
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2021 Planetarium