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 ¶
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 ¶
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 ¶
AddBalance adds the given amount to the balance of the specified account
func (*LightState) Copy ¶
func (self *LightState) Copy() *LightState
Copy creates a copy of the state
func (*LightState) CreateStateObject ¶
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) GetBalance ¶
GetBalance retrieves the balance from the given address or 0 if the account does not exist
func (*LightState) GetCode ¶
GetCode returns the contract code at the given address or nil if the account does not exist
func (*LightState) GetNonce ¶
GetNonce returns the nonce at the given address or 0 if the account does not exist
func (*LightState) GetOrNewStateObject ¶
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 ¶
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 ¶
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 ¶
HasAccount returns true if an account exists at the given address
func (*LightState) IsDeleted ¶
IsDeleted returns true if the given account has been marked for deletion or false if the account does not exist
func (*LightState) Set ¶
func (self *LightState) Set(state *LightState)
Set copies the contents of the given state onto this state, overwriting its contents
func (*LightState) SetState ¶
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 ¶
func (self *LightState) SetStateObject(object *StateObject)
SetStateObject sets the state object of the given account
type LightTrie ¶
type LightTrie struct {
// contains filtered or unexported fields
}
LightTrie is an ODR-capable wrapper around trie.SecureTrie
func NewLightTrie ¶
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 ¶
Get returns the value for key stored in the trie. The value bytes must not be modified by the caller.
func (*LightTrie) Update ¶
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 ¶
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 ¶
func (req *NodeDataRequest) GetData() []byte
GetData returns the retrieved node data after a successful request
func (*NodeDataRequest) StoreResult ¶
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 ¶
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 ¶
func DecodeObject(ctx context.Context, address common.Address, odr OdrBackend, data []byte) (*StateObject, error)
DecodeObject decodes an RLP-encoded state object.
func NewStateObject ¶
func NewStateObject(address common.Address, odr OdrBackend) *StateObject
NewStateObject creates a new StateObject of the specified account address
func (*StateObject) AddBalance ¶
func (c *StateObject) AddBalance(amount *big.Int)
AddBalance adds the given amount to the account balance
func (*StateObject) Address ¶
func (c *StateObject) Address() common.Address
Address returns the address of the contract/account
func (*StateObject) Balance ¶
func (self *StateObject) Balance() *big.Int
Balance returns the account balance
func (*StateObject) Copy ¶
func (self *StateObject) Copy() *StateObject
Copy creates a copy of the state object
func (*StateObject) GetState ¶
GetState returns the storage value at the given address from either the cache or the trie
func (*StateObject) MarkForDeletion ¶
func (self *StateObject) MarkForDeletion()
MarkForDeletion marks an account to be removed
func (*StateObject) SetBalance ¶
func (c *StateObject) SetBalance(amount *big.Int)
SetBalance sets the account balance to the given amount
func (*StateObject) SetCode ¶
func (self *StateObject) SetCode(code []byte)
SetCode sets the contract code
func (*StateObject) SetNonce ¶
func (self *StateObject) SetNonce(nonce uint64)
SetNonce sets the account nonce
func (*StateObject) SetState ¶
func (self *StateObject) SetState(k, value common.Hash)
SetState sets the storage value at the given address
func (*StateObject) Storage ¶
func (self *StateObject) Storage() Storage
Storage returns the storage cache object of the account
func (*StateObject) SubBalance ¶
func (c *StateObject) SubBalance(amount *big.Int)
SubBalance subtracts the given amount from the account balance
type Storage ¶
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