Documentation ¶
Index ¶
- Constants
- type Block
- func (b *Block) CalculateGasUsage() int64
- func (b *Block) CalculateHeadHash()
- func (b *Block) CalculateTxMerkleHash() []byte
- func (b *Block) CalculateTxReceiptMerkleHash() []byte
- func (b *Block) Decode(blockByte []byte) error
- func (b *Block) Encode() ([]byte, error)
- func (b *Block) EncodeM() ([]byte, error)
- func (b *Block) HeadHash() []byte
- func (b *Block) LenTx() int
- func (b *Block) VerifySelf() error
- type BlockChain
- func (bc *BlockChain) AllDelaytx() ([]*tx.Tx, error)
- func (bc *BlockChain) CheckLength()
- func (bc *BlockChain) Close()
- func (bc *BlockChain) CopyLastNBlockTo(newLocation string, numberToKeep int64) error
- func (bc *BlockChain) Draw(start int64, end int64) string
- func (bc *BlockChain) GetBlockByHash(hash []byte) (*Block, error)
- func (bc *BlockChain) GetBlockByNumber(number int64) (*Block, error)
- func (bc *BlockChain) GetBlockNumberByTxHash(hash []byte) (int64, error)
- func (bc *BlockChain) GetHashByNumber(number int64) ([]byte, error)
- func (bc *BlockChain) GetReceipt(hash []byte) (*tx.TxReceipt, error)
- func (bc *BlockChain) GetReceiptByTxHash(hash []byte) (*tx.TxReceipt, error)
- func (bc *BlockChain) GetTx(hash []byte) (*tx.Tx, error)
- func (bc *BlockChain) HasReceipt(hash []byte) (bool, error)
- func (bc *BlockChain) HasTx(hash []byte) (bool, error)
- func (bc *BlockChain) Length() int64
- func (bc *BlockChain) Push(block *Block) error
- func (bc *BlockChain) SetLength(i int64)
- func (bc *BlockChain) SetTxTotal(i int64)
- func (bc *BlockChain) Size() (int64, error)
- func (bc *BlockChain) Top() (*Block, error)
- func (bc *BlockChain) TxTotal() int64
- type BlockHead
- type Chain
Constants ¶
const ( V0 int64 = iota V1 )
BlockHead versions
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct { Head *BlockHead Sign *crypto.Signature Txs []*tx.Tx Receipts []*tx.TxReceipt TxHashes [][]byte ReceiptHashes [][]byte // contains filtered or unexported fields }
Block is the implementation of block
func (*Block) CalculateGasUsage ¶
CalculateGasUsage calculates the block's gas usage.
func (*Block) CalculateHeadHash ¶
func (b *Block) CalculateHeadHash()
CalculateHeadHash calculate the hash of the head
func (*Block) CalculateTxMerkleHash ¶
CalculateTxMerkleHash calculate the merkle hash of the transaction.
func (*Block) CalculateTxReceiptMerkleHash ¶
CalculateTxReceiptMerkleHash calculate the merkle hash of the transaction receipt.
func (*Block) VerifySelf ¶
VerifySelf verify block's signature and some base fields.
type BlockChain ¶
type BlockChain struct {
// contains filtered or unexported fields
}
BlockChain is the implementation of chain
func (*BlockChain) AllDelaytx ¶
func (bc *BlockChain) AllDelaytx() ([]*tx.Tx, error)
AllDelaytx returns all delay transactions.
func (*BlockChain) CheckLength ¶
func (bc *BlockChain) CheckLength()
CheckLength is check length of block in database
func (*BlockChain) CopyLastNBlockTo ¶
func (bc *BlockChain) CopyLastNBlockTo(newLocation string, numberToKeep int64) error
func (*BlockChain) Draw ¶
func (bc *BlockChain) Draw(start int64, end int64) string
Draw the graph about blockchain
func (*BlockChain) GetBlockByHash ¶
func (bc *BlockChain) GetBlockByHash(hash []byte) (*Block, error)
GetBlockByHash is get block by hash
func (*BlockChain) GetBlockByNumber ¶
func (bc *BlockChain) GetBlockByNumber(number int64) (*Block, error)
GetBlockByNumber is get block by number
func (*BlockChain) GetBlockNumberByTxHash ¶
func (bc *BlockChain) GetBlockNumberByTxHash(hash []byte) (int64, error)
GetBlockNumberByTxHash is get number of the block by hash of the tx
func (*BlockChain) GetHashByNumber ¶
func (bc *BlockChain) GetHashByNumber(number int64) ([]byte, error)
GetHashByNumber is get hash by number
func (*BlockChain) GetReceipt ¶
func (bc *BlockChain) GetReceipt(hash []byte) (*tx.TxReceipt, error)
GetReceipt gets receipt with receipt's hash
func (*BlockChain) GetReceiptByTxHash ¶
func (bc *BlockChain) GetReceiptByTxHash(hash []byte) (*tx.TxReceipt, error)
GetReceiptByTxHash gets receipt with tx's hash
func (*BlockChain) GetTx ¶
func (bc *BlockChain) GetTx(hash []byte) (*tx.Tx, error)
GetTx gets tx with tx's hash.
func (*BlockChain) HasReceipt ¶
func (bc *BlockChain) HasReceipt(hash []byte) (bool, error)
HasReceipt checks if database has receipt.
func (*BlockChain) HasTx ¶
func (bc *BlockChain) HasTx(hash []byte) (bool, error)
HasTx checks if database has tx.
func (*BlockChain) Length ¶
func (bc *BlockChain) Length() int64
Length return length of block chain
func (*BlockChain) Push ¶
func (bc *BlockChain) Push(block *Block) error
Push save the block to database
func (*BlockChain) SetLength ¶
func (bc *BlockChain) SetLength(i int64)
SetLength sets blockchain's length.
func (*BlockChain) SetTxTotal ¶
func (bc *BlockChain) SetTxTotal(i int64)
SetTxTotal sets blockchain's tx total.
func (*BlockChain) Size ¶
func (bc *BlockChain) Size() (int64, error)
Size returns the blockchain db size
func (*BlockChain) TxTotal ¶
func (bc *BlockChain) TxTotal() int64
TxTotal return tx total of block chain
type BlockHead ¶
type BlockHead struct { Version int64 ParentHash []byte TxMerkleHash []byte TxReceiptMerkleHash []byte Info []byte Number int64 Witness string Time int64 GasUsage int64 }
BlockHead is the struct of block head.
type Chain ¶
type Chain interface { Push(block *Block) error Length() int64 TxTotal() int64 CheckLength() SetLength(i int64) Top() (*Block, error) GetHashByNumber(number int64) ([]byte, error) GetBlockByNumber(number int64) (*Block, error) GetBlockByHash(blockHash []byte) (*Block, error) GetTx(hash []byte) (*tx.Tx, error) HasTx(hash []byte) (bool, error) GetReceipt(Hash []byte) (*tx.TxReceipt, error) GetReceiptByTxHash(Hash []byte) (*tx.TxReceipt, error) HasReceipt(hash []byte) (bool, error) Size() (int64, error) Close() AllDelaytx() ([]*tx.Tx, error) Draw(int64, int64) string GetBlockNumberByTxHash(hash []byte) (int64, error) }
Chain defines Chain's API.
func NewBlockChain ¶
NewBlockChain returns a Chain instance