Documentation ¶
Index ¶
- Constants
- Variables
- func AddrAllTokenUtxoKey(addr string, tid types.TokenID) []byte
- func AddrAllUtxoKey(addr string) []byte
- func AddrTokenUtxoKey(addr string, tid types.TokenID, op types.OutPoint) []byte
- func AddrUtxoKey(addr string, op types.OutPoint) []byte
- func ApplyMessage(evm *vm.EVM, msg types.Message) ([]byte, uint64, uint64, bool, *types.Transaction, error)
- func ApplyTransaction(tx *types.VMTransaction, header *types.BlockHeader, bc *BlockChain, ...) (*types.Receipt, uint64, uint64, []*types.Transaction, error)
- func BlockHashKey(height uint32) []byte
- func BlockKey(h *crypto.HashType) []byte
- func CalcBlockSubsidy(height uint32) uint64
- func CalcTxsHash(txs []*types.Transaction) *crypto.HashType
- func CanTransfer(db vm.StateDB, addr types.AddressHash, amount *big.Int) bool
- func CandidatesKey(h *crypto.HashType) []byte
- func CreateCoinbaseTx(addr []byte, blockHeight uint32) (*types.Transaction, error)
- func DeserializeUtxoWrap(serialized []byte) (*types.UtxoWrap, error)
- func FetchOutPointOwner(op *types.OutPoint, utxoSet *UtxoSet) (types.Address, error)
- func GetHashFn(bc *BlockChain) func(n uint64) *crypto.HashType
- func IntrinsicGas(data []byte, contractCreation bool) (uint64, error)
- func IsCoinBase(tx *types.Transaction) bool
- func IsTxFinalized(tx *types.Transaction, blockHeight uint32, blockTime int64) bool
- func LoadBlockByHash(hash crypto.HashType, reader storage.Reader) (*types.Block, error)
- func MakeRollbackContractUtxos(block *types.Block, stateDB *state.StateDB, db storage.Table) (types.UtxoMap, error)
- func MarshalMissData(height, miss uint32, ts int64) (data []byte, err error)
- func MarshalTxIndex(height, index uint32) (data []byte, err error)
- func NewEVMContext(msg types.Message, header *types.BlockHeader, bc *BlockChain) vm.Context
- func ReceiptKey(h *crypto.HashType) []byte
- func SecBloomBitSetKey(section uint32, bit uint) []byte
- func SerializeUtxoWrap(utxoWrap *types.UtxoWrap) ([]byte, error)
- func SplitAddrKey(hash []byte) []byte
- func SplitTxHashKey(h *crypto.HashType) []byte
- func TokenPreAllocation() ([]*types.Transaction, error)
- func Transfer(db vm.StateDB, sender, recipient types.AddressHash, amount *big.Int, ...)
- func TxIndexKey(h *crypto.HashType) []byte
- func TxKey(h *crypto.HashType) []byte
- func UnmarshalMissData(data []byte) (height uint32, miss uint32, ts int64, err error)
- func UnmarshalTxIndex(data []byte) (height uint32, index uint32, err error)
- func ValidateTransactionPreliminary(tx *types.Transaction) error
- func ValidateTxInputs(utxoSet *UtxoSet, tx *types.Transaction, txHeight uint32) (uint64, error)
- func VerifyBlockTimeOut(block *types.Block) error
- type BalanceChangeMap
- type BlockChain
- func (chain *BlockChain) BroadcastOrRelayBlock(block *types.Block, transferMode core.TransferMode)
- func (chain *BlockChain) Bus() eventbus.Bus
- func (chain *BlockChain) CalcRootHashForNBlocks(hash crypto.HashType, num uint32) (*crypto.HashType, error)
- func (chain *BlockChain) ChangeNewTail(tail *types.Block)
- func (chain *BlockChain) Consensus() Consensus
- func (chain *BlockChain) DB() storage.Table
- func (chain *BlockChain) DelSplitTxs(splitTxs map[crypto.HashType]*types.Transaction, db storage.Table) error
- func (chain *BlockChain) DelTxIndex(block *types.Block, splitTxs map[crypto.HashType]*types.Transaction, ...) error
- func (chain *BlockChain) DeleteSplitAddrIndex(block *types.Block, db storage.Table) error
- func (chain *BlockChain) EternalBlock() *types.Block
- func (chain *BlockChain) ExtractVMTransactions(tx *types.Transaction, ownerTxs ...*types.Transaction) (*types.VMTransaction, error)
- func (chain *BlockChain) FetchNBlockAfterSpecificHash(hash crypto.HashType, num uint32) ([]*types.Block, error)
- func (chain *BlockChain) FilterLogs(logs []*types.Log, topicslist [][][]byte) ([]*types.Log, error)
- func (chain *BlockChain) Genesis() *types.Block
- func (chain *BlockChain) GetBlockHash(blockHeight uint32) (*crypto.HashType, error)
- func (chain *BlockChain) GetBlockHeight() uint32
- func (chain *BlockChain) GetBlockLogs(hash *crypto.HashType) ([]*types.Log, error)
- func (chain *BlockChain) GetDataFromDB(key []byte) ([]byte, error)
- func (chain *BlockChain) GetEvmByHeight(msg types.Message, height uint32) (*vm.EVM, func() error, error)
- func (chain *BlockChain) GetLogs(from, to uint32, topicslist [][][]byte) ([]*types.Log, error)
- func (chain *BlockChain) GetParentBlock(block *types.Block) *types.Block
- func (chain *BlockChain) GetTxReceipt(txHash *crypto.HashType) (*types.Receipt, error)
- func (chain *BlockChain) IsBusy() bool
- func (chain *BlockChain) IsCoinBase(tx *types.Transaction) bool
- func (chain *BlockChain) LoadBlockByHeight(height uint32) (*types.Block, error)
- func (chain *BlockChain) LoadBlockInfoByTxHash(hash crypto.HashType) (*types.Block, *types.Transaction, error)
- func (chain *BlockChain) LoadEternalBlock() (*types.Block, error)
- func (chain *BlockChain) LocateForkPointAndFetchHeaders(hashes []*crypto.HashType) ([]*crypto.HashType, error)
- func (chain *BlockChain) Proc() goprocess.Process
- func (chain *BlockChain) ProcessBlock(block *types.Block, transferMode core.TransferMode, messageFrom peer.ID) error
- func (chain *BlockChain) ReadBlockFromDB(hash *crypto.HashType) (*types.Block, int, error)
- func (chain *BlockChain) ReceiptsCache() map[uint32]types.Receipts
- func (chain *BlockChain) RemoveBlock(block *types.Block)
- func (chain *BlockChain) Run() error
- func (chain *BlockChain) SetEternal(block *types.Block) error
- func (chain *BlockChain) SetTailState(root, utxoRoot *crypto.HashType) error
- func (chain *BlockChain) Setup(consensus Consensus, syncManager SyncManager)
- func (chain *BlockChain) SplitBlockOutputs(block *types.Block) map[crypto.HashType]*types.Transaction
- func (chain *BlockChain) StateProcessor() *StateProcessor
- func (chain *BlockChain) Stop()
- func (chain *BlockChain) StoreBlock(block *types.Block) error
- func (chain *BlockChain) StoreBlockWithIndex(block *types.Block, db storage.Table) error
- func (chain *BlockChain) StoreEternalBlock(block *types.Block) error
- func (chain *BlockChain) StoreReceipts(hash *crypto.HashType, receipts types.Receipts, db storage.Table) error
- func (chain *BlockChain) StoreSplitTxs(splitTxs map[crypto.HashType]*types.Transaction, db storage.Table) error
- func (chain *BlockChain) StoreTailBlock(block *types.Block, db storage.Table) error
- func (chain *BlockChain) TailBlock() *types.Block
- func (chain *BlockChain) TailState() *state.StateDB
- func (chain *BlockChain) UpdateContractUtxoState(statedb *state.StateDB, utxoSet *UtxoSet) error
- func (chain *BlockChain) UpdateNormalTxBalanceState(block *types.Block, utxoset *UtxoSet, stateDB *state.StateDB)
- func (chain *BlockChain) UtxoSetCache() map[uint32]*UtxoSet
- func (chain *BlockChain) ValidateExecuteResult(block *types.Block, utxoTxs []*types.Transaction, ...) error
- func (chain *BlockChain) WriteSplitAddrIndex(block *types.Block, db storage.Table) error
- func (chain *BlockChain) WriteTxIndex(block *types.Block, splitTxs map[crypto.HashType]*types.Transaction, ...) error
- type Consensus
- type DummyDpos
- func (dpos *DummyDpos) Finalize(*types.Block) error
- func (dpos *DummyDpos) Process(*types.Block, interface{}) error
- func (dpos *DummyDpos) RecoverMint()
- func (dpos *DummyDpos) Run() error
- func (dpos *DummyDpos) Stop()
- func (dpos *DummyDpos) StopMint()
- func (dpos *DummyDpos) Verify(*types.Block) error
- func (dpos *DummyDpos) VerifyTx(*types.Transaction) error
- type DummySyncManager
- type LockTime
- type ScriptItem
- type SectionManager
- type StateProcessor
- type StateTransition
- type SyncManager
- type TransferInfo
- type UpdateMsg
- type UtxoSet
- func (u *UtxoSet) AddUtxo(tx *types.Transaction, txOutIdx uint32, blockHeight uint32) error
- func (u *UtxoSet) All() types.UtxoMap
- func (u *UtxoSet) ApplyBlock(block *types.Block) error
- func (u *UtxoSet) ApplyInternalTxs(block *types.Block) error
- func (u *UtxoSet) FindUtxo(outPoint types.OutPoint) *types.UtxoWrap
- func (u *UtxoSet) GetUtxos() types.UtxoMap
- func (u *UtxoSet) ImportUtxoMap(m types.UtxoMap, overwrite bool)
- func (u *UtxoSet) LoadBlockAllUtxos(block *types.Block, needContract bool, db storage.Table) error
- func (u *UtxoSet) LoadBlockUtxos(block *types.Block, needContract bool, db storage.Table) error
- func (u *UtxoSet) LoadTxUtxos(tx *types.Transaction, db storage.Table) error
- func (u *UtxoSet) RevertBlock(block *types.Block, chain *BlockChain) error
- func (u *UtxoSet) RevertTx(tx *types.Transaction, chain *BlockChain) error
- func (u *UtxoSet) SpendUtxo(outPoint types.OutPoint)
- func (u *UtxoSet) TxInputAmount(tx *types.Transaction) uint64
- func (u *UtxoSet) WriteUtxoSetToDB(db storage.Table) error
Constants ¶
const ( BlockMsgChBufferSize = 1024 EternalBlockMsgChBufferSize = 65536 MaxTimeOffsetSeconds = 2 * 60 * 60 MaxBlockSize = 32000000 CoinbaseLib = 100 PeriodDuration = 21 * 5 * 10000 MaxBlocksPerSync = 1024 Threshold = 32 )
const defines constants
const ( // BlockTableName is the table name of db to store block chain data BlockTableName = "core" // WalletTableName is the table name of db to store wallet data WalletTableName = "wl" // SectionTableName is the table name of db to store section data SectionTableName = "sec" // Tail is the db key name of tail block Tail = "/tail" // Genesis is the db key name of genesis block Genesis = "/genesis" // Eternal is the db key name of eternal block Eternal = "/eternal" // Period is the db key name of current period Period = "/period/current" // MissCount is the db key name of minuer's block miss rate data // value: 4 bytes height + 4 bytes miss count + 10 bytes ts MissCount = "/missrate" // BlockPrefix is the key prefix of database key to store block content // /bk/{hex encoded block hash} // e.g. // key: /bk/005973c44c4879b137c3723c96d2e341eeaf83fe58845b2975556c9f3bd640bb // value: block binary BlockPrefix = "/bk" // TxPrefix is the key prefix of database key to store tx content TxPrefix = "/tx" // SecBloomBitSetPrefix is the key prefix of database key to store bloom bit set of section SecBloomBitSetPrefix = "/sec/bf" // SplitTxHashPrefix is the key prefix of database key to store split tx mapping SplitTxHashPrefix = "/split" // BlockHashPrefix is the key prefix of database key to store block hash of specified height // /bh/{hex encoded height} //e.g. // key: /bh/3e2d // value: block hash binary BlockHashPrefix = "/bh" // ReceiptPrefix is the key prefix of database key to store block receipts // of specified block hash // /br/{hex encoded block hash} // e.g. // key: /bk/005973c44c4879b137c3723c96d2e341eeaf83fe58845b2975556c9f3bd640bb // value: receipts binary ReceiptPrefix = "/rc" // TxIndexPrefix is the key prefix of database key to store tx index // /ti/{hex encoded tx hash} // e.g. // key: /ti/1113b8bdad74cdc045e64e09b3e2f0502d1b7f9bd8123b28239a3360bd3a8757 // value: 4 bytes height + 4 bytes index in txs TxIndexPrefix = "/ti" // UtxoPrefix is the key prefix of database key to store utxo content // /ut/{hex encoded tx hash}/{vout index} // e.g. // key: /ut/1113b8bdad74cdc045e64e09b3e2f0502d1b7f9bd8123b28239a3360bd3a8757/2 // value: utxo wrapper UtxoPrefix = "/ut" // CandidatesPrefix is the key prefix of database key to store candidates CandidatesPrefix = "/candidates" // FilterPrefix is the key prefix of block bloom filter to store a filter bytes // /bf/{hex encoded block hash} // e.g. // key: /bf/1113b8bdad74cdc045e64e09b3e2f0502d1b7f9bd8123b28239a3360bd3a8757 // value: crypto hash FilterPrefix = "/bf" // SplitAddressPrefix is the key prefix of split address SplitAddressPrefix = "/sap" // AddressUtxoPrefix is the key prefix of database key to store address related utxo AddressUtxoPrefix = "/aut" // AddressTokenUtxoPrefix is the key prefix of database key to store address related token utxo AddressTokenUtxoPrefix = "/atut" )
const ( TxGas uint64 = 2100 TxGasContractCreation uint64 = 5300 TxDataZeroGas uint64 = 1 TxDataNonZeroGas uint64 = 6 )
define const
const (
// SectionBloomLength represents the number of blooms used in a new section.
SectionBloomLength = 65536 >> 3
)
const (
VoutLimit = 1000
)
define const.
Variables ¶
var ( // TotalSupply is the total supply of box: 3 billion TotalSupply = (uint64)(3e9 * core.DuPerBox) // CoinbaseMaturity coinbase only spendable after this many blocks CoinbaseMaturity = (uint32)(0) // BaseSubsidy is the starting subsidy amount for mined blocks. // This value is halved every SubsidyReductionInterval blocks. BaseSubsidy = (uint64)(50 * core.DuPerBox) )
var EternalKey = []byte(Eternal)
EternalKey is the db key to store eternal block content
var GenesisBlock = types.Block{ Header: &types.BlockHeader{ Version: 1, PrevBlockHash: crypto.HashType{}, TimeStamp: time.Date(2018, 1, 31, 0, 0, 0, 0, time.UTC).Unix(), Height: 0, }, }
GenesisBlock represents genesis block.
var GenesisKey = []byte(Genesis)
GenesisKey is the db key to store genesis block content
var GenesisPeriod = []map[string]string{
{
"addr": "b1ndoQmEd83y4Fza5PzbUQDYpT3mV772J5o",
"peerID": "12D3KooWFQ2naj8XZUVyGhFzBTEMrMc6emiCEDKLjaJMsK7p8Cza",
},
{
"addr": "b1b8bzyci5VYUJVKRU2HRMMQiUXnoULkKAJ",
"peerID": "12D3KooWKPRAK7vBBrVv9szEin55kBnJEEuHG4gDTQEM72ByZDpA",
},
{
"addr": "b1jh8DSdB6kB7N7RanrudV1hzzMCCcoX6L7",
"peerID": "12D3KooWSdXLNeoRQQ2a7yiS6xLpTn3LdCr8B8fqPz94Bbi7itsi",
},
{
"addr": "b1UP5pbfJgZrF1ezoSHLdvkxvgF2BYLtGva",
"peerID": "12D3KooWRHVAwymCVcA8jqyjpP3r3HBkCW2q5AZRTBvtaungzFSJ",
},
{
"addr": "b1ZWSdrg48g145VdcmBwMPVuDFdaxDLoktk",
"peerID": "12D3KooWQSaxCgbWakLcU69f4gmNFMszwhyHbwx4xPAhV7erDC2P",
},
{
"addr": "b1fRtRnKF4qhQG7bSwqbgR2BMw9VfM2XpT4",
"peerID": "12D3KooWNcJQzHaNpW5vZDQbTcoLXVCyGS755hTpendGzb5Hqtcu",
},
}
GenesisPeriod genesis period
var MissrateKey = []byte(MissCount)
MissrateKey is the db key to store bookkeeper's blocks miss rate
var PeriodKey = []byte(Period)
PeriodKey is the db key to store current period contex content
var TailKey = []byte(Tail)
TailKey is the db key to store tail block content
var ( // Transfers map[types.AddressHash][]*TransferInfo // TransferToContract *types.Transaction Transfers = make(map[types.AddressHash][]*TransferInfo) )
Transfers used to record the transfer information
Functions ¶
func AddrAllTokenUtxoKey ¶ added in v0.3.0
AddrAllTokenUtxoKey is the key prefix to explore all token utxos of an address
func AddrAllUtxoKey ¶ added in v0.3.0
AddrAllUtxoKey is the key prefix to explore all utxos of an address
func AddrTokenUtxoKey ¶ added in v0.3.0
AddrTokenUtxoKey is the key to store an token utxo which belongs to the input param address
func AddrUtxoKey ¶ added in v0.3.0
AddrUtxoKey is the key to store an utxo which belongs to the input param address
func ApplyMessage ¶ added in v0.5.0
func ApplyMessage(evm *vm.EVM, msg types.Message) ([]byte, uint64, uint64, bool, *types.Transaction, error)
ApplyMessage computes the new state by applying the given message against the old state within the environment.
func ApplyTransaction ¶ added in v0.5.0
func ApplyTransaction( tx *types.VMTransaction, header *types.BlockHeader, bc *BlockChain, statedb *state.StateDB, cfg vm.Config, utxoSet *UtxoSet, ) (*types.Receipt, uint64, uint64, []*types.Transaction, error)
ApplyTransaction attempts to apply a transaction to the given state database and uses the input parameters for its environment.
func BlockHashKey ¶
BlockHashKey returns the db key to store block hash content of the height
func CalcBlockSubsidy ¶
CalcBlockSubsidy returns the subsidy amount a block at the provided height should have.
func CalcTxsHash ¶
func CalcTxsHash(txs []*types.Transaction) *crypto.HashType
CalcTxsHash calculate txsHash in block.
func CanTransfer ¶ added in v0.5.0
CanTransfer checks whether there are enough funds in the address' account to make a transfer. This does not take the necessary gas in to account to make the transfer valid.
func CandidatesKey ¶
CandidatesKey returns the db key to store candidates.
func CreateCoinbaseTx ¶
func CreateCoinbaseTx(addr []byte, blockHeight uint32) (*types.Transaction, error)
CreateCoinbaseTx creates a coinbase give bookkeeper address and block height
func DeserializeUtxoWrap ¶ added in v0.3.0
DeserializeUtxoWrap returns UtxoWrap form serialized bytes.
func FetchOutPointOwner ¶ added in v0.5.0
FetchOutPointOwner fetchs owner of outpoint in utxo set
func GetHashFn ¶ added in v0.5.0
func GetHashFn(bc *BlockChain) func(n uint64) *crypto.HashType
GetHashFn returns a GetHashFunc which retrieves header hashes by number
func IntrinsicGas ¶ added in v0.5.0
IntrinsicGas computes the 'intrinsic gas' for a message with the given data.
func IsCoinBase ¶
func IsCoinBase(tx *types.Transaction) bool
IsCoinBase determines whether or not a transaction is a coinbase.
func IsTxFinalized ¶
func IsTxFinalized(tx *types.Transaction, blockHeight uint32, blockTime int64) bool
IsTxFinalized checks if a transaction is finalized.
func LoadBlockByHash ¶ added in v0.5.0
LoadBlockByHash load block by hash from db.
func MakeRollbackContractUtxos ¶ added in v0.5.0
func MakeRollbackContractUtxos( block *types.Block, stateDB *state.StateDB, db storage.Table, ) (types.UtxoMap, error)
MakeRollbackContractUtxos makes finally contract utxos from block
func MarshalMissData ¶ added in v0.3.0
MarshalMissData writes miss rate data to bytes
func MarshalTxIndex ¶
MarshalTxIndex writes Tx height and index to bytes
func NewEVMContext ¶ added in v0.5.0
func NewEVMContext(msg types.Message, header *types.BlockHeader, bc *BlockChain) vm.Context
NewEVMContext creates a new context for use in the EVM.
func ReceiptKey ¶ added in v0.5.0
ReceiptKey returns the db key to store receipt content of the block hash
func SecBloomBitSetKey ¶ added in v0.5.0
SecBloomBitSetKey is the key to store bloom bit set
func SerializeUtxoWrap ¶ added in v0.3.0
SerializeUtxoWrap returns the utxoWrap serialized to a format that is suitable for long-term storage.
func SplitAddrKey ¶ added in v0.3.0
SplitAddrKey returns the db key to store split address
func SplitTxHashKey ¶ added in v0.3.1
SplitTxHashKey returns the db key to store split tx mapping
func TokenPreAllocation ¶ added in v0.3.0
func TokenPreAllocation() ([]*types.Transaction, error)
TokenPreAllocation is for token preallocation
func Transfer ¶ added in v0.5.0
func Transfer(db vm.StateDB, sender, recipient types.AddressHash, amount *big.Int, interpreterInvoke bool)
Transfer subtracts amount from sender and adds amount to recipient using the given Db
func TxIndexKey ¶
TxIndexKey returns the db key to store tx index of the hash
func UnmarshalMissData ¶ added in v0.3.0
UnmarshalMissData return tx index from bytes
func UnmarshalTxIndex ¶
UnmarshalTxIndex return tx index from bytes
func ValidateTransactionPreliminary ¶
func ValidateTransactionPreliminary(tx *types.Transaction) error
ValidateTransactionPreliminary performs some preliminary checks on a transaction to ensure it is sane. These checks are context free.
func ValidateTxInputs ¶
ValidateTxInputs validates the inputs of a tx. Returns the total tx fee.
func VerifyBlockTimeOut ¶
VerifyBlockTimeOut refuse to accept a block with wrong timestamp.
Types ¶
type BalanceChangeMap ¶ added in v0.5.0
type BalanceChangeMap map[types.AddressHash]uint64
BalanceChangeMap defines the balance changes of accounts (add or subtract)
type BlockChain ¶
type BlockChain struct { LongestChainHeight uint32 // contains filtered or unexported fields }
BlockChain define chain struct
func NewBlockChain ¶
func NewBlockChain(parent goprocess.Process, notifiee p2p.Net, db storage.Storage, bus eventbus.Bus) (*BlockChain, error)
NewBlockChain return a blockchain.
func NewTestBlockChain ¶
func NewTestBlockChain() *BlockChain
NewTestBlockChain generate a chain for testing
func (*BlockChain) BroadcastOrRelayBlock ¶ added in v0.5.0
func (chain *BlockChain) BroadcastOrRelayBlock(block *types.Block, transferMode core.TransferMode)
BroadcastOrRelayBlock broadcast or relay block to other peers.
func (*BlockChain) Bus ¶
func (chain *BlockChain) Bus() eventbus.Bus
Bus returns the goprocess of the BlockChain
func (*BlockChain) CalcRootHashForNBlocks ¶
func (chain *BlockChain) CalcRootHashForNBlocks(hash crypto.HashType, num uint32) (*crypto.HashType, error)
CalcRootHashForNBlocks return root hash for N blocks.
func (*BlockChain) ChangeNewTail ¶ added in v0.3.0
func (chain *BlockChain) ChangeNewTail(tail *types.Block)
ChangeNewTail change chain tail block.
func (*BlockChain) Consensus ¶ added in v0.3.0
func (chain *BlockChain) Consensus() Consensus
Consensus return chain consensus.
func (*BlockChain) DelSplitTxs ¶ added in v0.3.0
func (chain *BlockChain) DelSplitTxs(splitTxs map[crypto.HashType]*types.Transaction, db storage.Table) error
DelSplitTxs del split txs.
func (*BlockChain) DelTxIndex ¶
func (chain *BlockChain) DelTxIndex( block *types.Block, splitTxs map[crypto.HashType]*types.Transaction, db storage.Table, ) error
DelTxIndex deletes tx index in block Delete split transaction copies saved earlier, both before and after split
func (*BlockChain) DeleteSplitAddrIndex ¶ added in v0.3.0
DeleteSplitAddrIndex remove split address index from both db and cache
func (*BlockChain) EternalBlock ¶
func (chain *BlockChain) EternalBlock() *types.Block
EternalBlock return chain eternal block.
func (*BlockChain) ExtractVMTransactions ¶ added in v0.5.0
func (chain *BlockChain) ExtractVMTransactions( tx *types.Transaction, ownerTxs ...*types.Transaction, ) (*types.VMTransaction, error)
ExtractVMTransactions extract Transaction to VMTransaction
func (*BlockChain) FetchNBlockAfterSpecificHash ¶
func (chain *BlockChain) FetchNBlockAfterSpecificHash(hash crypto.HashType, num uint32) ([]*types.Block, error)
FetchNBlockAfterSpecificHash get N block after specific hash.
func (*BlockChain) FilterLogs ¶ added in v0.5.0
FilterLogs filter logs by addrs and topicslist.
func (*BlockChain) Genesis ¶ added in v0.3.0
func (chain *BlockChain) Genesis() *types.Block
Genesis return chain genesis block.
func (*BlockChain) GetBlockHash ¶
func (chain *BlockChain) GetBlockHash(blockHeight uint32) (*crypto.HashType, error)
GetBlockHash finds the block in target height of main chain and returns it's hash
func (*BlockChain) GetBlockHeight ¶
func (chain *BlockChain) GetBlockHeight() uint32
GetBlockHeight returns current height of main chain
func (*BlockChain) GetBlockLogs ¶ added in v0.5.0
GetBlockLogs get logs by block hash.
func (*BlockChain) GetDataFromDB ¶ added in v0.3.0
func (chain *BlockChain) GetDataFromDB(key []byte) ([]byte, error)
GetDataFromDB get data from db
func (*BlockChain) GetEvmByHeight ¶ added in v0.5.0
func (chain *BlockChain) GetEvmByHeight(msg types.Message, height uint32) (*vm.EVM, func() error, error)
GetEvmByHeight get evm by block height.
func (*BlockChain) GetParentBlock ¶ added in v0.3.0
func (chain *BlockChain) GetParentBlock(block *types.Block) *types.Block
GetParentBlock Finds the parent of a block. Return nil if nonexistent
func (*BlockChain) GetTxReceipt ¶ added in v0.5.0
GetTxReceipt returns a tx receipt by using given tx hash.
func (*BlockChain) IsBusy ¶ added in v0.3.0
func (chain *BlockChain) IsBusy() bool
IsBusy return if the chain is processing a block
func (*BlockChain) IsCoinBase ¶ added in v0.3.0
func (chain *BlockChain) IsCoinBase(tx *types.Transaction) bool
IsCoinBase checks if an transaction is coinbase transaction
func (*BlockChain) LoadBlockByHeight ¶
func (chain *BlockChain) LoadBlockByHeight(height uint32) (*types.Block, error)
LoadBlockByHeight load block by height from db.
func (*BlockChain) LoadBlockInfoByTxHash ¶ added in v0.3.0
func (chain *BlockChain) LoadBlockInfoByTxHash(hash crypto.HashType) (*types.Block, *types.Transaction, error)
LoadBlockInfoByTxHash returns block and txIndex of transaction with the input param hash
func (*BlockChain) LoadEternalBlock ¶ added in v0.3.0
func (chain *BlockChain) LoadEternalBlock() (*types.Block, error)
LoadEternalBlock returns the current highest eternal block
func (*BlockChain) LocateForkPointAndFetchHeaders ¶
func (chain *BlockChain) LocateForkPointAndFetchHeaders(hashes []*crypto.HashType) ([]*crypto.HashType, error)
LocateForkPointAndFetchHeaders return block headers when get locate fork point request for sync service.
func (*BlockChain) Proc ¶
func (chain *BlockChain) Proc() goprocess.Process
Proc returns the goprocess of the BlockChain
func (*BlockChain) ProcessBlock ¶
func (chain *BlockChain) ProcessBlock(block *types.Block, transferMode core.TransferMode, messageFrom peer.ID) error
ProcessBlock is used to handle new blocks.
func (*BlockChain) ReadBlockFromDB ¶ added in v0.3.0
ReadBlockFromDB reads a block from db by hash and returns block and it's size
func (*BlockChain) ReceiptsCache ¶ added in v0.5.0
func (chain *BlockChain) ReceiptsCache() map[uint32]types.Receipts
ReceiptsCache returns chain receipts cache.
func (*BlockChain) RemoveBlock ¶ added in v0.3.0
func (chain *BlockChain) RemoveBlock(block *types.Block)
RemoveBlock store block to db.
func (*BlockChain) SetEternal ¶
func (chain *BlockChain) SetEternal(block *types.Block) error
SetEternal set block eternal status.
func (*BlockChain) SetTailState ¶ added in v0.5.0
func (chain *BlockChain) SetTailState(root, utxoRoot *crypto.HashType) error
SetTailState returns chain tail statedb
func (*BlockChain) Setup ¶
func (chain *BlockChain) Setup(consensus Consensus, syncManager SyncManager)
Setup prepare blockchain.
func (*BlockChain) SplitBlockOutputs ¶ added in v0.5.0
func (chain *BlockChain) SplitBlockOutputs(block *types.Block) map[crypto.HashType]*types.Transaction
SplitBlockOutputs split outputs of txs in the block where applicable return all split transactions, i.e., transactions containing at least one output to a split address
func (*BlockChain) StateProcessor ¶ added in v0.5.0
func (chain *BlockChain) StateProcessor() *StateProcessor
StateProcessor returns chain stateProcessor.
func (*BlockChain) StoreBlock ¶ added in v0.3.0
func (chain *BlockChain) StoreBlock(block *types.Block) error
StoreBlock store block to db.
func (*BlockChain) StoreBlockWithIndex ¶ added in v0.5.0
StoreBlockWithIndex store block to db in batch mod.
func (*BlockChain) StoreEternalBlock ¶
func (chain *BlockChain) StoreEternalBlock(block *types.Block) error
StoreEternalBlock store eternal block to db.
func (*BlockChain) StoreReceipts ¶ added in v0.5.0
func (chain *BlockChain) StoreReceipts(hash *crypto.HashType, receipts types.Receipts, db storage.Table) error
StoreReceipts store receipts to db in batch mod.
func (*BlockChain) StoreSplitTxs ¶ added in v0.3.0
func (chain *BlockChain) StoreSplitTxs( splitTxs map[crypto.HashType]*types.Transaction, db storage.Table, ) error
StoreSplitTxs store split txs.
func (*BlockChain) StoreTailBlock ¶
StoreTailBlock store tail block to db.
func (*BlockChain) TailBlock ¶
func (chain *BlockChain) TailBlock() *types.Block
TailBlock return chain tail block.
func (*BlockChain) TailState ¶ added in v0.5.0
func (chain *BlockChain) TailState() *state.StateDB
TailState returns chain tail statedb
func (*BlockChain) UpdateContractUtxoState ¶ added in v0.5.0
func (chain *BlockChain) UpdateContractUtxoState(statedb *state.StateDB, utxoSet *UtxoSet) error
UpdateContractUtxoState updates contract utxo in statedb
func (*BlockChain) UpdateNormalTxBalanceState ¶ added in v0.5.0
func (chain *BlockChain) UpdateNormalTxBalanceState(block *types.Block, utxoset *UtxoSet, stateDB *state.StateDB)
UpdateNormalTxBalanceState updates the balance state of normal tx
func (*BlockChain) UtxoSetCache ¶ added in v0.5.0
func (chain *BlockChain) UtxoSetCache() map[uint32]*UtxoSet
UtxoSetCache returns chain utxoSet cache.
func (*BlockChain) ValidateExecuteResult ¶ added in v0.5.0
func (chain *BlockChain) ValidateExecuteResult( block *types.Block, utxoTxs []*types.Transaction, usedGas, gasRemainingFee, totalTxsFee uint64, receipts types.Receipts, ) error
ValidateExecuteResult validates evm execute result
func (*BlockChain) WriteSplitAddrIndex ¶ added in v0.3.0
WriteSplitAddrIndex writes split addr info index
func (*BlockChain) WriteTxIndex ¶
func (chain *BlockChain) WriteTxIndex(block *types.Block, splitTxs map[crypto.HashType]*types.Transaction, db storage.Table) error
WriteTxIndex builds tx index in block Save split transaction copies before and after split. The latter is needed when reverting a transaction during reorg, spending from utxo/coin received at a split address
type Consensus ¶ added in v0.5.0
type Consensus interface { Run() error Stop() StopMint() RecoverMint() Verify(*types.Block) error Process(*types.Block, interface{}) error Finalize(*types.Block) error VerifyTx(*types.Transaction) error }
Consensus define consensus interface
type DummyDpos ¶
type DummyDpos struct{}
DummyDpos dummy dpos
type DummySyncManager ¶
type DummySyncManager struct{}
DummySyncManager is only used to test
func NewDummySyncManager ¶
func NewDummySyncManager() *DummySyncManager
NewDummySyncManager returns a new DummySyncManager
func (*DummySyncManager) ActiveLightSync ¶
func (dm *DummySyncManager) ActiveLightSync(pid peer.ID) error
ActiveLightSync active light sync from remote peer.
type ScriptItem ¶ added in v0.3.0
type ScriptItem struct {
// contains filtered or unexported fields
}
ScriptItem saves scripts for parallel validation
func CheckTxScripts ¶ added in v0.3.0
func CheckTxScripts(utxoSet *UtxoSet, tx *types.Transaction, skipValidation bool) ([]*ScriptItem, error)
CheckTxScripts verifies unlocking script for each input to ensure it is authorized to spend the utxo Coinbase tx will not reach here
type SectionManager ¶ added in v0.5.0
type SectionManager struct {
// contains filtered or unexported fields
}
SectionManager takes a number of bloom filters and generates the rotated bloom bits to be used for batched filtering.
func NewSectionManager ¶ added in v0.5.0
func NewSectionManager(chain *BlockChain, db storage.Storage) (mgr *SectionManager, err error)
NewSectionManager creates a rotated bloom section manager that can iteratively fill a batched bloom filter's bits.
func (*SectionManager) AddBloom ¶ added in v0.5.0
func (sm *SectionManager) AddBloom(index uint, bloom bloom.Filter) error
AddBloom takes a single bloom filter and sets the corresponding bit column in memory accordingly.
type StateProcessor ¶ added in v0.5.0
type StateProcessor struct {
// contains filtered or unexported fields
}
StateProcessor is a basic Processor, which takes care of transitioning state from one point to another.
func NewStateProcessor ¶ added in v0.5.0
func NewStateProcessor(bc *BlockChain) *StateProcessor
NewStateProcessor initialises a new StateProcessor.
type StateTransition ¶ added in v0.5.0
type StateTransition struct {
// contains filtered or unexported fields
}
StateTransition the State Transitioning Model
func NewStateTransition ¶ added in v0.5.0
func NewStateTransition(evm *vm.EVM, msg types.Message) *StateTransition
NewStateTransition initialises and returns a new state transition object.
func (*StateTransition) TransitionDb ¶ added in v0.5.0
func (st *StateTransition) TransitionDb() (ret []byte, usedGas, gasRemaining uint64, failed bool, gasRefundTx *types.Transaction, err error)
TransitionDb will transition the state by applying the current message and returning the result including the used gas. There are three scenarios for executing a tx: case 1: the tx is invalid before it is actually executed by evm. The tx is not on chain and returns an error. case 2: error returned after tx is executed by evm (the error is not an insufficient balance error). The tx is on chain but it's failed and the gas is used. case 3: the tx execution successful. The tx is on chain and it`s successful.
type SyncManager ¶ added in v0.5.0
SyncManager define sync manager interface
type TransferInfo ¶ added in v0.5.0
type TransferInfo struct {
// contains filtered or unexported fields
}
TransferInfo used to record the transfer information occurred during the execution of the contract
func NewTransferInfo ¶ added in v0.5.0
func NewTransferInfo(from, to types.AddressHash, value *big.Int) *TransferInfo
NewTransferInfo creates a new transferInfo.
type UpdateMsg ¶
type UpdateMsg struct { // block connected/disconnected from main chain AttachBlocks []*types.Block DetachBlocks []*types.Block }
UpdateMsg sent from blockchain to, e.g., mempool
type UtxoSet ¶
type UtxoSet struct {
// contains filtered or unexported fields
}
UtxoSet contains all utxos
func GetExtendedTxUtxoSet ¶
func GetExtendedTxUtxoSet(tx *types.Transaction, db storage.Table, spendableTxs *sync.Map) (*UtxoSet, error)
GetExtendedTxUtxoSet returns tx's utxo set from both db & txs in spendableTxs
func NewUtxoSetFromMap ¶
NewUtxoSetFromMap returns the underlying utxos as a map
func (*UtxoSet) ApplyBlock ¶
ApplyBlock updates utxos with all transactions in the passed block
func (*UtxoSet) ApplyInternalTxs ¶ added in v0.5.0
ApplyInternalTxs applies internal txs in block
func (*UtxoSet) ImportUtxoMap ¶ added in v0.5.0
ImportUtxoMap imports utxos from a UtxoMap
func (*UtxoSet) LoadBlockAllUtxos ¶ added in v0.3.0
LoadBlockAllUtxos loads all UTXOs txs in the block
func (*UtxoSet) LoadBlockUtxos ¶
LoadBlockUtxos loads UTXOs txs in the block spend
func (*UtxoSet) LoadTxUtxos ¶
LoadTxUtxos loads the unspent transaction outputs related to tx
func (*UtxoSet) RevertBlock ¶
func (u *UtxoSet) RevertBlock(block *types.Block, chain *BlockChain) error
RevertBlock undoes utxo changes made with all the transactions in the passed block It undoes the effect of ApplyBlock on utxo set
func (*UtxoSet) RevertTx ¶
func (u *UtxoSet) RevertTx(tx *types.Transaction, chain *BlockChain) error
RevertTx updates utxos with the passed tx: delete all utxos in outputs and add all utxos in inputs. It undoes the effect of ApplyTx on utxo set
func (*UtxoSet) TxInputAmount ¶ added in v0.3.0
func (u *UtxoSet) TxInputAmount(tx *types.Transaction) uint64
TxInputAmount returns total amount from tx's inputs Return 0 if a tx is not fully funded, i.e., if not all of its spending utxos exist