Documentation
¶
Index ¶
- Constants
- Variables
- func ConfirmReward(state *StateDB, block *types.Block, confirmedBlock *types.Block)
- func CopyStorageValue(value []byte) []byte
- func MiningReward(state *StateDB, block *types.Block)
- func NewStateSync(root common.Hash, database dbwrapper.Database) *trie.Sync
- type Account
- type AccountForStorage
- type Code
- type Database
- type ManagedState
- type StateDB
- func (self *StateDB) AddBalance(addr common.Address, amount *big.Int)
- func (self *StateDB) AddLog(log *types.Log)
- func (self *StateDB) AddRefund(gas uint64)
- func (s *StateDB) Commit(deleteEmptyObjects bool) (root common.Hash, err error)
- func (self *StateDB) Copy() *StateDB
- func (self *StateDB) CreateAccount(addr common.Address)
- func (self *StateDB) Database() Database
- func (s *StateDB) DumpAllState(path string)
- func (s *StateDB) DumpState(msg string)
- func (self *StateDB) Empty(addr common.Address) bool
- func (self *StateDB) Error() error
- func (self *StateDB) Exist(addr common.Address) bool
- func (s *StateDB) Finalise(deleteEmptyObjects bool)
- func (s *StateDB) FinaliseOne()
- func (self *StateDB) GetBalance(addr common.Address) *big.Int
- func (self *StateDB) GetCode(addr common.Address) []byte
- func (self *StateDB) GetCodeHash(addr common.Address) common.Hash
- func (self *StateDB) GetCodeSize(addr common.Address) int
- func (self *StateDB) GetContractOwner(addr common.Address) common.Address
- func (self *StateDB) GetLogs(hash common.Hash) []*types.Log
- func (self *StateDB) GetNonce(addr common.Address) uint64
- func (self *StateDB) GetOrNewStateObject(addr common.Address) *stateObject
- func (self *StateDB) GetPackageNonce(addr common.Address) uint64
- func (self *StateDB) GetPackerInfo(index uint32) *types.PackerInfo
- func (self *StateDB) GetPackerNumber() uint32
- func (self *StateDB) GetRefund() uint64
- func (s *StateDB) GetRoot() common.Hash
- func (self *StateDB) GetState(addr common.Address, key StorageKey) []byte
- func (self *StateDB) GetTradableBalance(addr common.Address, currentRound uint64) *big.Int
- func (self *StateDB) GetTransferBlackList() []common.Address
- func (self *StateDB) GetTransferWhiteList() []common.Address
- func (self *StateDB) HasSuicided(addr common.Address) bool
- func (self *StateDB) InTransferBlackList(addr common.Address) bool
- func (self *StateDB) InTransferWhiteList(addr common.Address) bool
- func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash
- func (self *StateDB) Logs() []*types.Log
- func (self *StateDB) MarkNonceSetJournal(address common.Address, prev *nonces.NonceSet)
- func (self *StateDB) MarkPackageNonceSetJournal(address common.Address)
- func (self *StateDB) PackageNonceSet(addr common.Address) *nonces.NonceSet
- func (self *StateDB) Prepare(thash common.Hash, pi uint32, ti uint32)
- func (s *StateDB) PrintNonceSet()
- func (self *StateDB) Reset(root common.Hash) error
- func (self *StateDB) ResetTo(source *StateDB)
- func (self *StateDB) RevertToSnapshot(revid int)
- func (self *StateDB) SetBalance(addr common.Address, amount *big.Int)
- func (self *StateDB) SetBalanceLock(addr common.Address, amount *big.Int, lockToRound uint64)
- func (self *StateDB) SetCode(addr common.Address, code []byte)
- func (self *StateDB) SetContractOwner(addr common.Address, owner common.Address)
- func (self *StateDB) SetState(addr common.Address, key StorageKey, value []byte)
- func (self *StateDB) Snapshot() int
- func (self *StateDB) StorageTrie(addr common.Address) Trie
- func (self *StateDB) SubBalance(addr common.Address, amount *big.Int)
- func (self *StateDB) Suicide(addr common.Address) bool
- func (self *StateDB) TxNonceSet(addr common.Address) *nonces.NonceSet
- type Storage
- type StorageFormat
- type StorageKey
- type Trie
Constants ¶
const MaxStorageKeyLength = 40
Variables ¶
var MaxTrieCacheGen = uint16(120)
Trie cache generation limit after which to evict trie nodes from memory.
Functions ¶
func ConfirmReward ¶
func CopyStorageValue ¶
func MiningReward ¶
Types ¶
type Account ¶
type Account struct { TxNonceSet nonces.NonceSet PackageNonceSet nonces.NonceSet Balance *big.Int LockedBalance *big.Int LockToRound uint64 // time uint(100ms): same to the "Round" in block Root common.Hash CodeHash []byte ContractOwner common.Address }
Account is the Fractal consensus representation of accounts. These objects are stored in the main account trie.
type AccountForStorage ¶
type AccountForStorage struct { Code string `json:"code,omitempty"` Storage Storage `json:"storage,omitempty"` Balance *big.Int `json:"balance" gencodec:"required"` LockedBalance *big.Int `json:"lockedBalance" gencodec:"required"` LockToRound uint64 `json:"lockToRound" gencodec:"required"` PrivateKey []byte `json:"secretKey,omitempty"` // for tests Owner common.Address `json:"owner,omitempty"` }
type Database ¶
type Database interface { // OpenTrie opens the main account trie. OpenTrie(root common.Hash) (Trie, error) // OpenStorageTrie opens the storage trie of an account. OpenStorageTrie(addrHash, root common.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 common.Hash) ([]byte, error) // ContractCodeSize retrieves a particular contracts code's size. ContractCodeSize(addrHash, codeHash common.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 ManagedState ¶
type ManagedState struct { *StateDB // contains filtered or unexported fields }
func ManageState ¶
func ManageState(statedb *StateDB, elemType reflect.Type) *ManagedState
ManagedState returns a new managed state with the statedb as it's backing layer
type StateDB ¶
type StateDB struct {
// contains filtered or unexported fields
}
StateDBs within the fractal protocol are used to store anything within the merkle trie. StateDBs take care of caching and storing nested states.
func (*StateDB) AddBalance ¶
AddBalance adds amount to the account associated with addr.
func (*StateDB) Copy ¶
Copy creates a deep, independent copy of the state. Snapshots of the copied state cannot be applied to the copy.
func (*StateDB) CreateAccount ¶
CreateAccount explicitly creates a state object. If a state object with the address already exists the balance is carried over to the new account.
CreateAccount is called during the WASM CREATE operation. The new contract address is generated by the crypto.CreateAddress function.
Carrying over the balance ensures that Balance doesn't disappear.
func (*StateDB) Database ¶
Database retrieves the low level database supporting the lower level trie ops.
func (*StateDB) DumpAllState ¶
func (*StateDB) Empty ¶
Empty returns whether the state object is either non-existent or empty according to the specification (balance = nonce = code = 0)
func (*StateDB) Exist ¶
Exist reports whether the given account address exists in the state. Notably this also returns true for suicided accounts.
func (*StateDB) Finalise ¶
Finalise finalises the state by removing the self destructed objects and clears the journal as well as the refunds.
func (*StateDB) FinaliseOne ¶
func (s *StateDB) FinaliseOne()
FinaliseOne is called since a complete transaction/package ends
func (*StateDB) GetBalance ¶
Retrieve the balance from the given address or 0 if object not found
func (*StateDB) GetContractOwner ¶
func (*StateDB) GetOrNewStateObject ¶
Retrieve a state object or create a new state object if nil.
func (*StateDB) GetPackerInfo ¶
func (self *StateDB) GetPackerInfo(index uint32) *types.PackerInfo
func (*StateDB) GetPackerNumber ¶
func (*StateDB) GetState ¶
func (self *StateDB) GetState(addr common.Address, key StorageKey) []byte
func (*StateDB) GetTradableBalance ¶ added in v0.2.2
func (*StateDB) GetTransferBlackList ¶
func (*StateDB) GetTransferWhiteList ¶
func (*StateDB) InTransferBlackList ¶
func (*StateDB) InTransferWhiteList ¶
func (*StateDB) IntermediateRoot ¶
IntermediateRoot computes the current root hash of the state trie. It is called in between transactions to get the root hash that goes into transaction receipts.
func (*StateDB) MarkNonceSetJournal ¶
func (*StateDB) MarkPackageNonceSetJournal ¶
func (*StateDB) PackageNonceSet ¶
func (*StateDB) Prepare ¶
Prepare sets the current transaction hash and index and block hash which is used when the WASM emits new state logs.
func (*StateDB) PrintNonceSet ¶
func (s *StateDB) PrintNonceSet()
func (*StateDB) Reset ¶
Reset clears out all ephemeral state objects from the state db, but keeps the underlying state trie to avoid reloading data for the next operations.
func (*StateDB) RevertToSnapshot ¶
RevertToSnapshot reverts all state changes made since the given revision.
func (*StateDB) SetBalanceLock ¶ added in v0.2.2
Only set in genesis block when init. Must set total balance first.
func (*StateDB) SetContractOwner ¶
func (*StateDB) SetState ¶
func (self *StateDB) SetState(addr common.Address, key StorageKey, value []byte)
func (*StateDB) StorageTrie ¶
StorageTrie returns the storage trie of an account. The return value is a copy and is nil for non-existent accounts.
func (*StateDB) SubBalance ¶
SubBalance subtracts amount from the account associated with addr.
type Storage ¶
type Storage map[StorageKey][]byte
func (Storage) MarshalJSON ¶
func (*Storage) UnmarshalJSON ¶
type StorageFormat ¶
type StorageKey ¶
type StorageKey struct { Length uint8 Bytes [MaxStorageKeyLength]byte }
func GetStorageKey ¶
func GetStorageKey(table uint64, key []byte) StorageKey
func LoadStorageKey ¶
func LoadStorageKey(key []byte) StorageKey
func (*StorageKey) ToSlice ¶
func (self *StorageKey) ToSlice() []byte
type Trie ¶
type Trie interface { TryGet(key []byte) ([]byte, error) TryUpdate(key, value []byte) error TryDelete(key []byte) error Commit(onleaf trie.LeafCallback) (common.Hash, error) Hash() common.Hash NodeIterator(startKey []byte) trie.NodeIterator GetKey([]byte) []byte // TODO(fjl): remove this when SecureTrie is removed Prove(key []byte, fromLevel uint, proofDb dbwrapper.Putter) error }
Trie is a Merkle Trie.