account

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2018 License: LGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BalanceLog types.ChangeLogType = iota + 1
	StorageLog
	CodeLog
	AddEventLog
	SuicideLog
)
View Source
const MaxTrieCacheGen = uint16(120)

Trie cache generation limit after which to evict trie nodes from memory.

Variables

View Source
var (
	ErrNegativeBalance = errors.New("balance can't be negative")
	ErrLoadCodeFail    = errors.New("can't load contract code")
	ErrTrieFail        = errors.New("can't load contract storage trie")
	ErrTrieChanged     = errors.New("the trie has changed after Finalise")
)
View Source
var (
	ErrRevisionNotExist = errors.New("revision cannot be reverted")
	ErrNoEvents         = errors.New("the times of pop event is more than push")
	ErrSnapshotIsBroken = errors.New("the snapshot is broken")
)

Functions

func IsValuable

func IsValuable(log *types.ChangeLog) bool

IsValuable returns true if the change log contains some data change

func MergeChangeLogs

MergeChangeLogs merges the change logs for same account in block. Then return the merged change logs and the versions need to be revert.

func NewAddEventLog

func NewAddEventLog(account types.AccountAccessor, newEvent *types.Event) *types.ChangeLog

NewAddEventLog records contract code change

func NewBalanceLog

func NewBalanceLog(account types.AccountAccessor, newBalance *big.Int) *types.ChangeLog

NewBalanceLog records balance change

func NewCodeLog

func NewCodeLog(account types.AccountAccessor, code types.Code) *types.ChangeLog

NewCodeLog records contract code setting

func NewStorageLog

func NewStorageLog(account types.AccountAccessor, key common.Hash, newVal []byte) (*types.ChangeLog, error)

NewStorageLog records contract storage value change

func NewSuicideLog

func NewSuicideLog(account types.AccountAccessor) *types.ChangeLog

NewSuicideLog records balance change

Types

type Account

type Account struct {
	// contains filtered or unexported fields
}

Account is used to read and write account data. the code and dirty storage K/V would be cached till they are flushing to db

func NewAccount

func NewAccount(db protocol.ChainDB, address common.Address, data *types.AccountData, baseHeight uint32) *Account

NewAccount wrap an AccountData object, or creates a new one if it's nil.

func (*Account) Finalise

func (a *Account) Finalise() error

Finalise finalises the state, clears the change caches and update tries.

func (*Account) GetAddress

func (a *Account) GetAddress() common.Address

Implement AccountAccessor. Access Account without changelog

func (*Account) GetBalance

func (a *Account) GetBalance() *big.Int

func (*Account) GetBaseHeight

func (a *Account) GetBaseHeight() uint32

func (*Account) GetCode

func (a *Account) GetCode() (types.Code, error)

Code returns the contract code associated with this account, if any.

func (*Account) GetCodeHash

func (a *Account) GetCodeHash() common.Hash

func (*Account) GetStorageRoot

func (a *Account) GetStorageRoot() common.Hash

StorageRoot wouldn't change until Account.updateTrie() is called

func (*Account) GetStorageState

func (a *Account) GetStorageState(key common.Hash) ([]byte, error)

GetState returns a value in account storage.

func (*Account) GetSuicide

func (a *Account) GetSuicide() bool

func (*Account) GetTxHashList

func (a *Account) GetTxHashList() []common.Hash

func (*Account) GetVersion

func (a *Account) GetVersion(logType types.ChangeLogType) uint32

func (*Account) IsEmpty

func (a *Account) IsEmpty() bool

IsEmpty returns whether the state object is either non-existent or empty (version = 0)

func (*Account) LoadNewestChangeLogs

func (a *Account) LoadNewestChangeLogs() ([]*types.ChangeLog, error)

LoadNewestChangeLogs loads newest change logs

func (*Account) MarshalJSON

func (a *Account) MarshalJSON() ([]byte, error)

MarshalJSON encodes the lemoClient RPC account format.

func (*Account) Save

func (a *Account) Save() error

Save writes dirty data into db.

func (*Account) SetBalance

func (a *Account) SetBalance(balance *big.Int)

func (*Account) SetCode

func (a *Account) SetCode(code types.Code)

func (*Account) SetCodeHash

func (a *Account) SetCodeHash(codeHash common.Hash)

func (*Account) SetStorageRoot

func (a *Account) SetStorageRoot(root common.Hash)

func (*Account) SetStorageState

func (a *Account) SetStorageState(key common.Hash, value []byte) error

SetState updates a value in account storage.

func (*Account) SetSuicide

func (a *Account) SetSuicide(suicided bool)

func (*Account) SetVersion

func (a *Account) SetVersion(logType types.ChangeLogType, version uint32)

func (*Account) String

func (a *Account) String() string

func (*Account) UnmarshalJSON

func (a *Account) UnmarshalJSON(input []byte) error

UnmarshalJSON decodes the lemoClient RPC account format.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager is used to maintain the newest and not confirmed account data. It will save all data to the db when finished a block's transactions processing.

func NewManager

func NewManager(blockHash common.Hash, db protocol.ChainDB) *Manager

NewManager creates a new Manager. it is used to maintain account changes based on the block environment which specified by blockHash

func (*Manager) AddEvent

func (am *Manager) AddEvent(event *types.Event)

AddEvent records the event during transaction's execution.

func (*Manager) Finalise

func (am *Manager) Finalise() error

Finalise finalises the state, clears the change caches and update tries.

func (*Manager) GetAccount

func (am *Manager) GetAccount(address common.Address) types.AccountAccessor

GetAccount loads account from cache or db, or creates a new one if it's not exist.

func (*Manager) GetCanonicalAccount

func (am *Manager) GetCanonicalAccount(address common.Address) types.AccountAccessor

GetCanonicalAccount loads an readonly account object from confirmed block in db, or creates a new one if it's not exist. The Modification of the account will not be recorded to store.

func (*Manager) GetChangeLogs

func (am *Manager) GetChangeLogs() []*types.ChangeLog

GetChangeLogs returns all change logs since last reset

func (*Manager) GetEvents

func (am *Manager) GetEvents() []*types.Event

GetEvents returns all events since last reset

func (*Manager) GetEventsByTx

func (am *Manager) GetEventsByTx(txHash common.Hash) []*types.Event

GetEvents returns all events since last reset

func (*Manager) GetVersionRoot

func (am *Manager) GetVersionRoot() common.Hash

func (*Manager) IsExist

func (am *Manager) IsExist(address common.Address) bool

IsExist reports whether the given account address exists in the db. Notably this also returns true for suicided accounts.

func (*Manager) MergeChangeLogs

func (am *Manager) MergeChangeLogs(fromIndex int)

MergeChangeLogs merges the change logs for same account in block. Then update the version of change logs and account.

func (*Manager) Rebuild

func (am *Manager) Rebuild(address common.Address) error

Rebuild loads and redo all change logs to update account to the newest state.

TODO Changelog maybe retrieved from other node, so the account in local store is not contain the newest NewestRecords. We'd better change this function to "Rebuild(address common.Address, logs []types.ChangeLog)" cause the Rebuild function is called by change log synchronization module

func (*Manager) Reset

func (am *Manager) Reset(blockHash common.Hash)

Reset clears out all data and switch state to the new block environment.

func (*Manager) RevertToSnapshot

func (am *Manager) RevertToSnapshot(revid int)

RevertToSnapshot reverts all state changes made since the given revision.

func (*Manager) Save

func (am *Manager) Save(newBlockHash common.Hash) error

Save writes dirty data into db.

func (*Manager) SaveTxInAccount

func (am *Manager) SaveTxInAccount(fromAddr, toAddr common.Address, txHash common.Hash)

func (*Manager) Snapshot

func (am *Manager) Snapshot() int

Snapshot returns an identifier for the current revision of the state.

func (*Manager) Stop

func (am *Manager) Stop(graceful bool) error

type SafeAccount

type SafeAccount struct {
	// contains filtered or unexported fields
}

SafeAccount is used to record modifications with changelog. So that the modifications can be reverted

func NewSafeAccount

func NewSafeAccount(processor *logProcessor, account *Account) *SafeAccount

NewSafeAccount creates an account object.

func (*SafeAccount) AppendTx

func (a *SafeAccount) AppendTx(hash common.Hash)

func (*SafeAccount) GetAddress

func (a *SafeAccount) GetAddress() common.Address

func (*SafeAccount) GetBalance

func (a *SafeAccount) GetBalance() *big.Int

func (*SafeAccount) GetBaseHeight

func (a *SafeAccount) GetBaseHeight() uint32

func (*SafeAccount) GetCode

func (a *SafeAccount) GetCode() (types.Code, error)

func (*SafeAccount) GetCodeHash

func (a *SafeAccount) GetCodeHash() common.Hash

func (*SafeAccount) GetStorageRoot

func (a *SafeAccount) GetStorageRoot() common.Hash

func (*SafeAccount) GetStorageState

func (a *SafeAccount) GetStorageState(key common.Hash) ([]byte, error)

func (*SafeAccount) GetSuicide

func (a *SafeAccount) GetSuicide() bool

func (*SafeAccount) GetTxHashList

func (a *SafeAccount) GetTxHashList() []common.Hash

func (*SafeAccount) GetVersion

func (a *SafeAccount) GetVersion(logType types.ChangeLogType) uint32

func (*SafeAccount) IsDirty

func (a *SafeAccount) IsDirty() bool

func (*SafeAccount) IsEmpty

func (a *SafeAccount) IsEmpty() bool

func (*SafeAccount) MarshalJSON

func (a *SafeAccount) MarshalJSON() ([]byte, error)

MarshalJSON encodes the lemoClient RPC safeAccount format.

func (*SafeAccount) SetBalance

func (a *SafeAccount) SetBalance(balance *big.Int)

overwrite Account.SetXXX. Access Account with changelog

func (*SafeAccount) SetCode

func (a *SafeAccount) SetCode(code types.Code)

func (*SafeAccount) SetCodeHash

func (a *SafeAccount) SetCodeHash(codeHash common.Hash)

func (*SafeAccount) SetStorageRoot

func (a *SafeAccount) SetStorageRoot(root common.Hash)

func (*SafeAccount) SetStorageState

func (a *SafeAccount) SetStorageState(key common.Hash, value []byte) error

func (*SafeAccount) SetSuicide

func (a *SafeAccount) SetSuicide(suicided bool)

func (*SafeAccount) SetVersion

func (a *SafeAccount) SetVersion(logType types.ChangeLogType, version uint32)

func (*SafeAccount) String

func (a *SafeAccount) String() string

func (*SafeAccount) UnmarshalJSON

func (a *SafeAccount) UnmarshalJSON(input []byte) error

UnmarshalJSON decodes the lemoClient RPC safeAccount format.

type Storage

type Storage map[common.Hash][]byte

func (Storage) Copy

func (s Storage) Copy() Storage

func (Storage) String

func (s Storage) String() (str string)

Jump to

Keyboard shortcuts

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