blockchain

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2019 License: Apache-2.0, Apache-2.0 Imports: 13 Imported by: 0

README

blockchain

A BlockChain implementation.

Build Status codecov

Getting started

Running it then should be as simple as:

$ make all
Testing
$ make test

Documentation

Index

Constants

View Source
const (
	// DB plugin
	PLUGIN_LEVELDB = "leveldb"
	// memory plugin
	PLUGIN_MEMDB = "memorydb"
)

blockchain module constant value.

Variables

This section is empty.

Functions

func InitBlockChain

func InitBlockChain(chainConfig config.BlockChainConfig, eventCenter types.EventCenter) error

InitBlockChain init blockchain module config.

Types

type BlockChain

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

BlockChain is the chain manager.

The BlockChain is used to write block to chain, get block from chain, and get the block state.

func NewBlockChainByBlockHash

func NewBlockChainByBlockHash(blockHash types.Hash) (*BlockChain, error)

NewLatestStateBlockChain create a blockchain with specified block hash.

func NewBlockChainByHash

func NewBlockChainByHash(root types.Hash) (*BlockChain, error)

NewBlockChain returns a blockchain instance with specified hash.

func NewLatestStateBlockChain

func NewLatestStateBlockChain() (*BlockChain, error)

NewLatestStateBlockChain create a blockchain with latest state hash.

func (*BlockChain) AddBalance

func (blockChain *BlockChain) AddBalance(address types.Address, value *big.Int)

func (*BlockChain) AddLog

func (blockChain *BlockChain) AddLog(log *types.Log)

AddLog add contract execute log.

func (*BlockChain) AddPreimage

func (blockChain *BlockChain) AddPreimage(hash types.Hash, preimage []byte)

func (*BlockChain) AddRefund

func (blockChain *BlockChain) AddRefund(value uint64)

func (*BlockChain) Commit added in v1.0.0

func (blockChain *BlockChain) Commit(deleteEmptyObjects bool) (root types.Hash, err error)

Commit writes the state to the underlying in-memory trie database.

func (*BlockChain) CreateAccount

func (blockChain *BlockChain) CreateAccount(address types.Address)

CreateAccount create an account

func (*BlockChain) Empty

func (blockChain *BlockChain) Empty(address types.Address) bool

Empty returns whether the given account is empty. Empty is defined according to EIP161 (balance = nonce = code = 0).

func (*BlockChain) EventWriteBlockWithReceipts

func (blockChain *BlockChain) EventWriteBlockWithReceipts(block *types.Block, receipts []*types.Receipt, emitCommitEvent bool) error

WriteBlock write the block and relative receipts to database. return error if write failed.

func (*BlockChain) Exist

func (blockChain *BlockChain) Exist(address types.Address) bool

Exist reports whether the given account exists in state. Notably this should also return true for suicided accounts.

func (*BlockChain) Finalise

func (blockChain *BlockChain) Finalise(deleteEmptyObjects bool)

Finalise finalises the state by removing the self destructed objects and clears the journal as well as the refunds.

func (*BlockChain) ForEachStorage

func (blockChain *BlockChain) ForEachStorage(addr types.Address, cb func(key, value types.Hash) bool)

func (*BlockChain) Get added in v1.0.0

func (blockChain *BlockChain) Get(key []byte) ([]byte, error)

Get get a record by key

func (*BlockChain) GetBalance

func (blockChain *BlockChain) GetBalance(address types.Address) *big.Int

func (*BlockChain) GetBlockByHash

func (blockChain *BlockChain) GetBlockByHash(hash types.Hash) (*types.Block, error)

GetBlockByHash retrieves a block from the local chain.

func (*BlockChain) GetBlockByHeight

func (blockChain *BlockChain) GetBlockByHeight(height uint64) (*types.Block, error)

GetBlockByHeight get block by height.

func (*BlockChain) GetCode

func (blockChain *BlockChain) GetCode(address types.Address) []byte

func (*BlockChain) GetCodeHash

func (blockChain *BlockChain) GetCodeHash(address types.Address) types.Hash

func (*BlockChain) GetCodeSize

func (blockChain *BlockChain) GetCodeSize(address types.Address) int

func (*BlockChain) GetCommittedState added in v1.0.0

func (blockChain *BlockChain) GetCommittedState(addr types.Address, hash types.Hash) types.Hash

GetCommittedState retrieves a value from the given account's committed storage trie.

func (*BlockChain) GetCurrentBlock

func (blockChain *BlockChain) GetCurrentBlock() *types.Block

GetCurrentBlock get current block.

func (*BlockChain) GetCurrentBlockHeight

func (blockChain *BlockChain) GetCurrentBlockHeight() uint64

GetCurrentBlockHeight get current block height.

func (*BlockChain) GetLogs added in v1.0.0

func (blockChain *BlockChain) GetLogs(txHash types.Hash) []*types.Log

GetLogs get transaction's execution log

func (*BlockChain) GetNonce

func (blockChain *BlockChain) GetNonce(address types.Address) uint64

GetNonce get account's nounce

func (*BlockChain) GetReceiptByBlockHash added in v1.0.0

func (blockChain *BlockChain) GetReceiptByBlockHash(blockHash types.Hash) []*types.Receipt

GetReceiptByHash get receipt by relative block's hash

func (*BlockChain) GetReceiptByTxHash

func (blockChain *BlockChain) GetReceiptByTxHash(txHash types.Hash) (*types.Receipt, types.Hash, uint64, uint64, error)

GetReceiptByHash get receipt by relative tx's hash

func (*BlockChain) GetRefund

func (blockChain *BlockChain) GetRefund() uint64

func (*BlockChain) GetState

func (blockChain *BlockChain) GetState(address types.Address, bhash types.Hash) types.Hash

func (*BlockChain) GetTransactionByHash

func (blockChain *BlockChain) GetTransactionByHash(hash types.Hash) (*types.Transaction, types.Hash, uint64, uint64, error)

GetTransactionByHash get transaction by hash

func (*BlockChain) HasSuicided

func (blockChain *BlockChain) HasSuicided(address types.Address) bool

func (*BlockChain) IntermediateRoot

func (blockChain *BlockChain) IntermediateRoot(deleteEmptyObjects bool) types.Hash

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 (*BlockChain) Prepare

func (blockChain *BlockChain) Prepare(thash, bhash types.Hash, ti int)

Prepare sets the current transaction hash and index and block hash which is used when the EVM emits new state logs.

func (*BlockChain) Put added in v1.0.0

func (blockChain *BlockChain) Put(key []byte, value []byte) error

Put add a record to database

func (*BlockChain) Reset

func (blockChain *BlockChain) Reset(root types.Hash) error

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 (*BlockChain) RevertToSnapshot

func (blockChain *BlockChain) RevertToSnapshot(revid int)

func (*BlockChain) SetBalance

func (blockChain *BlockChain) SetBalance(addr types.Address, amount *big.Int)

func (*BlockChain) SetCode

func (blockChain *BlockChain) SetCode(address types.Address, code []byte)

func (*BlockChain) SetNonce

func (blockChain *BlockChain) SetNonce(address types.Address, value uint64)

func (*BlockChain) SetState

func (blockChain *BlockChain) SetState(address types.Address, key, value types.Hash)

func (*BlockChain) Snapshot

func (blockChain *BlockChain) Snapshot() int

func (*BlockChain) SubBalance

func (blockChain *BlockChain) SubBalance(address types.Address, value *big.Int)

func (*BlockChain) SubRefund added in v1.0.0

func (blockChain *BlockChain) SubRefund(gas uint64)

SubRefund removes gas from the refund counter. This method will panic if the refund counter goes below zero

func (*BlockChain) Suicide

func (blockChain *BlockChain) Suicide(address types.Address) bool

func (*BlockChain) WriteBlock

func (blockChain *BlockChain) WriteBlock(block *types.Block) error

WriteBlockWithState writes the block to the database.

func (*BlockChain) WriteBlockWithReceipts

func (blockChain *BlockChain) WriteBlockWithReceipts(block *types.Block, receipts []*types.Receipt) error

WriteBlock write the block and relative receipts to database. return error if write failed.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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