Documentation ¶
Index ¶
- Constants
- Variables
- func Byte2Uint32(val []byte) uint32
- func CheckSum(data []byte) uint16
- func FileUtilsAlign(length uint32) uint32
- func FileUtilsCreateFile(path string) error
- func FileUtilsEncode(flag uint32, key []byte, val []byte) ([]byte, error)
- func FileUtilsFlush(path string, offset int64, data []byte) (int64, error)
- func FileUtilsIsExist(path string) (bool, error)
- func FileUtilsRead(file *os.File, offset int64) (*RecordHead, *RecordBody, error)
- func GetBucketIndex(pos uint32) uint32
- func GetItemIndex(pos uint32) uint32
- func GetPos(bucketIndex uint32, itemIndex uint32) uint32
- func SerializeForks(unconfirmedBlocks map[common.Hash]*CBlock, currentHash common.Hash) string
- func UtilsGetAccount(db *BeansDB, address common.Address) (*types.AccountData, error)
- func UtilsGetAssetCode(db *BeansDB, code common.Hash) (common.Address, error)
- func UtilsGetAssetId(db *BeansDB, id common.Hash) (common.Hash, error)
- func UtilsGetBlockByHash(db *BeansDB, hash common.Hash) (*types.Block, error)
- func UtilsGetBlockByHeight(db *BeansDB, height uint32) (*types.Block, error)
- func UtilsHashBlock(db *BeansDB, hash common.Hash) (bool, error)
- func UtilsSetAssetCode(db *BeansDB, code common.Hash, address common.Address) error
- func UtilsSetAssetId(db *BeansDB, id common.Hash, code common.Hash) error
- type AccountTrieDB
- func (db *AccountTrieDB) Clone() *AccountTrieDB
- func (db *AccountTrieDB) Collect(dye uint32) []*types.AccountData
- func (db *AccountTrieDB) Get(address common.Address) (*types.AccountData, error)
- func (db *AccountTrieDB) GetReader() *BeansDB
- func (db *AccountTrieDB) GetTrie() *PatriciaTrie
- func (db *AccountTrieDB) Put(account *types.AccountData, dye uint32)
- func (db *AccountTrieDB) Set(account *types.AccountData)
- func (db *AccountTrieDB) SetReader(beansdb *BeansDB)
- func (db *AccountTrieDB) SetTrie(trie *PatriciaTrie)
- type Batch
- type BatchItem
- type BeansDB
- func (beansdb *BeansDB) After(flg uint32, key []byte, val []byte) error
- func (beansdb *BeansDB) Close()
- func (beansdb *BeansDB) Commit(batch Batch) error
- func (beansdb *BeansDB) Delete(flg uint32, key []byte) error
- func (beansdb *BeansDB) Get(flg uint32, key []byte) ([]byte, error)
- func (beansdb *BeansDB) Has(flag uint32, key []byte) (bool, error)
- func (beansdb *BeansDB) NewBatch() Batch
- func (beansdb *BeansDB) Put(flag uint32, key []byte, val []byte) error
- func (beansdb *BeansDB) Start()
- type BitCask
- type BizDatabase
- type BizDb
- type CBlock
- type CachedNode
- type Candidate
- type CandidateCache
- func (cache *CandidateCache) Decode(buf []byte, length int) error
- func (cache *CandidateCache) Encode() ([]byte, int)
- func (cache *CandidateCache) GetCandidatePage(index int, size int) ([]common.Address, uint32, error)
- func (cache *CandidateCache) GetCandidates() ([]*Candidate, error)
- func (cache *CandidateCache) IsExist(address common.Address) bool
- func (cache *CandidateCache) Set(candidate *Candidate) error
- type CandidatePos
- type CandidateTrieDB
- func (db *CandidateTrieDB) Clone() *CandidateTrieDB
- func (db *CandidateTrieDB) Get(address common.Address) (*Candidate, error)
- func (db *CandidateTrieDB) GetAll() []*Candidate
- func (db *CandidateTrieDB) GetTrie() *PatriciaTrie
- func (db *CandidateTrieDB) Put(candidate *Candidate, dye uint32)
- func (db *CandidateTrieDB) Set(candidate *Candidate)
- func (db *CandidateTrieDB) SetTrie(trie *PatriciaTrie)
- type ChainDatabase
- func (database *ChainDatabase) AfterScan(flag uint32, key []byte, val []byte) error
- func (database *ChainDatabase) CandidatesRanking(hash common.Hash, voteLogs types.ChangeLogSlice)
- func (database *ChainDatabase) Close() error
- func (database *ChainDatabase) GetAccount(addr common.Address) (*types.AccountData, error)
- func (database *ChainDatabase) GetActDatabase(hash common.Hash) (*AccountTrieDB, error)
- func (database *ChainDatabase) GetAllCandidates() ([]common.Address, error)
- func (database *ChainDatabase) GetAssetCode(code common.Hash) (common.Address, error)
- func (database *ChainDatabase) GetAssetID(id common.Hash) (common.Address, error)
- func (database *ChainDatabase) GetBlockByHash(hash common.Hash) (*types.Block, error)
- func (database *ChainDatabase) GetBlockByHeight(height uint32) (*types.Block, error)
- func (database *ChainDatabase) GetCandidatesPage(index int, size int) ([]common.Address, uint32, error)
- func (database *ChainDatabase) GetCandidatesTop(hash common.Hash) []*Candidate
- func (database *ChainDatabase) GetConfirms(hash common.Hash) ([]types.SignData, error)
- func (database *ChainDatabase) GetContractCode(hash common.Hash) (types.Code, error)
- func (database *ChainDatabase) GetLastConfirm() *CBlock
- func (database *ChainDatabase) GetStableBlock() (*types.Block, error)
- func (database *ChainDatabase) GetTrieDatabase() *TrieDatabase
- func (database *ChainDatabase) GetUnConfirmByHeight(height uint32, leafBlockHash common.Hash) (*types.Block, error)
- func (database *ChainDatabase) IsExistByHash(hash common.Hash) (bool, error)
- func (database *ChainDatabase) IterateUnConfirms(fn func(*types.Block))
- func (database *ChainDatabase) LoadLatestBlock() (*types.Block, error)
- func (database *ChainDatabase) SerializeForks(currentHash common.Hash) string
- func (database *ChainDatabase) SetBlock(hash common.Hash, block *types.Block) error
- func (database *ChainDatabase) SetConfirms(hash common.Hash, pack []types.SignData) (*types.Block, error)
- func (database *ChainDatabase) SetContractCode(hash common.Hash, code types.Code) error
- func (database *ChainDatabase) SetStableBlock(hash common.Hash) ([]*types.Block, error)
- func (database *ChainDatabase) SizeOfValue(hash common.Hash) (int, error)
- type Commit
- type Database
- type DatabaseReader
- type FileQueue
- type Index
- type Inject
- type LmBuffer
- type LmDBBatch
- type MemDatabase
- func (db *MemDatabase) Close()
- func (db *MemDatabase) Delete(flag uint32, key []byte) error
- func (db *MemDatabase) Get(flag uint32, key []byte) ([]byte, error)
- func (db *MemDatabase) Has(flag uint32, key []byte) (bool, error)
- func (db *MemDatabase) Keys() [][]byte
- func (db *MemDatabase) Len() int
- func (db *MemDatabase) NewBatch() Batch
- func (db *MemDatabase) Put(flag uint32, key []byte, value []byte) error
- type NewBatch
- type Offset
- type OffsetItem
- type PatriciaNode
- type PatriciaTrie
- func (trie *PatriciaTrie) All() []types.NodeData
- func (trie *PatriciaTrie) Clone() *PatriciaTrie
- func (trie *PatriciaTrie) Collected(dye uint32) []types.NodeData
- func (trie *PatriciaTrie) DelDye(dye uint32)
- func (trie *PatriciaTrie) Find(key string) types.NodeData
- func (trie *PatriciaTrie) Insert(key string, data types.NodeData) error
- func (trie *PatriciaTrie) Put(key string, data types.NodeData, dye uint32)
- type Putter
- type Reader
- type RecordBody
- type RecordHead
- type RunContext
- func (context *RunContext) CandidateIsExist(address common.Address) bool
- func (context *RunContext) Flush() error
- func (context *RunContext) GetCandidatePage(index int, size int) ([]common.Address, uint32, error)
- func (context *RunContext) GetCandidates() ([]*Candidate, error)
- func (context *RunContext) Load() error
- func (context *RunContext) SetCandidate(candidate *Candidate) error
- func (context *RunContext) SetCandidates(candidates []*Candidate) error
- type SyncFileDB
- type TrieDatabase
- func (db *TrieDatabase) Commit(node common.Hash, report bool) error
- func (db *TrieDatabase) Dereference(child common.Hash, parent common.Hash)
- func (db *TrieDatabase) DiskDB() DatabaseReader
- func (db *TrieDatabase) DiskDB4Test() Database
- func (db *TrieDatabase) Insert(hash common.Hash, blob []byte)
- func (db *TrieDatabase) InsertPreimage(hash common.Hash, preimage []byte)
- func (db *TrieDatabase) Lock()
- func (db *TrieDatabase) Node(hash common.Hash) ([]byte, error)
- func (db *TrieDatabase) Nodes() []common.Hash
- func (db *TrieDatabase) Nodes4Test() map[common.Hash]*CachedNode
- func (db *TrieDatabase) Preimage(hash common.Hash) ([]byte, error)
- func (db *TrieDatabase) Reference(child common.Hash, parent common.Hash)
- func (db *TrieDatabase) Size() common.StorageSize
- func (db *TrieDatabase) UnLock()
- type VTransaction
- type VTransactionDetail
- type VoteTop
- func (top *VoteTop) Clear()
- func (top *VoteTop) Clone() *VoteTop
- func (top *VoteTop) Count() int
- func (top *VoteTop) GetTop() []*Candidate
- func (top *VoteTop) Max() *Candidate
- func (top *VoteTop) MergeCandidates(candidates []*Candidate)
- func (top *VoteTop) Min() *Candidate
- func (top *VoteTop) Rank(topSize int, candidates []*Candidate)
- func (top *VoteTop) RemoveCandidates(candidates []*Candidate)
- func (top *VoteTop) Reset(candidates []*Candidate)
- type WriteExtend
Examples ¶
Constants ¶
const IdealBatchSize = 100 * 1024
Code using batches should try to add this much data to the batch. The value was determined empirically.
Variables ¶
var ( ErrArgInvalid = errors.New("invalid argument") ErrExist = errors.New("item already exists") ErrNotExist = errors.New("item does not exist") ErrContractCodeNotExist = errors.New("contract code does not exist") ErrBlockNotExist = errors.New("block does not exist") ErrStableBlockNotExist = errors.New("stable block does not exist") ErrAccountNotExist = errors.New("account does not exist") ErrAncestorsNotExist = errors.New("the block's ancestors does not exist") ErrEOF = errors.New("file EOF") ErrRlpEncode = errors.New("rlp encode err") ErrOutOfMemory = errors.New("out of memory") ErrUnKnown = errors.New("") )
var MbTable = []uint16{}/* 256 elements not displayed */
var RecordHeadLength = binary.Size(RecordHead{})
Functions ¶
func Byte2Uint32 ¶
func FileUtilsAlign ¶ added in v1.2.0
func FileUtilsCreateFile ¶ added in v1.2.0
func FileUtilsEncode ¶ added in v1.2.0
func FileUtilsFlush ¶ added in v1.2.0
func FileUtilsIsExist ¶ added in v1.2.0
func FileUtilsRead ¶ added in v1.2.0
func FileUtilsRead(file *os.File, offset int64) (*RecordHead, *RecordBody, error)
func GetBucketIndex ¶
func GetItemIndex ¶
func SerializeForks ¶ added in v1.3.0
Example ¶
package main import ( "fmt" "github.com/LemoFoundationLtd/lemochain-core/chain/types" "github.com/LemoFoundationLtd/lemochain-core/common" ) // makeForkBlocks make blocks and setup the tree struct like this: // // ┌─2 // // 0───1─┼─3───6 // // ├─4─┬─7───9 // │ └─8 // └─5 func makeForkBlocks() []*CBlock { rawBlock0 := &types.Block{Header: &types.Header{Height: 99}} block0 := &CBlock{Block: rawBlock0} rawBlock1 := &types.Block{Header: &types.Header{Height: 100}} block1 := &CBlock{Block: rawBlock1} rawBlock2 := &types.Block{Header: &types.Header{Height: 101, Time: 1}} block2 := &CBlock{Block: rawBlock2} rawBlock3 := &types.Block{Header: &types.Header{Height: 101, Time: 2}} block3 := &CBlock{Block: rawBlock3} rawBlock4 := &types.Block{Header: &types.Header{Height: 101, Time: 3}} block4 := &CBlock{Block: rawBlock4} rawBlock5 := &types.Block{Header: &types.Header{Height: 101, Time: 4}} block5 := &CBlock{Block: rawBlock5} rawBlock6 := &types.Block{Header: &types.Header{Height: 102, Time: 5}} block6 := &CBlock{Block: rawBlock6} rawBlock7 := &types.Block{Header: &types.Header{Height: 102, Time: 6}} block7 := &CBlock{Block: rawBlock7} rawBlock8 := &types.Block{Header: &types.Header{Height: 102, Time: 7}} block8 := &CBlock{Block: rawBlock8} rawBlock9 := &types.Block{Header: &types.Header{Height: 103, Time: 8}} block9 := &CBlock{Block: rawBlock9} block1.BeChildOf(block0) block2.BeChildOf(block1) block3.BeChildOf(block1) block4.BeChildOf(block1) block5.BeChildOf(block1) block6.BeChildOf(block3) block7.BeChildOf(block4) block8.BeChildOf(block4) block9.BeChildOf(block7) return []*CBlock{block0, block1, block2, block3, block4, block5, block6, block7, block8, block9} } func main() { blocks := makeForkBlocks() blockMap := make(map[common.Hash]*CBlock, len(blocks)) for _, block := range blocks { blockMap[block.Block.Hash()] = block } fmt.Printf(SerializeForks(blockMap, blocks[9].Block.Hash())) }
Output: ─[ 99]5bd69f─[100]757227┬[101]1ba62c ├[101]1dc055 ├[101]1f5603┬[102]44ae7c │ └[102]6490a0─[103]db4799 <-Current └[101]29d8a5─[102]379da9
func UtilsGetAccount ¶ added in v1.2.0
func UtilsGetAssetCode ¶ added in v1.2.0
func UtilsGetAssetId ¶ added in v1.2.0
func UtilsGetBlockByHash ¶ added in v1.2.0
不会返回ErrNotExist
func UtilsGetBlockByHeight ¶ added in v1.2.0
func UtilsHashBlock ¶ added in v1.2.0
func UtilsSetAssetCode ¶ added in v1.2.0
Types ¶
type AccountTrieDB ¶ added in v1.1.1
type AccountTrieDB struct {
// contains filtered or unexported fields
}
AccountAPI
func NewAccountTrieDB ¶ added in v1.1.1
func NewAccountTrieDB(trie *PatriciaTrie, beansdb *BeansDB) *AccountTrieDB
func NewEmptyAccountTrieDB ¶ added in v1.1.1
func NewEmptyAccountTrieDB(beansdb *BeansDB) *AccountTrieDB
func (*AccountTrieDB) Clone ¶ added in v1.1.1
func (db *AccountTrieDB) Clone() *AccountTrieDB
func (*AccountTrieDB) Collect ¶ added in v1.1.1
func (db *AccountTrieDB) Collect(dye uint32) []*types.AccountData
func (*AccountTrieDB) Get ¶ added in v1.1.1
func (db *AccountTrieDB) Get(address common.Address) (*types.AccountData, error)
func (*AccountTrieDB) GetReader ¶ added in v1.1.1
func (db *AccountTrieDB) GetReader() *BeansDB
func (*AccountTrieDB) GetTrie ¶ added in v1.1.1
func (db *AccountTrieDB) GetTrie() *PatriciaTrie
func (*AccountTrieDB) Put ¶ added in v1.1.1
func (db *AccountTrieDB) Put(account *types.AccountData, dye uint32)
func (*AccountTrieDB) Set ¶ added in v1.1.1
func (db *AccountTrieDB) Set(account *types.AccountData)
func (*AccountTrieDB) SetReader ¶ added in v1.1.1
func (db *AccountTrieDB) SetReader(beansdb *BeansDB)
func (*AccountTrieDB) SetTrie ¶ added in v1.1.1
func (db *AccountTrieDB) SetTrie(trie *PatriciaTrie)
type Batch ¶
type Batch interface { Put(flg uint32, key, value []byte) error Commit() error Items() []*BatchItem ValueSize() int Reset() }
Batch is a write-only database that commits changes to its host database when Write is called. Batch cannot be used concurrently.
type BeansDB ¶ added in v1.1.0
type BeansDB struct { Home string LevelDB *leveldb.LevelDBDatabase Queue *FileQueue }
func NewBeansDB ¶ added in v1.1.0
func NewBeansDB(home string, levelDB *leveldb.LevelDBDatabase) *BeansDB
type BitCask ¶ added in v1.1.0
type BitCask struct { RW sync.RWMutex Home string BitCaskIndex int CurIndex int CurOffset int64 LevelDB *leveldb.LevelDBDatabase }
func NewBitCask ¶ added in v1.1.0
type BizDatabase ¶ added in v1.1.0
type BizDatabase struct { Reader Reader LevelDB *leveldb.LevelDBDatabase }
func NewBizDatabase ¶ added in v1.1.0
func NewBizDatabase(reader Reader, levelDB *leveldb.LevelDBDatabase) *BizDatabase
func (*BizDatabase) AfterCommit ¶ added in v1.1.0
func (db *BizDatabase) AfterCommit(flag uint32, key []byte, val []byte) error
func (*BizDatabase) GetTxByAddr ¶ added in v1.1.0
func (db *BizDatabase) GetTxByAddr(src common.Address, index int, size int) ([]*VTransaction, uint32, error)
func (*BizDatabase) GetTxByHash ¶ added in v1.1.0
func (db *BizDatabase) GetTxByHash(hash common.Hash) (*VTransactionDetail, error)
type CBlock ¶ added in v1.1.0
type CBlock struct { Block *types.Block AccountTrieDB *AccountTrieDB CandidateTrieDB *CandidateTrieDB Top *VoteTop Parent *CBlock Children []*CBlock }
func NewGenesisBlock ¶ added in v1.1.1
func NewNormalBlock ¶ added in v1.1.1
func NewNormalBlock(block *types.Block, accountTrieDB *AccountTrieDB, candidateTrieDB *CandidateTrieDB, top *VoteTop) *CBlock
func (*CBlock) CollectToParent ¶ added in v1.2.0
CollectToParent collect blocks from parent to parent, include itself and exclude the end block
func (*CBlock) IsSameBlock ¶ added in v1.2.0
func (*CBlock) Ranking ¶ added in v1.1.1
func (block *CBlock) Ranking(voteLogs types.ChangeLogSlice)
type CachedNode ¶
type CachedNode struct { Blob []byte // Cached data block of the trie node Parents int // Number of live nodes referencing this one Children map[common.Hash]int // Children referenced by this nodes }
CachedNode is all the information we know about a single cached node in the memory database write layer.
type Candidate ¶ added in v1.1.0
func (*Candidate) GetAddress ¶ added in v1.1.0
type CandidateCache ¶ added in v1.1.1
type CandidateCache struct { Candidates map[common.Address]CandidatePos ItemMaxSize int Cap int Cur int CandidateBuf []byte }
func NewCandidateCache ¶ added in v1.1.1
func NewCandidateCache() *CandidateCache
func (*CandidateCache) Decode ¶ added in v1.1.1
func (cache *CandidateCache) Decode(buf []byte, length int) error
func (*CandidateCache) Encode ¶ added in v1.1.1
func (cache *CandidateCache) Encode() ([]byte, int)
func (*CandidateCache) GetCandidatePage ¶ added in v1.1.1
func (*CandidateCache) GetCandidates ¶ added in v1.1.1
func (cache *CandidateCache) GetCandidates() ([]*Candidate, error)
func (*CandidateCache) IsExist ¶ added in v1.1.1
func (cache *CandidateCache) IsExist(address common.Address) bool
func (*CandidateCache) Set ¶ added in v1.1.1
func (cache *CandidateCache) Set(candidate *Candidate) error
type CandidatePos ¶ added in v1.1.1
type CandidateTrieDB ¶ added in v1.1.1
type CandidateTrieDB struct {
// contains filtered or unexported fields
}
CandidateAPI
func NewEmptyCandidateTrieDB ¶ added in v1.1.1
func NewEmptyCandidateTrieDB() *CandidateTrieDB
func (*CandidateTrieDB) Clone ¶ added in v1.1.1
func (db *CandidateTrieDB) Clone() *CandidateTrieDB
func (*CandidateTrieDB) Get ¶ added in v1.1.1
func (db *CandidateTrieDB) Get(address common.Address) (*Candidate, error)
func (*CandidateTrieDB) GetAll ¶ added in v1.1.1
func (db *CandidateTrieDB) GetAll() []*Candidate
func (*CandidateTrieDB) GetTrie ¶ added in v1.1.1
func (db *CandidateTrieDB) GetTrie() *PatriciaTrie
func (*CandidateTrieDB) Put ¶ added in v1.1.1
func (db *CandidateTrieDB) Put(candidate *Candidate, dye uint32)
func (*CandidateTrieDB) Set ¶ added in v1.1.1
func (db *CandidateTrieDB) Set(candidate *Candidate)
func (*CandidateTrieDB) SetTrie ¶ added in v1.1.1
func (db *CandidateTrieDB) SetTrie(trie *PatriciaTrie)
type ChainDatabase ¶ added in v1.1.0
type ChainDatabase struct { LastConfirm *CBlock // the newest confirm block, and the root of unconfirmed block tree UnConfirmBlocks map[common.Hash]*CBlock // unconfirmed block tree nodes Context *RunContext LevelDB *leveldb.LevelDBDatabase Beansdb *BeansDB BizDB *BizDatabase RW sync.RWMutex BizRW sync.RWMutex }
func NewChainDataBase ¶ added in v1.1.0
func NewChainDataBase(home string) *ChainDatabase
func (*ChainDatabase) AfterScan ¶ added in v1.1.0
func (database *ChainDatabase) AfterScan(flag uint32, key []byte, val []byte) error
func (*ChainDatabase) CandidatesRanking ¶ added in v1.1.0
func (database *ChainDatabase) CandidatesRanking(hash common.Hash, voteLogs types.ChangeLogSlice)
func (*ChainDatabase) Close ¶ added in v1.1.0
func (database *ChainDatabase) Close() error
func (*ChainDatabase) GetAccount ¶ added in v1.1.0
func (database *ChainDatabase) GetAccount(addr common.Address) (*types.AccountData, error)
GetAccount loads account from cache or db
func (*ChainDatabase) GetActDatabase ¶ added in v1.1.0
func (database *ChainDatabase) GetActDatabase(hash common.Hash) (*AccountTrieDB, error)
func (*ChainDatabase) GetAllCandidates ¶ added in v1.4.0
func (database *ChainDatabase) GetAllCandidates() ([]common.Address, error)
func (*ChainDatabase) GetAssetCode ¶ added in v1.2.0
func (*ChainDatabase) GetAssetID ¶ added in v1.2.0
func (*ChainDatabase) GetBlockByHash ¶ added in v1.1.0
func (*ChainDatabase) GetBlockByHeight ¶ added in v1.1.0
func (database *ChainDatabase) GetBlockByHeight(height uint32) (*types.Block, error)
func (*ChainDatabase) GetCandidatesPage ¶ added in v1.1.0
func (*ChainDatabase) GetCandidatesTop ¶ added in v1.1.0
func (database *ChainDatabase) GetCandidatesTop(hash common.Hash) []*Candidate
func (*ChainDatabase) GetConfirms ¶ added in v1.1.0
func (*ChainDatabase) GetContractCode ¶ added in v1.1.0
GetContractCode loads contract's code from db.
func (*ChainDatabase) GetLastConfirm ¶ added in v1.1.0
func (database *ChainDatabase) GetLastConfirm() *CBlock
func (*ChainDatabase) GetStableBlock ¶ added in v1.2.0
func (database *ChainDatabase) GetStableBlock() (*types.Block, error)
func (*ChainDatabase) GetTrieDatabase ¶ added in v1.1.0
func (database *ChainDatabase) GetTrieDatabase() *TrieDatabase
func (*ChainDatabase) GetUnConfirmByHeight ¶ added in v1.3.0
func (database *ChainDatabase) GetUnConfirmByHeight(height uint32, leafBlockHash common.Hash) (*types.Block, error)
GetUnConfirmByHeight find unconfirmed block by height. The leafBlockHash is a son block on the fork
func (*ChainDatabase) IsExistByHash ¶ added in v1.1.0
func (database *ChainDatabase) IsExistByHash(hash common.Hash) (bool, error)
func (*ChainDatabase) IterateUnConfirms ¶ added in v1.3.0
func (database *ChainDatabase) IterateUnConfirms(fn func(*types.Block))
func (*ChainDatabase) LoadLatestBlock ¶ added in v1.1.0
func (database *ChainDatabase) LoadLatestBlock() (*types.Block, error)
func (*ChainDatabase) SerializeForks ¶ added in v1.3.0
func (database *ChainDatabase) SerializeForks(currentHash common.Hash) string
func (*ChainDatabase) SetConfirms ¶ added in v1.1.0
func (database *ChainDatabase) SetConfirms(hash common.Hash, pack []types.SignData) (*types.Block, error)
SetConfirms 设置区块的确认信息
func (*ChainDatabase) SetContractCode ¶ added in v1.1.0
SetContractCode saves contract's code
func (*ChainDatabase) SetStableBlock ¶ added in v1.1.0
SetStableBlock set the state of the block to stable, then return pruned uncle blocks
func (*ChainDatabase) SizeOfValue ¶ added in v1.1.0
func (database *ChainDatabase) SizeOfValue(hash common.Hash) (int, error)
type Database ¶
type Database interface { NewBatch Put(flg uint32, key, value []byte) error Get(flg uint32, key []byte) ([]byte, error) Has(flg uint32, key []byte) (bool, error) Delete(flg uint32, key []byte) error Close() }
Database wraps all database operations. All methods are safe for concurrent use.
type DatabaseReader ¶
type DatabaseReader interface { // Get retrieves the value associated with key form the database. Get(flg uint32, key []byte) (value []byte, err error) // Has retrieves whether a key is present in the database. Has(flg uint32, key []byte) (bool, error) }
DatabaseReader wraps the Get and Has method of a backing store for the trie.
type FileQueue ¶ added in v1.2.0
type FileQueue struct { Home string Offset int64 IndexRW sync.RWMutex Index map[string]*item LevelDB *leveldb.LevelDBDatabase SyncFileDB *SyncFileDB DoneChan chan *Inject ErrChan chan *Inject Quit chan struct{} }
func NewFileQueue ¶ added in v1.2.0
func NewFileQueue(home string, levelDB *leveldb.LevelDBDatabase, extend WriteExtend) *FileQueue
type LmBuffer ¶
type LmBuffer struct {
// contains filtered or unexported fields
}
func NewLmBuffer ¶
type LmDBBatch ¶ added in v1.1.0
type LmDBBatch struct {
// contains filtered or unexported fields
}
type MemDatabase ¶
type MemDatabase struct {
// contains filtered or unexported fields
}
* This is a test memory database. Do not use for any production it does not get persisted
func NewMemDatabase ¶
func NewMemDatabase() (*MemDatabase, error)
func NewMemDatabaseWithCap ¶
func NewMemDatabaseWithCap(size int) (*MemDatabase, error)
func (*MemDatabase) Close ¶
func (db *MemDatabase) Close()
func (*MemDatabase) Keys ¶
func (db *MemDatabase) Keys() [][]byte
func (*MemDatabase) Len ¶
func (db *MemDatabase) Len() int
func (*MemDatabase) NewBatch ¶
func (db *MemDatabase) NewBatch() Batch
type OffsetItem ¶ added in v1.4.0
type PatriciaNode ¶ added in v1.1.0
type PatriciaNode struct {
// contains filtered or unexported fields
}
func (*PatriciaNode) Clone ¶ added in v1.1.0
func (node *PatriciaNode) Clone() *PatriciaNode
type PatriciaTrie ¶ added in v1.1.0
type PatriciaTrie struct {
// contains filtered or unexported fields
}
func NewActDatabase ¶ added in v1.1.0
func NewActDatabase(root *PatriciaTrie) *PatriciaTrie
func NewEmptyDatabase ¶ added in v1.1.0
func NewEmptyDatabase() *PatriciaTrie
func (*PatriciaTrie) All ¶ added in v1.1.1
func (trie *PatriciaTrie) All() []types.NodeData
func (*PatriciaTrie) Clone ¶ added in v1.1.0
func (trie *PatriciaTrie) Clone() *PatriciaTrie
func (*PatriciaTrie) Collected ¶ added in v1.1.0
func (trie *PatriciaTrie) Collected(dye uint32) []types.NodeData
func (*PatriciaTrie) DelDye ¶ added in v1.1.0
func (trie *PatriciaTrie) DelDye(dye uint32)
func (*PatriciaTrie) Find ¶ added in v1.1.0
func (trie *PatriciaTrie) Find(key string) types.NodeData
type Putter ¶
Putter wraps the database write operation supported by both batches and regular databases.
type RecordBody ¶ added in v1.2.0
type RecordHead ¶ added in v1.2.0
type RunContext ¶ added in v1.1.0
type RunContext struct { Path string Candidates *CandidateCache }
func NewRunContext ¶ added in v1.1.0
func NewRunContext(path string) *RunContext
func (*RunContext) CandidateIsExist ¶ added in v1.1.0
func (context *RunContext) CandidateIsExist(address common.Address) bool
func (*RunContext) Flush ¶ added in v1.1.0
func (context *RunContext) Flush() error
func (*RunContext) GetCandidatePage ¶ added in v1.1.0
func (*RunContext) GetCandidates ¶ added in v1.1.1
func (context *RunContext) GetCandidates() ([]*Candidate, error)
func (*RunContext) Load ¶ added in v1.1.0
func (context *RunContext) Load() error
func (*RunContext) SetCandidate ¶ added in v1.1.0
func (context *RunContext) SetCandidate(candidate *Candidate) error
func (*RunContext) SetCandidates ¶ added in v1.1.1
func (context *RunContext) SetCandidates(candidates []*Candidate) error
type SyncFileDB ¶ added in v1.2.0
type SyncFileDB struct { Home string Height uint BitCasks []*BitCask LevelDB *leveldb.LevelDBDatabase Extend WriteExtend DoneChan chan *Inject ErrChan chan *Inject WriteChan chan *Inject Quit chan struct{} }
func NewSyncFileDB ¶ added in v1.2.0
func NewSyncFileDB(home string, levelDB *leveldb.LevelDBDatabase, doneChan chan *Inject, errChan chan *Inject, quit chan struct{}, extend WriteExtend) *SyncFileDB
func (*SyncFileDB) Get ¶ added in v1.2.0
func (db *SyncFileDB) Get(flag uint32, key []byte) ([]byte, error)
func (*SyncFileDB) Open ¶ added in v1.2.0
func (db *SyncFileDB) Open()
type TrieDatabase ¶
type TrieDatabase struct {
// contains filtered or unexported fields
}
Database is an intermediate write layer between the trie data structures and the disk database. The aim is to accumulate trie writes in-memory and only periodically flush a couple tries to disk, garbage collecting the remainder.
func NewTrieDatabase ¶
func NewTrieDatabase(diskdb Database) *TrieDatabase
NewTrieDatabase creates a new trie database to store ephemeral trie content before its written out to disk or garbage collected.
func (*TrieDatabase) Commit ¶
func (db *TrieDatabase) Commit(node common.Hash, report bool) error
Commit iterates over all the Children of a particular node, writes them out to disk, forcefully tearing down all references in both directions.
As a side effect, all pre-images accumulated up to this point are also written.
func (*TrieDatabase) Dereference ¶
func (db *TrieDatabase) Dereference(child common.Hash, parent common.Hash)
Dereference removes an existing reference from a parent node to a child node.
func (*TrieDatabase) DiskDB ¶
func (db *TrieDatabase) DiskDB() DatabaseReader
DiskDB retrieves the persistent storage backing the trie database.
func (*TrieDatabase) DiskDB4Test ¶
func (db *TrieDatabase) DiskDB4Test() Database
func (*TrieDatabase) Insert ¶
func (db *TrieDatabase) Insert(hash common.Hash, blob []byte)
Insert writes a new trie node to the memory database if it's yet unknown. The method will make a copy of the slice.
func (*TrieDatabase) InsertPreimage ¶
func (db *TrieDatabase) InsertPreimage(hash common.Hash, preimage []byte)
insertPreimage writes a new trie node pre-image to the memory database if it's yet unknown. The method will make a copy of the slice.
Note, this method assumes that the database's lock is held!
func (*TrieDatabase) Lock ¶
func (db *TrieDatabase) Lock()
func (*TrieDatabase) Node ¶
func (db *TrieDatabase) Node(hash common.Hash) ([]byte, error)
Node retrieves a cached trie node from memory. If it cannot be found cached, the method queries the persistent database for the content.
func (*TrieDatabase) Nodes ¶
func (db *TrieDatabase) Nodes() []common.Hash
Nodes retrieves the hashes of all the nodes cached within the memory database. This method is extremely expensive and should only be used to validate internal states in test code.
func (*TrieDatabase) Nodes4Test ¶
func (db *TrieDatabase) Nodes4Test() map[common.Hash]*CachedNode
func (*TrieDatabase) Preimage ¶
func (db *TrieDatabase) Preimage(hash common.Hash) ([]byte, error)
preimage retrieves a cached trie node pre-image from memory. If it cannot be found cached, the method queries the persistent database for the content.
func (*TrieDatabase) Reference ¶
func (db *TrieDatabase) Reference(child common.Hash, parent common.Hash)
Reference adds a new reference from a parent node to a child node.
func (*TrieDatabase) Size ¶
func (db *TrieDatabase) Size() common.StorageSize
Size returns the current storage size of the memory cache in front of the persistent database layer.
func (*TrieDatabase) UnLock ¶
func (db *TrieDatabase) UnLock()
type VTransaction ¶ added in v1.1.0
type VTransaction struct { Tx *types.Transaction `json:"tx" gencodec:"required"` PHash common.Hash `json:"pHash" gencodec:"required"` PackageTime uint32 `json:"time" gencodec:"required"` AssetCode common.Hash `json:"assetCode"` AssetId common.Hash `json:"assetId"` }
func (VTransaction) MarshalJSON ¶ added in v1.1.0
func (v VTransaction) MarshalJSON() ([]byte, error)
MarshalJSON marshals as JSON.
func (*VTransaction) UnmarshalJSON ¶ added in v1.1.0
func (v *VTransaction) UnmarshalJSON(input []byte) error
UnmarshalJSON unmarshals from JSON.
type VTransactionDetail ¶ added in v1.1.0
type VTransactionDetail struct { BlockHash common.Hash `json:"blockHash" gencodec:"required"` PHash common.Hash `json:"pHash" gencodec:"required"` Height uint32 `json:"height" gencodec:"required"` Tx *types.Transaction `json:"tx" gencodec:"required"` PackageTime uint32 `json:"time" gencodec:"required"` AssetCode common.Hash `json:"assetCode"` AssetId common.Hash `json:"assetId"` }
func (VTransactionDetail) MarshalJSON ¶ added in v1.1.0
func (v VTransactionDetail) MarshalJSON() ([]byte, error)
MarshalJSON marshals as JSON.
func (*VTransactionDetail) UnmarshalJSON ¶ added in v1.1.0
func (v *VTransactionDetail) UnmarshalJSON(input []byte) error
UnmarshalJSON unmarshals from JSON.
type VoteTop ¶ added in v1.1.0
type VoteTop struct {
Top []*Candidate
}
func NewEmptyVoteTop ¶ added in v1.1.1
func NewEmptyVoteTop() *VoteTop
func NewVoteTop ¶ added in v1.1.0
func (*VoteTop) MergeCandidates ¶ added in v1.4.0
MergeCandidates merge candidates together
func (*VoteTop) RemoveCandidates ¶ added in v1.4.0
MergeCandidates merge candidates together