state

package
v0.10.14 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: MIT Imports: 17 Imported by: 4

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) 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) GetNonce

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

func (*MemoryStateDB) GetRefund

func (db *MemoryStateDB) GetRefund() uint64

func (*MemoryStateDB) GetState

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

func (*MemoryStateDB) HasSuicided

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

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) 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) 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)

func (*MemoryStateDB) Suicide

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

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