light

package
v1.4.10-alpha2 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 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

type Code []byte

Code represents a contract code in binary form

func (Code) String

func (self Code) String() string

String returns a string representation of the code

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

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

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

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

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

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

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

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

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

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

func (self *LightState) Set(state *LightState)

Set copies the contents of the given state onto this state, overwriting its contents

func (*LightState) SetCode

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

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

SetNonce sets the nonce of the specified account

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

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

Delete removes any existing value for key from the trie.

func (*LightTrie) Get

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

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

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

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

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

func (self *StateObject) Code() []byte

Code returns the contract code

func (*StateObject) Copy

func (self *StateObject) Copy() *StateObject

Copy creates a copy of the state object

func (*StateObject) GetState

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

func (self *StateObject) MarkForDeletion()

MarkForDeletion marks an account to be removed

func (*StateObject) Nonce

func (self *StateObject) Nonce() uint64

Nonce returns the account nonce

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

type Storage map[string]common.Hash

Storage is a memory map cache of a contract storage

func (Storage) Copy

func (self Storage) Copy() Storage

Copy copies the contents of a storage cache

func (Storage) String

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