block

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2018 License: LGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 added in v1.1.0

func (b *Block) CalculateGasUsage() int64

CalculateGasUsage calculates the block's gas usage.

func (*Block) CalculateHeadHash

func (b *Block) CalculateHeadHash() error

CalculateHeadHash calculate the hash of the head

func (*Block) CalculateTxMerkleHash added in v1.1.0

func (b *Block) CalculateTxMerkleHash() []byte

CalculateTxMerkleHash calculate the merkle hash of the transaction.

func (*Block) CalculateTxReceiptMerkleHash added in v1.1.0

func (b *Block) CalculateTxReceiptMerkleHash() []byte

CalculateTxReceiptMerkleHash calculate the merkle hash of the transaction receipt.

func (*Block) Decode

func (b *Block) Decode(blockByte []byte) error

Decode is unmarshal

func (*Block) Encode

func (b *Block) Encode() ([]byte, error)

Encode is marshal

func (*Block) EncodeM added in v1.1.0

func (b *Block) EncodeM() ([]byte, error)

EncodeM is marshal

func (*Block) HeadHash

func (b *Block) HeadHash() []byte

HeadHash return block hash

func (*Block) LenTx

func (b *Block) LenTx() int

LenTx return len of transaction

type BlockChain

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

BlockChain is the implementation of chain

func (*BlockChain) AllDelaytx added in v1.1.0

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) Close

func (bc *BlockChain) Close()

Close is close database

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) GetHashByNumber

func (bc *BlockChain) GetHashByNumber(number int64) ([]byte, error)

GetHashByNumber is get hash by number

func (*BlockChain) GetReceipt added in v1.1.0

func (bc *BlockChain) GetReceipt(hash []byte) (*tx.TxReceipt, error)

GetReceipt gets receipt with receipt's hash

func (*BlockChain) GetReceiptByTxHash added in v1.1.0

func (bc *BlockChain) GetReceiptByTxHash(hash []byte) (*tx.TxReceipt, error)

GetReceiptByTxHash gets receipt with tx's hash

func (*BlockChain) GetTx added in v1.1.0

func (bc *BlockChain) GetTx(hash []byte) (*tx.Tx, error)

GetTx gets tx with tx's hash.

func (*BlockChain) HasReceipt added in v1.1.0

func (bc *BlockChain) HasReceipt(hash []byte) (bool, error)

HasReceipt checks if database has receipt.

func (*BlockChain) HasTx added in v1.1.0

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 added in v1.1.0

func (bc *BlockChain) SetLength(i int64)

SetLength sets blockchain's length.

func (*BlockChain) Top

func (bc *BlockChain) Top() (*Block, error)

Top return the block

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.

func (*BlockHead) Decode

func (b *BlockHead) Decode(bhByte []byte) error

Decode is unmarshal

func (*BlockHead) Encode

func (b *BlockHead) Encode() ([]byte, error)

Encode is marshal

func (*BlockHead) FromPb added in v1.1.0

func (b *BlockHead) FromPb(bh *blockpb.BlockHead) *BlockHead

FromPb convert BlockHead from proto buf data structure.

func (*BlockHead) Hash

func (b *BlockHead) Hash() ([]byte, error)

Hash return hash

func (*BlockHead) ToBytes added in v1.1.0

func (b *BlockHead) ToBytes() []byte

ToBytes converts BlockHead to a specific byte slice.

func (*BlockHead) ToPb added in v1.1.0

func (b *BlockHead) ToPb() *blockpb.BlockHead

ToPb convert BlockHead to proto buf data structure.

type Chain

type Chain interface {
	Push(block *Block) error
	Length() int64
	CheckLength()
	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)
	Close()
	AllDelaytx() ([]*tx.Tx, error)
	Draw(int64, int64) string
}

Chain defines Chain's API.

func NewBlockChain

func NewBlockChain(path string) (Chain, error)

NewBlockChain returns a Chain instance

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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