Documentation ¶
Overview ¶
Package light implements on-demand retrieval capable state and chain objects for the Ethereum Light Client.
Index ¶
- Variables
- type Code
- type LightState
- func (self *LightState) AddBalance(ctx context.Context, addr common.Address, amount *big.Int) error
- func (self *LightState) Copy() *LightState
- func (self *LightState) CreateStateObject(ctx context.Context, addr common.Address) (*StateObject, error)
- func (self *LightState) Delete(ctx context.Context, addr common.Address) (bool, error)
- func (self *LightState) GetBalance(ctx context.Context, addr common.Address) (*big.Int, error)
- func (self *LightState) GetCode(ctx context.Context, addr common.Address) ([]byte, error)
- func (self *LightState) GetNonce(ctx context.Context, addr common.Address) (uint64, error)
- func (self *LightState) GetOrNewStateObject(ctx context.Context, addr common.Address) (*StateObject, error)
- func (self *LightState) GetState(ctx context.Context, a common.Address, b common.Hash) (common.Hash, error)
- func (self *LightState) GetStateObject(ctx context.Context, addr common.Address) (stateObject *StateObject, err error)
- func (self *LightState) HasAccount(ctx context.Context, addr common.Address) (bool, error)
- func (self *LightState) IsDeleted(ctx context.Context, addr common.Address) (bool, error)
- func (self *LightState) Set(state *LightState)
- func (self *LightState) SetCode(ctx context.Context, addr common.Address, code []byte) error
- func (self *LightState) SetNonce(ctx context.Context, addr common.Address, nonce uint64) error
- func (self *LightState) SetState(ctx context.Context, addr common.Address, key common.Hash, value common.Hash) error
- func (self *LightState) SetStateObject(object *StateObject)
- type LightTrie
- type NodeDataRequest
- type OdrBackend
- type OdrRequest
- type StateObject
- func (c *StateObject) AddBalance(amount *big.Int)
- func (c *StateObject) Address() common.Address
- func (self *StateObject) Balance() *big.Int
- func (self *StateObject) Code() []byte
- func (self *StateObject) Copy() *StateObject
- func (self *StateObject) GetState(ctx context.Context, key common.Hash) (common.Hash, error)
- func (self *StateObject) MarkForDeletion()
- func (self *StateObject) Nonce() uint64
- func (c *StateObject) SetBalance(amount *big.Int)
- func (self *StateObject) SetCode(code []byte)
- func (self *StateObject) SetNonce(nonce uint64)
- func (self *StateObject) SetState(k, value common.Hash)
- func (self *StateObject) Storage() Storage
- func (c *StateObject) SubBalance(amount *big.Int)
- type Storage
- type TrieRequest
Constants ¶
This section is empty.
Variables ¶
var StartingNonce uint64
StartingNonce determines the default nonce when new accounts are being created.
Functions ¶
This section is empty.
Types ¶
type LightState ¶ added in v1.4.0
type LightState struct {
// contains filtered or unexported fields
}
LightState is a memory representation of a state. This version is ODR capable, caching only the already accessed part of the state, retrieving unknown parts on-demand from the ODR backend. Changes are never stored in the local database, only in the memory objects.
func NewLightState ¶ added in v1.4.0
func NewLightState(root common.Hash, odr OdrBackend) *LightState
NewLightState creates a new LightState with the specified root. Note that the creation of a light state is always successful, even if the root is non-existent. In that case, ODR retrieval will always be unsuccessful and every operation will return with an error or wait for the context to be cancelled.
func (*LightState) AddBalance ¶ added in v1.4.0
AddBalance adds the given amount to the balance of the specified account
func (*LightState) Copy ¶ added in v1.4.0
func (self *LightState) Copy() *LightState
Copy creates a copy of the state
func (*LightState) CreateStateObject ¶ added in v1.4.0
func (self *LightState) CreateStateObject(ctx context.Context, addr common.Address) (*StateObject, error)
CreateStateObject creates creates a new state object and takes ownership. This is different from "NewStateObject"
func (*LightState) Delete ¶ added in v1.4.0
Delete marks an account to be removed and clears its balance
func (*LightState) GetBalance ¶ added in v1.4.0
GetBalance retrieves the balance from the given address or 0 if the account does not exist
func (*LightState) GetCode ¶ added in v1.4.0
GetCode returns the contract code at the given address or nil if the account does not exist
func (*LightState) GetNonce ¶ added in v1.4.0
GetNonce returns the nonce at the given address or 0 if the account does not exist
func (*LightState) GetOrNewStateObject ¶ added in v1.4.0
func (self *LightState) GetOrNewStateObject(ctx context.Context, addr common.Address) (*StateObject, error)
GetOrNewStateObject returns the state object of the given account or creates a new one if the account does not exist
func (*LightState) GetState ¶ added in v1.4.0
func (self *LightState) GetState(ctx context.Context, a common.Address, b common.Hash) (common.Hash, error)
GetState returns the contract storage value at storage address b from the contract address a or common.Hash{} if the account does not exist
func (*LightState) GetStateObject ¶ added in v1.4.0
func (self *LightState) GetStateObject(ctx context.Context, addr common.Address) (stateObject *StateObject, err error)
GetStateObject returns the state object of the given account or nil if the account does not exist
func (*LightState) HasAccount ¶ added in v1.4.0
HasAccount returns true if an account exists at the given address
func (*LightState) IsDeleted ¶ added in v1.4.0
IsDeleted returns true if the given account has been marked for deletion or false if the account does not exist
func (*LightState) Set ¶ added in v1.4.0
func (self *LightState) Set(state *LightState)
Set copies the contents of the given state onto this state, overwriting its contents
func (*LightState) SetCode ¶ added in v1.4.0
SetCode sets the contract code at the specified account
func (*LightState) SetState ¶ added in v1.4.0
func (self *LightState) SetState(ctx context.Context, addr common.Address, key common.Hash, value common.Hash) error
SetState sets the storage value at storage address key of the account addr
func (*LightState) SetStateObject ¶ added in v1.4.0
func (self *LightState) SetStateObject(object *StateObject)
SetStateObject sets the state object of the given account
type LightTrie ¶ added in v1.4.0
type LightTrie struct {
// contains filtered or unexported fields
}
LightTrie is an ODR-capable wrapper around trie.SecureTrie
func NewLightTrie ¶ added in v1.4.0
func NewLightTrie(root common.Hash, odr OdrBackend, useFakeMap bool) *LightTrie
NewLightTrie creates a new LightTrie instance. It doesn't instantly try to access the db or network and retrieve the root node, it only initializes its encapsulated SecureTrie at the first actual operation.
func (*LightTrie) Get ¶ added in v1.4.0
Get returns the value for key stored in the trie. The value bytes must not be modified by the caller.
func (*LightTrie) Update ¶ added in v1.4.0
Update associates key with value in the trie. Subsequent calls to Get will return value. If value has length zero, any existing value is deleted from the trie and calls to Get will return nil.
The value bytes must not be modified by the caller while they are stored in the trie.
type NodeDataRequest ¶ added in v1.4.0
type NodeDataRequest struct { OdrRequest // contains filtered or unexported fields }
NodeDataRequest is the ODR request type for node data (used for retrieving contract code)
func (*NodeDataRequest) GetData ¶ added in v1.4.0
func (req *NodeDataRequest) GetData() []byte
GetData returns the retrieved node data after a successful request
func (*NodeDataRequest) StoreResult ¶ added in v1.4.0
func (req *NodeDataRequest) StoreResult(db ethdb.Database)
StoreResult stores the retrieved data in local database
type OdrBackend ¶
type OdrBackend interface { Database() ethdb.Database Retrieve(ctx context.Context, req OdrRequest) error }
OdrBackend is an interface to a backend service that handles odr retrievals
type OdrRequest ¶
OdrRequest is an interface for retrieval requests
type StateObject ¶ added in v1.4.0
type StateObject struct {
// contains filtered or unexported fields
}
StateObject is a memory representation of an account or contract and its storage. This version is ODR capable, caching only the already accessed part of the storage, retrieving unknown parts on-demand from the ODR backend. Changes are never stored in the local database, only in the memory objects.
func DecodeObject ¶ added in v1.4.0
func DecodeObject(ctx context.Context, address common.Address, odr OdrBackend, data []byte) (*StateObject, error)
DecodeObject decodes an RLP-encoded state object.
func NewStateObject ¶ added in v1.4.0
func NewStateObject(address common.Address, odr OdrBackend) *StateObject
NewStateObject creates a new StateObject of the specified account address
func (*StateObject) AddBalance ¶ added in v1.4.0
func (c *StateObject) AddBalance(amount *big.Int)
AddBalance adds the given amount to the account balance
func (*StateObject) Address ¶ added in v1.4.0
func (c *StateObject) Address() common.Address
Address returns the address of the contract/account
func (*StateObject) Balance ¶ added in v1.4.0
func (self *StateObject) Balance() *big.Int
Balance returns the account balance
func (*StateObject) Code ¶ added in v1.4.0
func (self *StateObject) Code() []byte
Code returns the contract code
func (*StateObject) Copy ¶ added in v1.4.0
func (self *StateObject) Copy() *StateObject
Copy creates a copy of the state object
func (*StateObject) GetState ¶ added in v1.4.0
GetState returns the storage value at the given address from either the cache or the trie
func (*StateObject) MarkForDeletion ¶ added in v1.4.0
func (self *StateObject) MarkForDeletion()
MarkForDeletion marks an account to be removed
func (*StateObject) Nonce ¶ added in v1.4.0
func (self *StateObject) Nonce() uint64
Nonce returns the account nonce
func (*StateObject) SetBalance ¶ added in v1.4.0
func (c *StateObject) SetBalance(amount *big.Int)
SetBalance sets the account balance to the given amount
func (*StateObject) SetCode ¶ added in v1.4.0
func (self *StateObject) SetCode(code []byte)
SetCode sets the contract code
func (*StateObject) SetNonce ¶ added in v1.4.0
func (self *StateObject) SetNonce(nonce uint64)
SetNonce sets the account nonce
func (*StateObject) SetState ¶ added in v1.4.0
func (self *StateObject) SetState(k, value common.Hash)
SetState sets the storage value at the given address
func (*StateObject) Storage ¶ added in v1.4.0
func (self *StateObject) Storage() Storage
Storage returns the storage cache object of the account
func (*StateObject) SubBalance ¶ added in v1.4.0
func (c *StateObject) SubBalance(amount *big.Int)
SubBalance subtracts the given amount from the account balance
type Storage ¶ added in v1.4.0
Storage is a memory map cache of a contract storage
type TrieRequest ¶
type TrieRequest struct { OdrRequest // contains filtered or unexported fields }
TrieRequest is the ODR request type for state/storage trie entries
func (*TrieRequest) StoreResult ¶
func (req *TrieRequest) StoreResult(db ethdb.Database)
StoreResult stores the retrieved data in local database