Class InitializeStates
Introduced at Initial commit(2e645be18a4e2caea031c347f00777fbad5dbcc6) Updated at NCG distribution(7e4515b6e14cc5d6eb716d5ebb587ab04b4246f9) Updated at https://github.com/planetarium/lib9c/pull/19 Updated at https://github.com/planetarium/lib9c/pull/36 Updated at https://github.com/planetarium/lib9c/pull/42 Updated at https://github.com/planetarium/lib9c/pull/55 Updated at https://github.com/planetarium/lib9c/pull/57 Updated at https://github.com/planetarium/lib9c/pull/60 Updated at https://github.com/planetarium/lib9c/pull/102 Updated at https://github.com/planetarium/lib9c/pull/128 Updated at https://github.com/planetarium/lib9c/pull/167 Updated at https://github.com/planetarium/lib9c/pull/422 Updated at https://github.com/planetarium/lib9c/pull/747 Updated at https://github.com/planetarium/lib9c/pull/798 Updated at https://github.com/planetarium/lib9c/pull/957
[Serializable]
[ActionType("initialize_states")]
public class InitializeStates : GameAction, IAction, IInitializeStatesV1
- Inheritance
-
InitializeStates
- Implements
-
IActionIInitializeStatesV1
- Inherited Members
Constructors
InitializeStates()
public InitializeStates()
InitializeStates(ValidatorSet, RankingState0, ShopState, Dictionary<string, string>, GameConfigState, RedeemCodeState, ActivatedAccountsState, GoldCurrencyState, GoldDistribution[], PendingActivationState[], AdminState, AuthorizedMinersState, CreditsState, ISet<Address>)
public InitializeStates(ValidatorSet validatorSet, RankingState0 rankingState, ShopState shopState, Dictionary<string, string> tableSheets, GameConfigState gameConfigState, RedeemCodeState redeemCodeState, ActivatedAccountsState activatedAccountsState, GoldCurrencyState goldCurrencyState, GoldDistribution[] goldDistributions, PendingActivationState[] pendingActivationStates, AdminState adminAddressState = null, AuthorizedMinersState authorizedMinersState = null, CreditsState creditsState = null, ISet<Address> assetMinters = null)
Parameters
validatorSetValidatorSetrankingStateRankingState0shopStateShopStatetableSheetsDictionary<string, string>gameConfigStateGameConfigStateredeemCodeStateRedeemCodeStateactivatedAccountsStateActivatedAccountsStategoldCurrencyStateGoldCurrencyStategoldDistributionsGoldDistribution[]pendingActivationStatesPendingActivationState[]adminAddressStateAdminStateauthorizedMinersStateAuthorizedMinersStatecreditsStateCreditsStateassetMintersISet<Address>
Properties
ActivatedAccounts
public Dictionary ActivatedAccounts { get; set; }
Property Value
- Dictionary
AdminAddressState
public Dictionary AdminAddressState { get; set; }
Property Value
- Dictionary
AssetMinters
public ISet<Address> AssetMinters { get; set; }
Property Value
- ISet<Address>
AuthorizedMiners
public Dictionary AuthorizedMiners { get; set; }
Property Value
- Dictionary
Credits
public Dictionary Credits { get; set; }
Property Value
- Dictionary
GameConfig
public Dictionary GameConfig { get; set; }
Property Value
- Dictionary
GoldCurrency
public Dictionary GoldCurrency { get; set; }
Property Value
- Dictionary
GoldDistributions
public List GoldDistributions { get; set; }
Property Value
- List
PendingActivations
public List PendingActivations { get; set; }
Property Value
- List
PlainValueInternal
protected override IImmutableDictionary<string, IValue> PlainValueInternal { get; }
Property Value
- IImmutableDictionary<string, IValue>
Ranking
public Dictionary Ranking { get; set; }
Property Value
- Dictionary
RedeemCode
public Dictionary RedeemCode { get; set; }
Property Value
- Dictionary
Shop
public Dictionary Shop { get; set; }
Property Value
- Dictionary
TableSheets
public Dictionary<string, string> TableSheets { get; set; }
Property Value
ValidatorSet
public IValue ValidatorSet { get; set; }
Property Value
- IValue
Methods
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 Libplanet.Action.State.IWorld object functions as a delta which shifts from previous states to next states.
public override IWorld Execute(IActionContext context)
Parameters
contextIActionContextA context object containing addresses that signed the transaction, states immediately before the execution, and a PRNG object which produces deterministic random numbers. See Libplanet.Action.IActionContext for details.
Returns
- IWorld
A map of changed states (so-called "dirty").
Remarks
This method should be deterministic: for structurally (member-wise) equal actions and Libplanet.Action.IActionContexts, the same result should be returned. Side effects should be avoided, because an action's Libplanet.Action.IAction.Execute(Libplanet.Action.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 Blockchain.Renderers.IRenderer interface separately and attach it to a Blockchain.BlockChain instance.
For randomness, never use Random nor any other PRNGs provided by other than Libplanet. Use IActionContext.Random instead. IActionContext.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
LoadPlainValueInternal(IImmutableDictionary<string, IValue>)
protected override void LoadPlainValueInternal(IImmutableDictionary<string, IValue> plainValue)
Parameters
plainValueIImmutableDictionary<string, IValue>