@ethereumjs/statemanager / MerkleStateManager
Defined in: merkleStateManager.ts:62
Default StateManager implementation for the VM.
The state manager abstracts from the underlying data store by providing higher level access to accounts, contract code and storage slots.
The default state manager implementation uses a
@ethereumjs/mpt trie as a data backend.
Note that there is a SimpleStateManager dependency-free state
manager implementation available shipped with the @ethereumjs/statemanager
package which might be an alternative to this implementation
for many basic use cases.
StateManagerInterfacenew MerkleStateManager(
opts):MerkleStateManager
Defined in: merkleStateManager.ts:93
Instantiate the StateManager interface.
MerkleStateManager
readonlycommon:Common
Defined in: merkleStateManager.ts:74
originalStorageCache:
OriginalStorageCache
Defined in: merkleStateManager.ts:66
StateManagerInterface.originalStorageCache
checkpoint():
Promise<void>
Defined in: merkleStateManager.ts:443
Checkpoints the current state of the StateManager instance.
State changes that follow can then be committed by calling
commit or reverted by calling rollback.
Promise<void>
StateManagerInterface.checkpoint
clearCaches():
void
Defined in: merkleStateManager.ts:724
Clears all underlying caches
void
StateManagerInterface.clearCaches
clearStorage(
address):Promise<void>
Defined in: merkleStateManager.ts:426
Clears all storage entries for the account corresponding to address.
Address
Address to clear the storage of
Promise<void>
StateManagerInterface.clearStorage
commit():
Promise<void>
Defined in: merkleStateManager.ts:453
Commits the current change-set to the instance since the last call to checkpoint.
Promise<void>
StateManagerInterface.commit
deleteAccount(
address):Promise<void>
Defined in: merkleStateManager.ts:181
Deletes an account from state under the provided address.
Address
Address of the account which should be deleted
Promise<void>
StateManagerInterface.deleteAccount
dumpStorage(
address):Promise<StorageDump>
Defined in: merkleStateManager.ts:583
Dumps the RLP-encoded storage values for an account specified by address.
Address
The address of the account to return storage for
Promise<StorageDump>
Object map.
Keys are are the storage keys, values are the storage values as strings.
Both are represented as hex strings without the 0x prefix.StateManagerInterface.dumpStorage
dumpStorageRange(
address,startKey,limit):Promise<StorageRange>
Defined in: merkleStateManager.ts:605
Dumps a limited number of RLP-encoded storage values for an account specified by address,
starting from startKey or greater.
Address
The address of the account to return storage for.
bigint
The bigint representation of the smallest storage key that will be returned.
number
The maximum number of storage values that will be returned.
Promise<StorageRange>
limit entries in its storage field.
The object will also contain nextKey, the next (hashed) storage key after the range included in storage.StateManagerInterface.dumpStorageRange
flush():
Promise<void>
Defined in: merkleStateManager.ts:491
Writes all cache items to the trie
Promise<void>
generateCanonicalGenesis(
initState):Promise<void>
Defined in: merkleStateManager.ts:641
Initializes the provided genesis state into the state trie. Will error if there are uncommitted checkpoints on the instance.
any
| address -> balance | [balance, code, storage] |
Promise<void>
StateManagerInterface.generateCanonicalGenesis
getAccount(
address):Promise<Account|undefined>
Defined in: merkleStateManager.ts:120
Gets the account associated with address or undefined if account does not exist
Address
Address of the account to get
Promise<Account | undefined>
StateManagerInterface.getAccount
getAppliedKey(
address):Uint8Array
Defined in: merkleStateManager.ts:734
Returns the applied key for a given address Used for saving preimages
Uint8Array
The address to return the applied key
Uint8Array
StateManagerInterface.getAppliedKey
getCode(
address):Promise<Uint8Array<ArrayBufferLike>>
Defined in: merkleStateManager.ts:225
Gets the code corresponding to the provided address.
Address
Address to get the code for
Promise<Uint8Array<ArrayBufferLike>>
Uint8Array if the account has no associated code.StateManagerInterface.getCode
getCodeSize(
address):Promise<number>
Defined in: merkleStateManager.ts:246
Address
Promise<number>
StateManagerInterface.getCodeSize
getStateRoot():
Promise<Uint8Array<ArrayBufferLike>>
Defined in: merkleStateManager.ts:547
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.
Promise<Uint8Array<ArrayBufferLike>>
StateManagerStateManagerInterface.getStateRoot
getStorage(
address,key):Promise<Uint8Array<ArrayBufferLike>>
Defined in: merkleStateManager.ts:319
Gets the storage value associated with the provided address and key. This method returns
the shortest representation of the stored value.
Address
Address of the account to get the storage for
Uint8Array
Key in the account’s storage to get the value for. Must be 32 bytes long.
Promise<Uint8Array<ArrayBufferLike>>
Uint8Array is returned.StateManagerInterface.getStorage
hasStateRoot(
root):Promise<boolean>
Defined in: merkleStateManager.ts:677
Checks whether there is a state corresponding to a stateRoot
Uint8Array
Promise<boolean>
StateManagerInterface.hasStateRoot
modifyAccountFields(
address,accountFields):Promise<void>
Defined in: merkleStateManager.ts:173
Gets the account associated with address, modifies the given account
fields, then saves the account into state. Account fields can include
nonce, balance, storageRoot, and codeHash.
Address
Address of the account to modify
AccountFields
Object containing account fields and values to modify
Promise<void>
StateManagerInterface.modifyAccountFields
putAccount(
address,account):Promise<void>
Defined in: merkleStateManager.ts:140
Saves an account into state under the provided address.
Address
Address under which to store account
The account to store or undefined if to be deleted
Account |
undefined |
Promise<void>
StateManagerInterface.putAccount
putCode(
address,value):Promise<void>
Defined in: merkleStateManager.ts:199
Adds value to the state trie as code, and sets codeHash on the account
corresponding to address to reference this.
Address
Address of the account to add the code for
Uint8Array
The value of the code
Promise<void>
StateManagerInterface.putCode
putStorage(
address,key,value):Promise<void>
Defined in: merkleStateManager.ts:403
Adds value to the state trie for the account
corresponding to address at the provided key.
Address
Address to set a storage value for
Uint8Array
Key to set the value at. Must be 32 bytes long.
Uint8Array
Value to set at key for account corresponding to address.
Cannot be more than 32 bytes. Leading zeros are stripped.
If it is a empty or filled with zeros, deletes the value.
Promise<void>
StateManagerInterface.putStorage
revert():
Promise<void>
Defined in: merkleStateManager.ts:473
Reverts the current change-set to the instance since the last call to checkpoint.
Promise<void>
StateManagerInterface.revert
setStateRoot(
stateRoot,clearCache):Promise<void>
Defined in: merkleStateManager.ts:559
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.
Uint8Array
The state-root to reset the instance to
boolean = true
Promise<void>
StateManagerInterface.setStateRoot
shallowCopy(
downlevelCaches):MerkleStateManager
Defined in: merkleStateManager.ts:703
Copies the current instance of the StateManager
at the last fully committed point, i.e. as if all current
checkpoints were reverted.
Caches are downleveled (so: adopted for short-term usage) by default.
This means in particular:
Both adoptions can be deactivated by setting downlevelCaches to
false.
Cache values are generally not copied along regardless of the
downlevelCaches setting.
boolean = true
MerkleStateManager
StateManagerInterface.shallowCopy