Skip to content

Latest commit

 

History

History
608 lines (367 loc) · 16.6 KB

statemanager.md

File metadata and controls

608 lines (367 loc) · 16.6 KB

ethereumjs-vm > StateManager

Class: StateManager

Interface for getting and setting data from an underlying state trie.

Hierarchy

StateManager

Index

Constructors

Properties

Methods


Constructors

constructor

new StateManager(opts?: StateManagerOpts): StateManager

Defined in state/stateManager.ts:45

Instantiate the StateManager interface.

Parameters:

Name Type Default value
Default value opts StateManagerOpts {}

Returns: StateManager


Properties

_cache

● _cache: Cache

Defined in state/stateManager.ts:41


_checkpointCount

● _checkpointCount: number

Defined in state/stateManager.ts:44


_common

● _common: Common

Defined in state/stateManager.ts:38


_originalStorageCache

● _originalStorageCache: Map<string, Map<string, Buffer>>

Defined in state/stateManager.ts:45


_storageTries

● _storageTries: any

Defined in state/stateManager.ts:40


_touched

● _touched: Set<string>

Defined in state/stateManager.ts:42


_touchedStack

● _touchedStack: Set<string>[]

Defined in state/stateManager.ts:43


_trie

● _trie: any

Defined in state/stateManager.ts:39


Methods

<Private> _getStorageTrie

_getStorageTrie(address: Buffer, cb: any): void

Defined in state/stateManager.ts:177

Gets the storage trie for an account from the storage cache or does a lookup.

Parameters:

Name Type
address Buffer
cb any

Returns: void


<Private> _lookupStorageTrie

_lookupStorageTrie(address: Buffer, cb: any): void

Defined in state/stateManager.ts:159

Creates a storage trie from the primary storage trie for an account and saves this in the storage cache.

Parameters:

Name Type
address Buffer
cb any

Returns: void


<Private> _modifyContractStorage

_modifyContractStorage(address: Buffer, modifyTrie: any, cb: any): void

Defined in state/stateManager.ts:264

Modifies the storage trie of an account

Parameters:

Name Type Description
address Buffer Address of the account whose storage is to be modified
modifyTrie any Function to modify the storage trie of the account
cb any

Returns: void


accountIsEmpty

accountIsEmpty(address: Buffer, cb: any): void

Defined in state/stateManager.ts:554

Checks if the account corresponding to address is empty as defined in EIP-161.

Parameters:

Name Type Description
address Buffer Address to check
cb any

Returns: void


checkpoint

checkpoint(cb: any): void

Defined in state/stateManager.ts:334

Checkpoints the current state of the StateManager instance. State changes that follow can then be committed by calling commit or reverted by calling rollback.

Parameters:

Name Type Description
cb any Callback function

Returns: void


cleanupTouchedAccounts

cleanupTouchedAccounts(cb: any): void

Defined in state/stateManager.ts:575

Removes accounts form the state trie that have been touched, as defined in EIP-161.

Parameters:

Name Type Description
cb any Callback function

Returns: void


clearContractStorage

clearContractStorage(address: Buffer, cb: any): void

Defined in state/stateManager.ts:317

Clears all storage entries for the account corresponding to address.

Parameters:

Name Type Description
address Buffer Address to clear the storage of
cb any Callback function

Returns: void


commit

commit(cb: any): void

Defined in state/stateManager.ts:347

Commits the current change-set to the instance since the last call to checkpoint.

Parameters:

Name Type Description
cb any Callback function

Returns: void


copy

copy(): StateManager

Defined in state/stateManager.ts:71

Copies the current instance of the StateManager at the last fully committed point, i.e. as if all current checkpoints were reverted.

Returns: StateManager


dumpStorage

dumpStorage(address: Buffer, cb: any): void

Defined in state/stateManager.ts:460

Dumps the the storage values for an account specified by address.

Parameters:

Name Type Description
address Buffer The address of the `account` to return storage for
cb any

Returns: void


generateCanonicalGenesis

generateCanonicalGenesis(cb: any): void

Defined in state/stateManager.ts:500

Generates a canonical genesis state on the instance based on the configured chain parameters. Will error if there are uncommitted checkpoints on the instance.

Parameters:

Name Type Description
cb any Callback function

Returns: void


generateGenesis

generateGenesis(initState: any, cb: any): any

Defined in state/stateManager.ts:519

Initializes the provided genesis state into the state trie

Parameters:

Name Type Description
initState any Object (address -> balance)
cb any Callback function

Returns: any


getAccount

getAccount(address: Buffer, cb: any): void

Defined in state/stateManager.ts:89

Gets the ethereumjs-account associated with address. Returns an empty account if the account does not exist.

Parameters:

Name Type Description
address Buffer Address of the `account` to get
cb any

Returns: void


getContractCode

getContractCode(address: Buffer, cb: any): void

Defined in state/stateManager.ts:145

Gets the code corresponding to the provided address.

Parameters:

Name Type Description
address Buffer Address to get the `code` for
cb any

Returns: void


getContractStorage

getContractStorage(address: Buffer, key: Buffer, cb: any): void

Defined in state/stateManager.ts:203

Gets the storage value associated with the provided address and key. This method returns the shortest representation of the stored value.

Parameters:

Name Type Description
address Buffer Address of the account to get the storage for
key Buffer Key in the account's storage to get the value for. Must be 32 bytes long.
cb any

Returns: void


getOriginalContractStorage

getOriginalContractStorage(address: Buffer, key: Buffer, cb: any): void

Defined in state/stateManager.ts:230

Caches the storage value associated with the provided address and key on first invocation, and returns the cached (original) value from then onwards. This is used to get the original value of a storage slot for computing gas costs according to EIP-1283.

Parameters:

Name Type Description
address Buffer Address of the account to get the storage for
key Buffer Key in the account's storage to get the value for. Must be 32 bytes long.
cb any

Returns: void


getStateRoot

getStateRoot(cb: any): void

Defined in state/stateManager.ts:396

Gets the state-root of the Merkle-Patricia trie representation of the state of this StateManager. Will error if there are uncommitted checkpoints on the instance.

Parameters:

Name Type Description
cb any

Returns: void


hasGenesisState

hasGenesisState(cb: any): void

Defined in state/stateManager.ts:489

Checks whether the current instance has the canonical genesis state for the configured chain parameters.

Parameters:

Name Type Description
cb any

Returns: void


putAccount

putAccount(address: Buffer, account: Account, cb: any): void

Defined in state/stateManager.ts:100

Saves an ethereumjs-account into state under the provided address.

Parameters:

Name Type Description
address Buffer Address under which to store `account`
account Account The `ethereumjs-account` to store
cb any Callback function

Returns: void


putContractCode

putContractCode(address: Buffer, value: Buffer, cb: any): void

Defined in state/stateManager.ts:117

Adds value to the state trie as code, and sets codeHash on the account corresponding to address to reference this.

Parameters:

Name Type Description
address Buffer Address of the `account` to add the `code` for
value Buffer The value of the `code`
cb any Callback function

Returns: void


putContractStorage

putContractStorage(address: Buffer, key: Buffer, value: Buffer, cb: any): void

Defined in state/stateManager.ts:291

Adds value to the state trie for the account corresponding to address at the provided key.

Parameters:

Name Type Description
address Buffer Address to set a storage value for
key Buffer Key to set the value at. Must be 32 bytes long.
value Buffer Value to set at `key` for account corresponding to `address`
cb any Callback function

Returns: void


revert

revert(cb: any): void

Defined in state/stateManager.ts:365

Reverts the current change-set to the instance since the last call to checkpoint.

Parameters:

Name Type Description
cb any Callback function

Returns: void


setStateRoot

setStateRoot(stateRoot: Buffer, cb: any): void

Defined in state/stateManager.ts:418

Sets the state of the instance to that represented by the provided stateRoot. Will error if there are uncommitted checkpoints on the instance or if the state root does not exist in the state trie.

Parameters:

Name Type Description
stateRoot Buffer The state-root to reset the instance to
cb any Callback function

Returns: void