Documentation ¶
Index ¶
- Constants
- Variables
- func DeriveHash(list DerivableList) common.Hash
- func GetStateDB(storage persistent.Storage) state.Database
- type Block
- func (b *Block) ChainID() uint32
- func (b *Block) ConsensusRoot() common.Hash
- func (b *Block) Extra() []byte
- func (b *Block) GetAccount(address common.Address) state.Account
- func (b *Block) Hash() common.Hash
- func (b *Block) Number() uint64
- func (b *Block) ParentHash() common.Hash
- func (b *Block) ReceiptsRoot() common.Hash
- func (b *Block) Sign(signer crypto.Signer) error
- func (b *Block) Signers() (map[common.Address]crypto.Signature, error)
- func (b *Block) StateRoot() common.Hash
- func (b *Block) Time() uint64
- func (b *Block) ToBytes() ([]byte, error)
- func (b *Block) TxsRoot() common.Hash
- func (b *Block) ValidatorAddr() []common.Address
- func (b *Block) VerifyBody() error
- func (b *Block) Write(putter persistent.Putter) error
- type BlockChain
- func (bc *BlockChain) AddBlock(b *Block) error
- func (bc *BlockChain) BuildNextBlock(parent *Block, t uint64, txs Transactions) (*Block, error)
- func (bc *BlockChain) ChainID() ChainID
- func (bc *BlockChain) CurrentBlockHeight() uint64
- func (bc *BlockChain) GetBlockByHash(hash common.Hash) *Block
- func (bc *BlockChain) GetBlockByNumber(number uint64) *Block
- func (bc *BlockChain) GetBlockNum2Hash(number uint64) *common.Hash
- func (bc *BlockChain) GetTxByHash(hash common.Hash) *Transaction
- func (bc *BlockChain) GetValidators() []string
- func (bc *BlockChain) LastBlock() *Block
- func (bc *BlockChain) Reset() error
- func (bc *BlockChain) State() (state.AccountTrie, error)
- func (bc *BlockChain) StateAt(root common.Hash) (state.AccountTrie, error)
- func (bc *BlockChain) Stop()
- type BlockHeader
- type BlockPool
- func (bp *BlockPool) AddSealRequest(h, t uint64, txs Transactions)
- func (bp *BlockPool) GetBlockByHash(hash common.Hash) *Block
- func (bp *BlockPool) GetBlockByNumber(number uint64) *Block
- func (bp *BlockPool) GetBlockNum2Hash(number uint64) *common.Hash
- func (bp *BlockPool) Start()
- func (bp *BlockPool) Stop()
- type ChainID
- type ChainReader
- type Core
- func (c *Core) AddressFromPublicKey(publicKey []byte) ([]byte, error)
- func (c *Core) Chain() *BlockChain
- func (c *Core) FakeP2pRecv(msg *p2p.Message)
- func (c *Core) GetChainData(kind string, key []byte) []byte
- func (c *Core) GetMinerSigner() (crypto.Signer, error)
- func (c *Core) GetPrivateKeyOfDefaultAccount() ([]byte, error)
- func (c *Core) GetRemoteBlockByHash(hash common.Hash) (*Block, error)
- func (c *Core) GetRemoteBlockByNumber(n uint64) (*Block, error)
- func (c *Core) GetRemoteLatestHash() (*common.Hash, error)
- func (c *Core) GetRemoteLatestNumber() (uint64, error)
- func (c *Core) GetSigner() crypto.Signer
- func (c *Core) IsSyncing() bool
- func (c *Core) MinerAddr() *address.Address
- func (c *Core) Start() error
- func (c *Core) Stop() error
- func (c *Core) TriggerSync()
- func (c *Core) TxBroadcast(tx *Transaction) error
- type DerivableList
- type Genesis
- type INode
- type InitYeeDist
- type Receipt
- type Receipts
- type Transaction
- func (t *Transaction) Amount() *big.Int
- func (t *Transaction) ChainID() uint32
- func (t *Transaction) Decode(enc []byte) error
- func (t *Transaction) Encode() ([]byte, error)
- func (t *Transaction) From() *common.Address
- func (t *Transaction) FromProto(msg proto.Message) error
- func (t *Transaction) Hash() *common.Hash
- func (t *Transaction) Nonce() uint64
- func (t *Transaction) Recipient() *common.Address
- func (t *Transaction) Sign(signer crypto.Signer) error
- func (t *Transaction) String() string
- func (t *Transaction) To() *common.Address
- func (t *Transaction) ToProto() (*corepb.Transaction, error)
- func (t *Transaction) VerifySig() error
- type TransactionPool
- type Transactions
Constants ¶
View Source
const ( ChainDataTypeLatestH = "latestH" // latest block hash ChainDataTypeLatestN = "latestN" // latest block number ChainDataTypeBlockH = "blkH" // block for given hash ChainDataTypeBlockN = "blkN" // block for given number )
chainData types used to query from peers
View Source
const ( KeyChainID = "ChainID" KeyLastBlock = "LastBlock" KeyPrefixStateTrie = "sTrie-" // stateTrie Hash => trie node KeyPrefixTx = "tx-" // txHash => encodedTx KeyPrefixHeader = "blkH-" // blockHash => encodedBlockHeader KeyPrefixBody = "blkB-" // blockHash => encodedBlockBody KeyPrefixBlockNum2Hash = "bn2h-" // blockNum => blockHash KeyPrefixBlockHash2Num = "bh2n-" // blockHash => blockNum )
Key / KeyPrefix for blockchain used in persistent.Storage
View Source
const ( EventReqDhtGetMaxRetry = 128 EventReqDhtGetTimeout = 60 * time.Second OutputTxsDhtGetMaxRetry = 1024 OutputTxsDhtGetTimeout = 60 * time.Second )
View Source
const TooFarBlocks = 120
View Source
const TooFarTx = 8192
Variables ¶
View Source
var ( EmptyRootHash = DeriveHash(Transactions{}) ErrBlockBodyTxsMismatch = errors.New("block body txs mismatch") )
View Source
var ( ErrBlockChainID = errors.New("block chainID mismatch") ErrBlockTooFarForChain = errors.New("block too far for chain head") )
View Source
var ( ErrBlockChainNoStorage = errors.New("core.chain: must provide block chain storage") ErrBlockChainIDMismatch = errors.New("core.chain: chainID mismatch") ErrBlockStateTrieMismatch = errors.New("core.chain: trie root hash mismatch") ErrBlockParentMissing = errors.New("core.chain: block parent missing") ErrBlockParentMismatch = errors.New("core.chain: block parent mismatch") ErrBlockSignatureMismatch = errors.New("core.chain: block signature mismatch") )
View Source
var ( ErrNoCoinbase = errors.New("coinbase not provided") ErrNoCoinbasePwdFile = errors.New("coinbase keystore password file not provided") ErrCoinbaseKeyNotFound = errors.New("coinbase not found in keystore") )
View Source
var ( ErrNoSignature = errors.New("no signature with tx") ErrNoSigner = errors.New("no signer found") ErrSignatureMismatch = errors.New("signature mismatch") ErrTxFromMismatch = errors.New("tx sender mismatch") )
View Source
var (
ErrInvalidProtoToTransaction = errors.New("failed to parse ProtoBuf msg to Transaction")
)
View Source
var (
ErrTxChainID = errors.New("transaction chainID mismatch")
)
Functions ¶
func DeriveHash ¶
func DeriveHash(list DerivableList) common.Hash
Add list elements to a in-mem trie, with index as key, trie root hash is returned.
func GetStateDB ¶
func GetStateDB(storage persistent.Storage) state.Database
Types ¶
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
In-memory representative for the block concept
func NewBlock ¶
func NewBlock(header *BlockHeader, txs []*Transaction) *Block
func ParseBlock ¶
func (*Block) ConsensusRoot ¶
func (*Block) ParentHash ¶
func (*Block) ReceiptsRoot ¶
func (*Block) ValidatorAddr ¶
func (*Block) VerifyBody ¶
Verify block body match with hash in header
type BlockChain ¶
type BlockChain struct {
// contains filtered or unexported fields
}
BlockChain is a Data Manager that
created with a Storage, for chain trie/data storage created with a Genesis block handles tx / block lookup within the chain check on block arrival, receive block on signatures confirmation notify sub routines to stop, while wait for them to stop
func NewBlockChain ¶
func NewBlockChain(chainID ChainID, storage persistent.Storage, engine consensus.Engine) (*BlockChain, error)
func NewBlockChainWithCore ¶
func NewBlockChainWithCore(core *Core) (*BlockChain, error)
func (*BlockChain) AddBlock ¶
func (bc *BlockChain) AddBlock(b *Block) error
add a checked block to block chain, as last block
func (*BlockChain) BuildNextBlock ¶
func (bc *BlockChain) BuildNextBlock(parent *Block, t uint64, txs Transactions) (*Block, error)
Build Next block from parent block, with transactions
func (*BlockChain) ChainID ¶
func (bc *BlockChain) ChainID() ChainID
func (*BlockChain) CurrentBlockHeight ¶
func (bc *BlockChain) CurrentBlockHeight() uint64
func (*BlockChain) GetBlockByHash ¶
func (bc *BlockChain) GetBlockByHash(hash common.Hash) *Block
func (*BlockChain) GetBlockByNumber ¶
func (bc *BlockChain) GetBlockByNumber(number uint64) *Block
func (*BlockChain) GetBlockNum2Hash ¶
func (bc *BlockChain) GetBlockNum2Hash(number uint64) *common.Hash
func (*BlockChain) GetTxByHash ¶
func (bc *BlockChain) GetTxByHash(hash common.Hash) *Transaction
func (*BlockChain) GetValidators ¶
func (bc *BlockChain) GetValidators() []string
func (*BlockChain) LastBlock ¶
func (bc *BlockChain) LastBlock() *Block
func (*BlockChain) State ¶
func (bc *BlockChain) State() (state.AccountTrie, error)
func (*BlockChain) StateAt ¶
func (bc *BlockChain) StateAt(root common.Hash) (state.AccountTrie, error)
func (*BlockChain) Stop ¶
func (bc *BlockChain) Stop()
type BlockHeader ¶
type BlockHeader struct { // chain ChainID uint32 `json:"chainID"` Number uint64 `json:"number"` ParentHash common.Hash `json:"parentHash"` // trie root hashes ConsensusRoot common.Hash `json:"consensusRoot"` StateRoot common.Hash `json:"stateRoot"` TxsRoot common.Hash `json:"transactionsRoot"` ReceiptsRoot common.Hash `json:"receiptsRoot"` // block time in milli seconds Time uint64 `json:"timestamp"` // extra binary data Extra []byte `json:"extraData"` }
Block Header of yee chain
Encoded with RLP into byte[] for hashing stored as value in Storage, with hash as key
func CopyHeader ¶
func CopyHeader(header *BlockHeader) *BlockHeader
func (*BlockHeader) Hash ¶
func (bh *BlockHeader) Hash() ([]byte, error)
func (*BlockHeader) ToBytes ¶
func (bh *BlockHeader) ToBytes() ([]byte, error)
type BlockPool ¶
type BlockPool struct {
// contains filtered or unexported fields
}
func NewBlockPool ¶
func (*BlockPool) AddSealRequest ¶
func (bp *BlockPool) AddSealRequest(h, t uint64, txs Transactions)
func (*BlockPool) GetBlockByNumber ¶
func (*BlockPool) GetBlockNum2Hash ¶
type ChainReader ¶
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
func NewCoreWithGenesis ¶
func (*Core) AddressFromPublicKey ¶
func (*Core) Chain ¶
func (c *Core) Chain() *BlockChain
func (*Core) FakeP2pRecv ¶
as if msg was received from p2p module
func (*Core) GetPrivateKeyOfDefaultAccount ¶
func (*Core) GetRemoteBlockByHash ¶
func (*Core) GetRemoteBlockByNumber ¶
func (*Core) GetRemoteLatestNumber ¶
func (*Core) TriggerSync ¶
func (c *Core) TriggerSync()
func (*Core) TxBroadcast ¶
func (c *Core) TxBroadcast(tx *Transaction) error
type DerivableList ¶
DerivableList can be add to a trie for hashing, getting a proof to verify the list
type Genesis ¶
type Genesis struct { ChainID ChainID Time int64 Extra string Consensus struct { Tetris struct { Validators []string } } InitYeeDist []InitYeeDist // block header hash generated with info above Hash string }
func LoadGenesis ¶
func NewGenesis ¶
type InitYeeDist ¶
type InitYeeDist struct {
Address, Value string
}
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
func NewTransaction ¶
func NewTransactionFromProto ¶
func NewTransactionFromProto(msg proto.Message) (*Transaction, error)
func (*Transaction) Amount ¶
func (t *Transaction) Amount() *big.Int
func (*Transaction) ChainID ¶
func (t *Transaction) ChainID() uint32
func (*Transaction) Decode ¶
func (t *Transaction) Decode(enc []byte) error
func (*Transaction) Encode ¶
func (t *Transaction) Encode() ([]byte, error)
func (*Transaction) From ¶
func (t *Transaction) From() *common.Address
func (*Transaction) Hash ¶
func (t *Transaction) Hash() *common.Hash
func (*Transaction) Nonce ¶
func (t *Transaction) Nonce() uint64
func (*Transaction) Recipient ¶
func (t *Transaction) Recipient() *common.Address
func (*Transaction) String ¶
func (t *Transaction) String() string
func (*Transaction) To ¶
func (t *Transaction) To() *common.Address
func (*Transaction) ToProto ¶
func (t *Transaction) ToProto() (*corepb.Transaction, error)
func (*Transaction) VerifySig ¶
func (t *Transaction) VerifySig() error
type TransactionPool ¶
type TransactionPool struct {
// contains filtered or unexported fields
}
func NewTransactionPool ¶
func NewTransactionPool(core *Core) (*TransactionPool, error)
func (*TransactionPool) Start ¶
func (tp *TransactionPool) Start()
func (*TransactionPool) Stop ¶
func (tp *TransactionPool) Stop()
func (*TransactionPool) TxBroadcast ¶
func (tp *TransactionPool) TxBroadcast(tx *Transaction) error
type Transactions ¶
type Transactions []*Transaction
func (Transactions) GetEncoded ¶
func (txs Transactions) GetEncoded(index int) []byte
func (Transactions) Len ¶
func (txs Transactions) Len() int
func (Transactions) String ¶
func (txs Transactions) String() string
func (Transactions) Write ¶
func (txs Transactions) Write(putter persistent.Putter) error
Source Files ¶
Click to show internal directories.
Click to hide internal directories.