Show / Hide Table of Contents

Class Utils.DummyAction

Inheritance
Object
Utils.DummyAction
Implements
IAction
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: Libplanet.Extensions.Cocona
Assembly: Libplanet.Extensions.Cocona.dll
Syntax
public class DummyAction : IAction

Constructors

| Improve this Doc View Source

DummyAction()

Declaration
public DummyAction()

Properties

| Improve this Doc View Source

PlainValue

Serializes values bound to an action, which is held by properties (or fields) of an action, so that they can be transmitted over network or saved to persistent storage.

Serialized values are deserialized by LoadPlainValue(IValue) method later.

Declaration
public IValue PlainValue { get; }
Property Value
Type Description
Bencodex.Types.IValue

A Bencodex value which encodes this action's bound values (held by properties or fields).

See Also
LoadPlainValue(Bencodex.Types.IValue)

Methods

| Improve this Doc View Source

Execute(IActionContext)

Executes the main game logic of an action. This should be deterministic.

Through the context object, it receives information such as a transaction signer, its states immediately before the execution, and a deterministic random seed.

Other “bound” information resides in the action object in itself, as its properties (or fields).

A returned IAccount object functions as a delta which shifts from previous states to next states.

Declaration
public IAccount Execute(IActionContext context)
Parameters
Type Name Description
IActionContext context

A context object containing addresses that signed the transaction, states immediately before the execution, and a PRNG object which produces deterministic random numbers. See IActionContext for details.

Returns
Type Description
IAccount

A map of changed states (so-called "dirty").

Remarks

This method should be deterministic: for structurally (member-wise) equal actions and IActionContexts, the same result should be returned. Side effects should be avoided, because an action's Execute(IActionContext) method can be called more than once, the time it's called is difficult to predict.

For changing in-memory game states or drawing graphics, implement the interface separately and attach it to a instance.

For randomness, never use Random nor any other PRNGs provided by other than Libplanet. Use Random instead. Random guarantees the same action has the consistent result for every node in the network.

Also do not perform I/O operations such as file system access or networking. These bring an action indeterministic. You maybe fine to log messages for debugging purpose, but equivalent messages could be logged multiple times.

Although it might be surprising, floating-point arithmetics are underspecified so that it can make different results on different machines, platforms, runtimes, compilers, and builds.

Lastly, you need to be aware and keep in mind that there is a global state named CurrentCulture on .NET; if you format numbers, dates and times, currencies, or other such things into strings and parse these strings back these can rely on CurrentCulture, so that the same action make different results on two differently configured systems like Thai language and French language. In order to make these types of conversions deterministic, you have to explicitly pass InvariantCulture.

For more on determinism in general, please read also Tendermint ABCI's docs on determinism.

Lastly, you can conduct static analysis on your code using Libplanet.Analyzers. The analyzer can be enabled by adding its NuGet package into your project as a dependency.

See Also
IActionContext
| Improve this Doc View Source

LoadPlainValue(IValue)

Deserializes serialized data (i.e., data PlainValue property made), and then fills this action's properties (or fields) with the deserialized values.

Declaration
public void LoadPlainValue(IValue plainValue)
Parameters
Type Name Description
Bencodex.Types.IValue plainValue

Data (made by PlainValue property) to be deserialized and assigned to this action's properties (or fields).

See Also
PlainValue

Implements

IAction
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2023 Planetarium