Interface for getting and setting data from an underlying state trie.
StateManager
- _getStorageTrie
- _lookupStorageTrie
- _modifyContractStorage
- accountIsEmpty
- checkpoint
- cleanupTouchedAccounts
- clearContractStorage
- commit
- copy
- dumpStorage
- generateCanonicalGenesis
- generateGenesis
- getAccount
- getContractCode
- getContractStorage
- getOriginalContractStorage
- getStateRoot
- hasGenesisState
- putAccount
- putContractCode
- putContractStorage
- revert
- setStateRoot
⊕ 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
● _cache: Cache
Defined in state/stateManager.ts:41
● _checkpointCount: number
Defined in state/stateManager.ts:44
● _common: Common
Defined in state/stateManager.ts:38
● _originalStorageCache: Map
<string
, Map
<string
, Buffer
>>
Defined in state/stateManager.ts:45
● _storageTries: any
Defined in state/stateManager.ts:40
● _touched: Set
<string
>
Defined in state/stateManager.ts:42
● _touchedStack: Set
<string
>[]
Defined in state/stateManager.ts:43
● _trie: any
Defined in state/stateManager.ts:39
▸ _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
▸ _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
▸ _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(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(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(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(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(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(): 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(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(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(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(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(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(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(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(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(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(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(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(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(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(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