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 ¶
- Constants
- Variables
- func LatestTokenIDTrieKey() []byte
- func TokenTrieKey(tokenID int32) []byte
- type AccountData
- type BalanceSet
- func (bs *BalanceSet) Copy() BalanceSet
- func (bs *BalanceSet) IsEmpty() bool
- func (bs *BalanceSet) MarshalMsg() (b []byte, err error)
- func (bs *BalanceSet) MsgSize() int
- func (bs *BalanceSet) PreAdd(tokenID int32, increment *math.BigInt) *math.BigInt
- func (bs *BalanceSet) PreSub(tokenID int32, decrement *math.BigInt) *math.BigInt
- func (bs *BalanceSet) UnmarshalMsg(bts []byte) (b []byte, err error)
- type Database
- type JournalEntry
- type StateDB
- func (sd *StateDB) AddBalance(addr ogTypes.Address, increment *math.BigInt)
- func (sd *StateDB) AddPreimage(h ogTypes.Hash, b []byte)
- func (sd *StateDB) AddRefund(increment uint64)
- func (sd *StateDB) AddTokenBalance(addr ogTypes.Address, tokenID int32, increment *math.BigInt)
- func (sd *StateDB) AppendJournal(entry JournalEntry)
- func (sd *StateDB) ClearJournalAndRefund()
- func (sd *StateDB) Commit() (ogTypes.Hash, error)
- func (sd *StateDB) CreateAccount(addr ogTypes.Address)
- func (sd *StateDB) Database() Database
- func (sd *StateDB) DeleteStateObject(addr ogTypes.Address) error
- func (sd *StateDB) DestroyToken(tokenID int32) error
- func (sd *StateDB) Empty(addr ogTypes.Address) bool
- func (sd *StateDB) Exist(addr ogTypes.Address) bool
- func (sd *StateDB) ForEachStorage(addr ogTypes.Address, f func(key, value ogTypes.Hash) bool)
- func (sd *StateDB) GetAllTokenBalance(addr ogTypes.Address) BalanceSet
- func (sd *StateDB) GetBalance(addr ogTypes.Address) *math.BigInt
- func (sd *StateDB) GetCode(addr ogTypes.Address) []byte
- func (sd *StateDB) GetCodeHash(addr ogTypes.Address) ogTypes.Hash
- func (sd *StateDB) GetCodeSize(addr ogTypes.Address) int
- func (sd *StateDB) GetCommittedState(addr ogTypes.Address, key ogTypes.Hash) ogTypes.Hash
- func (sd *StateDB) GetNonce(addr ogTypes.Address) uint64
- func (sd *StateDB) GetOrCreateStateObject(addr ogTypes.Address) *StateObject
- func (sd *StateDB) GetRefund() uint64
- func (sd *StateDB) GetState(addr ogTypes.Address, key ogTypes.Hash) ogTypes.Hash
- func (sd *StateDB) GetStateObject(addr ogTypes.Address) *StateObject
- func (sd *StateDB) GetTokenBalance(addr ogTypes.Address, tokenID int32) *math.BigInt
- func (sd *StateDB) GetTokenObject(tokenID int32) *TokenObject
- func (sd *StateDB) HasSuicided(addr ogTypes.Address) bool
- func (sd *StateDB) IssueToken(issuer ogTypes.Address, name, symbol string, reIssuable bool, ...) (int32, error)
- func (sd *StateDB) LatestTokenID() int32
- func (sd *StateDB) ReIssueToken(tokenID int32, amount *math.BigInt) error
- func (sd *StateDB) RevertToSnapshot(snapshotid int)
- func (sd *StateDB) Root() ogTypes.Hash
- func (sd *StateDB) SetBalance(addr ogTypes.Address, balance *math.BigInt)
- func (sd *StateDB) SetCode(addr ogTypes.Address, code []byte)
- func (sd *StateDB) SetNonce(addr ogTypes.Address, nonce uint64)
- func (sd *StateDB) SetState(addr ogTypes.Address, key, value ogTypes.Hash)
- func (sd *StateDB) SetStateObject(addr ogTypes.Address, stobj *StateObject)
- func (sd *StateDB) SetTokenBalance(addr ogTypes.Address, tokenID int32, balance *math.BigInt)
- func (sd *StateDB) Snapshot() int
- func (sd *StateDB) Stop()
- func (sd *StateDB) String() string
- func (sd *StateDB) SubBalance(addr ogTypes.Address, decrement *math.BigInt)
- func (sd *StateDB) SubRefund(decrement uint64)
- func (sd *StateDB) SubTokenBalance(addr ogTypes.Address, tokenID int32, decrement *math.BigInt)
- func (sd *StateDB) Suicide(addr ogTypes.Address) bool
- type StateDBConfig
- type StateDBInterface
- type StateObject
- func (s *StateObject) AddBalance(tokenID int32, increment *math.BigInt)
- func (s *StateObject) CommitStorage(db Database, preCommit bool) error
- func (s *StateObject) Copy(src *StateObject)
- 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) GetAllBalance() BalanceSet
- func (s *StateObject) GetBalance(tokenID int32) *math.BigInt
- func (s *StateObject) GetCode(db Database) []byte
- func (s *StateObject) GetCodeHash() ogTypes.Hash
- func (s *StateObject) GetCodeSize(db Database) (int, error)
- func (s *StateObject) GetCommittedState(db Database, key ogTypes.Hash) ogTypes.Hash
- func (s *StateObject) GetNonce() uint64
- func (s *StateObject) GetState(db Database, key ogTypes.Hash) ogTypes.Hash
- func (s *StateObject) Map() map[string]interface{}
- func (z StateObject) MarshalMsg(b []byte) (o []byte, err error)
- func (z StateObject) Msgsize() (s int)
- func (s *StateObject) SetBalance(tokenID int32, balance *math.BigInt)
- func (s *StateObject) SetCode(codehash ogTypes.Hash, code []byte)
- func (s *StateObject) SetNonce(nonce uint64)
- func (s *StateObject) SetState(db Database, key, value ogTypes.Hash)
- func (s *StateObject) String() string
- func (s *StateObject) SubBalance(tokenID int32, decrement *math.BigInt)
- func (s *StateObject) Uncache()
- func (z *StateObject) UnmarshalMsg(bts []byte) (o []byte, err error)
- type TokenObject
- func (t *TokenObject) AllIssues() []*math.BigInt
- func (t *TokenObject) CanReIssue() bool
- func (t *TokenObject) CopyRaw(tObj *TokenObject)
- func (t *TokenObject) Decode(b []byte) error
- func (t *TokenObject) Destroy()
- func (t *TokenObject) Encode() ([]byte, error)
- func (t *TokenObject) GetID() int32
- func (t *TokenObject) GetName() string
- func (t *TokenObject) GetSymbol() string
- func (t *TokenObject) MarshalMsg() ([]byte, error)
- func (t *TokenObject) MsgSize() int
- func (t *TokenObject) OneIssue(term int) *math.BigInt
- func (t *TokenObject) ReIssue(amount *math.BigInt) error
- func (t *TokenObject) UnmarshalMsg(b []byte) ([]byte, error)
- type Trie
Constants ¶
const ( MaxTokenName = 20 MaxTokenSymbol = 5 )
const (
KeyPrefix string = "tkID"
)
const TokenNotDirtied int32 = -1
Variables ¶
var MaxTrieCacheGen = uint16(120)
MaxTrieCacheGen is trie cache generation limit after which to evict trie nodes from memory.
var (
OGTokenID = int32(0)
)
token id
Functions ¶
func LatestTokenIDTrieKey ¶
func LatestTokenIDTrieKey() []byte
func TokenTrieKey ¶
Types ¶
type AccountData ¶
type AccountData struct { Address ogTypes.Address Balances BalanceSet Nonce uint64 Root ogTypes.Hash CodeHash []byte }
func NewAccountData ¶
func NewAccountData() AccountData
func (*AccountData) DecodeMsg ¶
func (z *AccountData) DecodeMsg(dc *msgp.Reader) (err error)
DecodeMsg implements msgp.Decodable
func (*AccountData) EncodeMsg ¶
func (z *AccountData) EncodeMsg(en *msgp.Writer) (err error)
EncodeMsg implements msgp.Encodable
func (*AccountData) MarshalMsg ¶
func (a *AccountData) MarshalMsg() (b []byte, err error)
func (*AccountData) MsgSize ¶
func (a *AccountData) MsgSize() int
func (*AccountData) UnmarshalMsg ¶
func (a *AccountData) UnmarshalMsg(b []byte) ([]byte, error)
type BalanceSet ¶
func NewBalanceSet ¶
func NewBalanceSet() BalanceSet
func (*BalanceSet) Copy ¶
func (bs *BalanceSet) Copy() BalanceSet
func (*BalanceSet) IsEmpty ¶
func (bs *BalanceSet) IsEmpty() bool
func (*BalanceSet) MarshalMsg ¶
func (bs *BalanceSet) MarshalMsg() (b []byte, err error)
func (*BalanceSet) MsgSize ¶
func (bs *BalanceSet) MsgSize() int
func (*BalanceSet) UnmarshalMsg ¶
func (bs *BalanceSet) UnmarshalMsg(bts []byte) (b []byte, err error)
type Database ¶
type Database interface { // OpenTrie opens the main account trie. OpenTrie(root ogTypes.Hash) (Trie, error) // OpenStorageTrie opens the storage trie of an account. OpenStorageTrie(addrHash, root ogTypes.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 ogTypes.Hash) ([]byte, error) // ContractCodeSize retrieves a particular contracts code's size. ContractCodeSize(addrHash, codeHash ogTypes.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 JournalEntry ¶
type JournalEntry interface { // revert undoes the changes introduced by this journal entry. Revert(db *StateDB) // dirtied returns the address modified by this journal entry. Dirtied() ogTypes.Address // TokenDirtied returns the Token ID modified by this journal entry. TokenDirtied() int32 }
journalEntry is a modification entry in the state change journal that can be reverted on demand.
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) AddTokenBalance ¶
func (*StateDB) AppendJournal ¶
func (sd *StateDB) AppendJournal(entry JournalEntry)
func (*StateDB) ClearJournalAndRefund ¶
func (sd *StateDB) ClearJournalAndRefund()
func (*StateDB) CreateAccount ¶
CreateAccount will create a new state for input address.
func (*StateDB) DeleteStateObject ¶
DeleteStateObject remove a state from StateDB. Return error if it fails.
func (*StateDB) DestroyToken ¶
func (*StateDB) ForEachStorage ¶
func (*StateDB) GetAllTokenBalance ¶
func (sd *StateDB) GetAllTokenBalance(addr ogTypes.Address) BalanceSet
func (*StateDB) GetCommittedState ¶
func (*StateDB) GetOrCreateStateObject ¶
func (sd *StateDB) GetOrCreateStateObject(addr ogTypes.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 ogTypes.Address) *StateObject
GetStateObject get a state from StateDB. If state not exist, load it from db.
func (*StateDB) GetTokenBalance ¶
func (*StateDB) GetTokenObject ¶
func (sd *StateDB) GetTokenObject(tokenID int32) *TokenObject
GetTokenObject get token object from StateDB.tokens . If not exists then try to load from trie db.
func (*StateDB) IssueToken ¶
func (sd *StateDB) IssueToken(issuer ogTypes.Address, name, symbol string, reIssuable bool, fstIssue *math.BigInt) (int32, error)
IssueToken creates a new token according to offered token information.
func (*StateDB) LatestTokenID ¶
func (*StateDB) ReIssueToken ¶
func (*StateDB) RevertToSnapshot ¶
func (*StateDB) SetBalance ¶
SetBalance set origin OG token balance. TODO should be modified to satisfy all tokens.
func (*StateDB) SetStateObject ¶
func (sd *StateDB) SetStateObject(addr ogTypes.Address, stobj *StateObject)
func (*StateDB) SetTokenBalance ¶
func (*StateDB) SubBalance ¶
SubBalance
func (*StateDB) SubTokenBalance ¶
type StateDBConfig ¶
func DefaultStateDBConfig ¶
func DefaultStateDBConfig() StateDBConfig
type StateDBInterface ¶
type StateDBInterface interface { CreateAccount(ogTypes.Address) SubBalance(ogTypes.Address, *math.BigInt) SubTokenBalance(ogTypes.Address, int32, *math.BigInt) AddBalance(ogTypes.Address, *math.BigInt) AddTokenBalance(ogTypes.Address, int32, *math.BigInt) SetTokenBalance(ogTypes.Address, int32, *math.BigInt) // Retrieve the balance from the given address or 0 if object not found GetBalance(ogTypes.Address) *math.BigInt GetTokenBalance(ogTypes.Address, int32) *math.BigInt GetNonce(ogTypes.Address) uint64 SetNonce(ogTypes.Address, uint64) GetCodeHash(ogTypes.Address) ogTypes.Hash GetCode(ogTypes.Address) []byte SetCode(ogTypes.Address, []byte) GetCodeSize(ogTypes.Address) int // AddRefund adds gas to the refund counter AddRefund(uint64) // SubRefund removes gas from the refund counter. // This method will panic if the refund counter goes below zero SubRefund(uint64) // GetRefund returns the current value of the refund counter. GetRefund() uint64 GetCommittedState(ogTypes.Address, ogTypes.Hash) ogTypes.Hash // GetState retrieves a value from the given account's storage trie. GetState(ogTypes.Address, ogTypes.Hash) ogTypes.Hash SetState(ogTypes.Address, ogTypes.Hash, ogTypes.Hash) AppendJournal(JournalEntry) // Suicide marks the given account as suicided. // This clears the account balance. // // The account's state object is still available until the state is committed, // getStateObject will return a non-nil account after Suicide. Suicide(ogTypes.Address) bool HasSuicided(ogTypes.Address) bool // Exist reports whether the given account exists in state. // Notably this should also return true for suicided accounts. Exist(ogTypes.Address) bool // Empty returns whether the given account is empty. Empty // is defined according to EIP161 (balance = nonce = code = 0). Empty(ogTypes.Address) bool // RevertToSnapshot reverts all state changes made since the given revision. RevertToSnapshot(int) // Snapshot creates a new revision Snapshot() int //AddLog(*Log) AddPreimage(ogTypes.Hash, []byte) ForEachStorage(ogTypes.Address, func(ogTypes.Hash, ogTypes.Hash) bool) // for debug. String() string }
StateDB is an OVM database for full state querying.
type StateObject ¶
type StateObject struct {
// contains filtered or unexported fields
}
func NewStateObject ¶
func NewStateObject(addr ogTypes.Address, db StateDBInterface) *StateObject
func (*StateObject) AddBalance ¶
func (s *StateObject) AddBalance(tokenID int32, increment *math.BigInt)
func (*StateObject) CommitStorage ¶
func (s *StateObject) CommitStorage(db Database, preCommit bool) error
func (*StateObject) Copy ¶
func (s *StateObject) Copy(src *StateObject)
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) GetAllBalance ¶
func (s *StateObject) GetAllBalance() BalanceSet
func (*StateObject) GetBalance ¶
func (s *StateObject) GetBalance(tokenID int32) *math.BigInt
func (*StateObject) GetCode ¶
func (s *StateObject) GetCode(db Database) []byte
func (*StateObject) GetCodeHash ¶
func (s *StateObject) GetCodeHash() ogTypes.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) Map ¶
func (s *StateObject) Map() map[string]interface{}
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(tokenID int32, balance *math.BigInt)
func (*StateObject) SetNonce ¶
func (s *StateObject) SetNonce(nonce uint64)
func (*StateObject) String ¶
func (s *StateObject) String() string
func (*StateObject) SubBalance ¶
func (s *StateObject) SubBalance(tokenID int32, 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 TokenObject ¶
type TokenObject struct { TokenID int32 Name string Symbol string Issuer ogtypes.Address ReIssuable bool Issues []*math.BigInt Destroyed bool // contains filtered or unexported fields }
func NewTokenObject ¶
func NewTokenObject(tokenID int32, issuer ogtypes.Address, name, symbol string, reIssuable bool, fstIssue *math.BigInt, db StateDBInterface) *TokenObject
func (*TokenObject) AllIssues ¶
func (t *TokenObject) AllIssues() []*math.BigInt
func (*TokenObject) CanReIssue ¶
func (t *TokenObject) CanReIssue() bool
func (*TokenObject) CopyRaw ¶
func (t *TokenObject) CopyRaw(tObj *TokenObject)
func (*TokenObject) Decode ¶
func (t *TokenObject) Decode(b []byte) error
func (*TokenObject) Destroy ¶
func (t *TokenObject) Destroy()
func (*TokenObject) Encode ¶
func (t *TokenObject) Encode() ([]byte, error)
func (*TokenObject) GetID ¶
func (t *TokenObject) GetID() int32
func (*TokenObject) GetName ¶
func (t *TokenObject) GetName() string
func (*TokenObject) GetSymbol ¶
func (t *TokenObject) GetSymbol() string
func (*TokenObject) MarshalMsg ¶
func (t *TokenObject) MarshalMsg() ([]byte, error)
func (*TokenObject) MsgSize ¶
func (t *TokenObject) MsgSize() int
func (*TokenObject) UnmarshalMsg ¶
func (t *TokenObject) UnmarshalMsg(b []byte) ([]byte, error)
type Trie ¶
type Trie interface { TryGet(key []byte) ([]byte, error) TryUpdate(key, value []byte) error TryDelete(key []byte) error // preCommit is a flag for pre confirming sequencer. Because pre confirm uses the // same trie db in real sequencer confirm and the db will be modified during db commit. // To avoid this, add a flag to let pre confirm process not modify trie db anymore. Commit(onleaf trie.LeafCallback, preCommit bool) (ogTypes.Hash, error) Hash() ogTypes.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.