block

package
v3.9.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2022 License: LGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
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

func (b *Block) CalculateGasUsage() int64

CalculateGasUsage calculates the block's gas usage.

func (*Block) CalculateHeadHash

func (b *Block) CalculateHeadHash()

CalculateHeadHash calculate the hash of the head

func (*Block) CalculateTxMerkleHash

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

CalculateTxMerkleHash calculate the merkle hash of the transaction.

func (*Block) CalculateTxReceiptMerkleHash

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

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

EncodeM is marshal

func (*Block) FromPb

func (b *Block) FromPb(br *blockpb.Block) *Block

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

func (*Block) ToPb

func (b *Block) ToPb(t blockpb.BlockType) *blockpb.Block

ToPb convert to protobuf

func (*Block) VerifySelf

func (b *Block) VerifySelf() error

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

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

Top return the block

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.

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

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

FromPb convert BlockHead from proto buf data structure.

func (*BlockHead) Rules

func (b *BlockHead) Rules() *version.Rules

Rules create new rules for this block

func (*BlockHead) ToBytes

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

ToBytes converts BlockHead to a specific byte slice.

func (*BlockHead) ToPb

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
	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()
	Draw(int64, int64) string
	GetBlockNumberByTxHash(hash []byte) (int64, error)
}

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