state

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeAddressValue

func EncodeAddressValue(value any, offset uint) (common.Hash, error)

EncodeAddressValue will encode an address like value given a storage offset.

func EncodeBoolValue

func EncodeBoolValue(value any, offset uint) (common.Hash, error)

EncodeBoolValue will encode a boolean value given a storage offset.

func EncodeBytes32Value

func EncodeBytes32Value(value any, offset uint) (common.Hash, error)

EncodeBytes32Value will encode a bytes32 value. The offset is included so that it can implement the ElementEncoder interface, but the offset must always be 0.

func EncodeStringValue

func EncodeStringValue(value any, offset uint) (common.Hash, error)

EncodeStringValue will encode a string to a type suitable for storage in state. The offset must be 0.

func EncodeUintValue

func EncodeUintValue(value any, offset uint) (common.Hash, error)

EncodeUintValue will encode a uint value given a storage offset

func SetStorage

func SetStorage(name string, address common.Address, values StorageValues, db vm.StateDB) error

SetStorage will set the storage values in a db given a contract name, address and the storage values

Types

type ElementEncoder

type ElementEncoder func(value any, offset uint) (common.Hash, error)

ElementEncoder is a function that can encode an element based on a solidity type

type EncodedStorage

type EncodedStorage struct {
	Key   common.Hash
	Value common.Hash
}

EncodedStorage represents the storage key and value serialized to be placed in Ethereum state.

func ComputeStorageSlots

func ComputeStorageSlots(layout *solc.StorageLayout, values StorageValues) ([]*EncodedStorage, error)

ComputeStorageSlots will compute the storage slots for a given contract.

func EncodeStorage

func EncodeStorage(entry solc.StorageLayoutEntry, value any, storageType solc.StorageLayoutType) ([]*EncodedStorage, error)

EncodeStorage will encode a storage layout

func EncodeStorageKeyValue

func EncodeStorageKeyValue(value any, entry solc.StorageLayoutEntry, storageType solc.StorageLayoutType) ([]*EncodedStorage, error)

EncodeStorageKeyValue encodes the key value pair that is stored in state given a StorageLayoutEntry and StorageLayoutType. A single input may result in multiple outputs. Unknown or unimplemented types will return an error. Note that encoding uints is *not* overflow safe, so be sure to check the ABI before setting very large values

func MergeStorage

func MergeStorage(storage []*EncodedStorage) []*EncodedStorage

MergeStorage will combine any overlapping storage slots for when values are tightly packed. Do this by checking to see if any of the produced storage slots have a matching key, if so use a binary or to add the storage values together

type MemoryStateDB

type MemoryStateDB struct {
	// contains filtered or unexported fields
}

MemoryStateDB implements geth's StateDB interface but operates on a core.Genesis so that a genesis.json can easily be created.

func NewMemoryStateDB

func NewMemoryStateDB(genesis *core.Genesis) *MemoryStateDB

func (*MemoryStateDB) AddAddressToAccessList

func (db *MemoryStateDB) AddAddressToAccessList(addr common.Address)

AddAddressToAccessList adds the given address to the access list. This operation is safe to perform even if the feature/fork is not active yet

func (*MemoryStateDB) AddBalance

func (db *MemoryStateDB) AddBalance(addr common.Address, amount *big.Int)

func (*MemoryStateDB) AddLog

func (db *MemoryStateDB) AddLog(*types.Log)

func (*MemoryStateDB) AddPreimage

func (db *MemoryStateDB) AddPreimage(common.Hash, []byte)

func (*MemoryStateDB) AddRefund

func (db *MemoryStateDB) AddRefund(uint64)

func (*MemoryStateDB) AddSlotToAccessList

func (db *MemoryStateDB) AddSlotToAccessList(addr common.Address, slot common.Hash)

AddSlotToAccessList adds the given (address,slot) to the access list. This operation is safe to perform even if the feature/fork is not active yet

func (*MemoryStateDB) AddressInAccessList

func (db *MemoryStateDB) AddressInAccessList(addr common.Address) bool

func (*MemoryStateDB) CreateAccount

func (db *MemoryStateDB) CreateAccount(addr common.Address)

func (*MemoryStateDB) DeleteState

func (db *MemoryStateDB) DeleteState(addr common.Address, key common.Hash)

func (*MemoryStateDB) Empty

func (db *MemoryStateDB) Empty(addr common.Address) bool

Empty returns whether the given account is empty. Empty is defined according to EIP161 (balance = nonce = code = 0).

func (*MemoryStateDB) Exist

func (db *MemoryStateDB) Exist(addr common.Address) bool

Exist reports whether the given account exists in state. Notably this should also return true for suicided accounts.

func (*MemoryStateDB) ForEachStorage

func (db *MemoryStateDB) ForEachStorage(addr common.Address, cb func(common.Hash, common.Hash) bool) error

func (*MemoryStateDB) Genesis

func (db *MemoryStateDB) Genesis() *core.Genesis

Genesis is a getter for the underlying core.Genesis

func (*MemoryStateDB) GetAccount

func (db *MemoryStateDB) GetAccount(addr common.Address) *core.GenesisAccount

GetAccount is a getter for a core.GenesisAccount found in the core.Genesis

func (*MemoryStateDB) GetBalance

func (db *MemoryStateDB) GetBalance(addr common.Address) *big.Int

func (*MemoryStateDB) GetCode

func (db *MemoryStateDB) GetCode(addr common.Address) []byte

func (*MemoryStateDB) GetCodeHash

func (db *MemoryStateDB) GetCodeHash(addr common.Address) common.Hash

func (*MemoryStateDB) GetCodeSize

func (db *MemoryStateDB) GetCodeSize(addr common.Address) int

func (*MemoryStateDB) GetCommittedState

func (db *MemoryStateDB) GetCommittedState(common.Address, common.Hash) common.Hash

func (*MemoryStateDB) GetLiveStateAccount

func (db *MemoryStateDB) GetLiveStateAccount(addr common.Address) *types.StateAccount

func (*MemoryStateDB) GetNonce

func (db *MemoryStateDB) GetNonce(addr common.Address) uint64

func (*MemoryStateDB) GetProof

func (db *MemoryStateDB) GetProof(addr common.Address) ([][]byte, error)

func (*MemoryStateDB) GetProofByHash

func (db *MemoryStateDB) GetProofByHash(addrHash common.Hash) ([][]byte, error)

func (*MemoryStateDB) GetRefund

func (db *MemoryStateDB) GetRefund() uint64

func (*MemoryStateDB) GetRootHash

func (db *MemoryStateDB) GetRootHash() common.Hash

func (*MemoryStateDB) GetState

func (db *MemoryStateDB) GetState(addr common.Address, key common.Hash) common.Hash

func (*MemoryStateDB) GetStorageProof

func (db *MemoryStateDB) GetStorageProof(a common.Address, key common.Hash) ([][]byte, error)

func (*MemoryStateDB) GetTransientState

func (db *MemoryStateDB) GetTransientState(addr common.Address, key common.Hash) common.Hash

func (*MemoryStateDB) HasSelfDestructed

func (db *MemoryStateDB) HasSelfDestructed(common.Address) bool

func (*MemoryStateDB) Prepare

func (db *MemoryStateDB) Prepare(rules params.Rules, sender, coinbase common.Address, dest *common.Address, precompiles []common.Address, txAccesses types.AccessList)

func (*MemoryStateDB) PrepareAccessList

func (db *MemoryStateDB) PrepareAccessList(sender common.Address, dest *common.Address, precompiles []common.Address, txAccesses types.AccessList)

func (*MemoryStateDB) RevertToSnapshot

func (db *MemoryStateDB) RevertToSnapshot(int)

func (*MemoryStateDB) SelfDestruct

func (db *MemoryStateDB) SelfDestruct(common.Address)

func (*MemoryStateDB) Selfdestruct6780

func (db *MemoryStateDB) Selfdestruct6780(common.Address)

func (*MemoryStateDB) SetCode

func (db *MemoryStateDB) SetCode(addr common.Address, code []byte)

func (*MemoryStateDB) SetNonce

func (db *MemoryStateDB) SetNonce(addr common.Address, value uint64)

func (*MemoryStateDB) SetState

func (db *MemoryStateDB) SetState(addr common.Address, key, value common.Hash)

func (*MemoryStateDB) SetTransientState

func (db *MemoryStateDB) SetTransientState(addr common.Address, key, value common.Hash)

func (*MemoryStateDB) SlotInAccessList

func (db *MemoryStateDB) SlotInAccessList(addr common.Address, slot common.Hash) (addressOk bool, slotOk bool)

func (*MemoryStateDB) Snapshot

func (db *MemoryStateDB) Snapshot() int

func (*MemoryStateDB) SubBalance

func (db *MemoryStateDB) SubBalance(addr common.Address, amount *big.Int)

func (*MemoryStateDB) SubRefund

func (db *MemoryStateDB) SubRefund(uint64)

type StorageConfig

type StorageConfig map[string]StorageValues

StorageConfig represents the storage configuration for the L2 predeploy contracts.

type StorageValues

type StorageValues map[string]any

StorageValues represents the values to be set in storage. The key is the name of the storage variable and the value is the value to set in storage.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL