light

package
v1.4.13 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2016 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package light implements on-demand retrieval capable state and chain objects for the Ethereum Light Client.

Index

Constants

This section is empty.

Variables

View Source
var StartingNonce uint64

StartingNonce determines the default nonce when new accounts are being created.

Functions

This section is empty.

Types

type Code added in v1.4.0

type Code []byte

Code represents a contract code in binary form

func (Code) String added in v1.4.0

func (self Code) String() string

String returns a string representation of the code

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

func (self *LightState) AddBalance(ctx context.Context, addr common.Address, amount *big.Int) error

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

func (self *LightState) Delete(ctx context.Context, addr common.Address) (bool, error)

Delete marks an account to be removed and clears its balance

func (*LightState) GetBalance added in v1.4.0

func (self *LightState) GetBalance(ctx context.Context, addr common.Address) (*big.Int, error)

GetBalance retrieves the balance from the given address or 0 if the account does not exist

func (*LightState) GetCode added in v1.4.0

func (self *LightState) GetCode(ctx context.Context, addr common.Address) ([]byte, error)

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

func (self *LightState) GetNonce(ctx context.Context, addr common.Address) (uint64, error)

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

func (self *LightState) HasAccount(ctx context.Context, addr common.Address) (bool, error)

HasAccount returns true if an account exists at the given address

func (*LightState) IsDeleted added in v1.4.0

func (self *LightState) IsDeleted(ctx context.Context, addr common.Address) (bool, error)

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

func (self *LightState) SetCode(ctx context.Context, addr common.Address, code []byte) error

SetCode sets the contract code at the specified account

func (*LightState) SetNonce added in v1.4.0

func (self *LightState) SetNonce(ctx context.Context, addr common.Address, nonce uint64) error

SetNonce sets the nonce of 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) Delete added in v1.4.0

func (t *LightTrie) Delete(ctx context.Context, key []byte) (err error)

Delete removes any existing value for key from the trie.

func (*LightTrie) Get added in v1.4.0

func (t *LightTrie) Get(ctx context.Context, key []byte) (res []byte, err error)

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

func (t *LightTrie) Update(ctx context.Context, key, value []byte) (err error)

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

type OdrRequest interface {
	StoreResult(db ethdb.Database)
}

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

func (self *StateObject) GetState(ctx context.Context, key common.Hash) (common.Hash, error)

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

type Storage map[string]common.Hash

Storage is a memory map cache of a contract storage

func (Storage) Copy added in v1.4.0

func (self Storage) Copy() Storage

Copy copies the contents of a storage cache

func (Storage) String added in v1.4.0

func (self Storage) String() (str string)

String returns a string representation of the storage cache

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

Jump to

Keyboard shortcuts

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