Documentation
¶
Overview ¶
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Variables
- type Account
- type Database
- type StateDB
- func (sd *StateDB) AddBalance(addr types.Address, increment *math.BigInt)
- func (sd *StateDB) AddLog(l *vmtypes.Log)
- func (sd *StateDB) AddPreimage(h types.Hash, b []byte)
- func (sd *StateDB) AddRefund(increment uint64)
- func (sd *StateDB) Commit() (types.Hash, error)
- func (sd *StateDB) CreateAccount(addr types.Address)
- func (sd *StateDB) Database() Database
- func (sd *StateDB) DeleteStateObject(addr types.Address) error
- func (sd *StateDB) Empty(addr types.Address) bool
- func (sd *StateDB) Exist(addr types.Address) bool
- func (sd *StateDB) ForEachStorage(addr types.Address, f func(key, value types.Hash) bool)
- func (sd *StateDB) GetBalance(addr types.Address) *math.BigInt
- func (sd *StateDB) GetCode(addr types.Address) []byte
- func (sd *StateDB) GetCodeHash(addr types.Address) types.Hash
- func (sd *StateDB) GetCodeSize(addr types.Address) int
- func (sd *StateDB) GetCommittedState(addr types.Address, key types.Hash) types.Hash
- func (sd *StateDB) GetNonce(addr types.Address) uint64
- func (sd *StateDB) GetOrCreateStateObject(addr types.Address) *StateObject
- func (sd *StateDB) GetRefund() uint64
- func (sd *StateDB) GetState(addr types.Address, key types.Hash) types.Hash
- func (sd *StateDB) GetStateObject(addr types.Address) *StateObject
- func (sd *StateDB) HasSuicided(addr types.Address) bool
- func (sd *StateDB) RevertToSnapshot(snapshotid int)
- func (sd *StateDB) Root() types.Hash
- func (sd *StateDB) SetBalance(addr types.Address, balance *math.BigInt)
- func (sd *StateDB) SetCode(addr types.Address, code []byte)
- func (sd *StateDB) SetNonce(addr types.Address, nonce uint64)
- func (sd *StateDB) SetState(addr types.Address, key, value types.Hash)
- func (sd *StateDB) SetStateObject(addr types.Address, stobj *StateObject)
- func (sd *StateDB) Snapshot() int
- func (sd *StateDB) Stop()
- func (sd *StateDB) String() string
- func (sd *StateDB) SubBalance(addr types.Address, decrement *math.BigInt)
- func (sd *StateDB) SubRefund(decrement uint64)
- func (sd *StateDB) Suicide(addr types.Address) bool
- type StateDBConfig
- type StateObject
- func (s *StateObject) AddBalance(increment *math.BigInt)
- func (s *StateObject) CommitStorage(db Database) error
- func (s *StateObject) Decode(b []byte, db *StateDB) error
- func (z *StateObject) DecodeMsg(dc *msgp.Reader) (err error)
- func (s *StateObject) Encode() ([]byte, error)
- func (z StateObject) EncodeMsg(en *msgp.Writer) (err error)
- func (s *StateObject) GetBalance() *math.BigInt
- func (s *StateObject) GetCode(db Database) []byte
- func (s *StateObject) GetCodeHash() types.Hash
- func (s *StateObject) GetCodeSize(db Database) (int, error)
- func (s *StateObject) GetCommittedState(db Database, key types.Hash) types.Hash
- func (s *StateObject) GetNonce() uint64
- func (s *StateObject) GetState(db Database, key types.Hash) types.Hash
- func (z StateObject) MarshalMsg(b []byte) (o []byte, err error)
- func (z StateObject) Msgsize() (s int)
- func (s *StateObject) SetBalance(balance *math.BigInt)
- func (s *StateObject) SetCode(codehash types.Hash, code []byte)
- func (s *StateObject) SetNonce(nonce uint64)
- func (s *StateObject) SetState(db Database, key, value types.Hash)
- func (s *StateObject) SubBalance(decrement *math.BigInt)
- func (s *StateObject) Uncache()
- func (z *StateObject) UnmarshalMsg(bts []byte) (o []byte, err error)
- type Trie
Constants ¶
This section is empty.
Variables ¶
var MaxTrieCacheGen = uint16(120)
MaxTrieCacheGen is trie cache generation limit after which to evict trie nodes from memory.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct {
Address types.Address
Balance *math.BigInt
Nonce uint64
Root types.Hash
CodeHash []byte
}
func (*Account) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type Database ¶
type Database interface {
// OpenTrie opens the main account trie.
OpenTrie(root types.Hash) (Trie, error)
// OpenStorageTrie opens the storage trie of an account.
OpenStorageTrie(addrHash, root types.Hash) (Trie, error)
// CopyTrie returns an independent copy of the given trie.
CopyTrie(Trie) Trie
// ContractCode retrieves a particular contract's code.
ContractCode(addrHash, codeHash types.Hash) ([]byte, error)
// ContractCodeSize retrieves a particular contracts code's size.
ContractCodeSize(addrHash, codeHash types.Hash) (int, error)
// TrieDB retrieves the low level trie database used for data storage.
TrieDB() *trie.Database
}
Database wraps access to tries and contract code.
func NewDatabase ¶
NewDatabase creates a backing store for state. The returned database is safe for concurrent use and retains cached trie nodes in memory. The pool is an optional intermediate trie-node memory pool between the low level storage layer and the high level trie abstraction.
type StateDB ¶
type StateDB struct {
// contains filtered or unexported fields
}
StateDB stores account's data. Account's data include address, balance, nonce, code and its contract db if it is an contract address. An account is stored as a StateObject, for more detail please check StateObject struct.
func NewStateDB ¶
func (*StateDB) AddBalance ¶
AddBalance
func (*StateDB) CreateAccount ¶
CreateAccount will create a new state for input address and return the state. If input address already exists in StateDB returns it.
func (*StateDB) DeleteStateObject ¶
DeleteStateObject remove a state from StateDB. Return error if it fails.
func (*StateDB) ForEachStorage ¶
func (*StateDB) GetCommittedState ¶
func (*StateDB) GetOrCreateStateObject ¶
func (sd *StateDB) GetOrCreateStateObject(addr types.Address) *StateObject
GetOrCreateStateObject will find a state from memory by account address. If state not exists, it will load a state from db.
func (*StateDB) GetStateObject ¶
func (sd *StateDB) GetStateObject(addr types.Address) *StateObject
GetStateObject get a state from StateDB. If state not exist, load it from db.
func (*StateDB) RevertToSnapshot ¶
func (*StateDB) SetBalance ¶
SetBalance
func (*StateDB) SetStateObject ¶
func (sd *StateDB) SetStateObject(addr types.Address, stobj *StateObject)
func (*StateDB) SubBalance ¶
SubBalance
type StateDBConfig ¶
func DefaultStateDBConfig ¶
func DefaultStateDBConfig() StateDBConfig
type StateObject ¶
type StateObject struct {
// contains filtered or unexported fields
}
func NewStateObject ¶
func NewStateObject(addr types.Address, db *StateDB) *StateObject
func (*StateObject) AddBalance ¶
func (s *StateObject) AddBalance(increment *math.BigInt)
func (*StateObject) CommitStorage ¶
func (s *StateObject) CommitStorage(db Database) error
func (*StateObject) DecodeMsg ¶
func (z *StateObject) DecodeMsg(dc *msgp.Reader) (err error)
DecodeMsg implements msgp.Decodable
func (*StateObject) Encode ¶
func (s *StateObject) Encode() ([]byte, error)
func (StateObject) EncodeMsg ¶
func (z StateObject) EncodeMsg(en *msgp.Writer) (err error)
EncodeMsg implements msgp.Encodable
func (*StateObject) GetBalance ¶
func (s *StateObject) GetBalance() *math.BigInt
func (*StateObject) GetCode ¶
func (s *StateObject) GetCode(db Database) []byte
func (*StateObject) GetCodeHash ¶
func (s *StateObject) GetCodeHash() types.Hash
func (*StateObject) GetCodeSize ¶
func (s *StateObject) GetCodeSize(db Database) (int, error)
func (*StateObject) GetCommittedState ¶
func (*StateObject) GetNonce ¶
func (s *StateObject) GetNonce() uint64
func (StateObject) MarshalMsg ¶
func (z StateObject) MarshalMsg(b []byte) (o []byte, err error)
MarshalMsg implements msgp.Marshaler
func (StateObject) Msgsize ¶
func (z StateObject) Msgsize() (s int)
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*StateObject) SetBalance ¶
func (s *StateObject) SetBalance(balance *math.BigInt)
func (*StateObject) SetNonce ¶
func (s *StateObject) SetNonce(nonce uint64)
func (*StateObject) SubBalance ¶
func (s *StateObject) SubBalance(decrement *math.BigInt)
func (*StateObject) Uncache ¶
func (s *StateObject) Uncache()
Uncache clears dirtyStorage and committedStorage. This is aimed to check if state is committed into db.
Note that this function is for test debug only, should not be called by other functions.
func (*StateObject) UnmarshalMsg ¶
func (z *StateObject) UnmarshalMsg(bts []byte) (o []byte, err error)
UnmarshalMsg implements msgp.Unmarshaler
type Trie ¶
type Trie interface {
TryGet(key []byte) ([]byte, error)
TryUpdate(key, value []byte) error
TryDelete(key []byte) error
Commit(onleaf trie.LeafCallback) (types.Hash, error)
Hash() types.Hash
NodeIterator(startKey []byte) trie.NodeIterator
GetKey([]byte) []byte // TODO(fjl): remove this when SecureTrie is removed
Prove(key []byte, fromLevel uint, proofDb ogdb.Putter) error
}
Trie is a Ethereum Merkle Trie.