block

package
v0.0.0-...-f94ef0f Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxTransactionsPerBlock is the maximum number of transactions per block.
	MaxTransactionsPerBlock = math.MaxUint16
)

Variables

View Source
var ErrMaxContentsPerBlock = errors.New("the number of contents exceeds the maximum number of contents per block")

ErrMaxContentsPerBlock is returned when the maximum number of contents per block is reached.

Functions

This section is empty.

Types

type Block

type Block struct {
	// The base of the block.
	Header

	// Transaction list.
	Transactions []*transaction.Transaction

	// True if this block is created from trimmed data.
	Trimmed bool
}

Block represents one block in the chain.

func New

func New() *Block

New creates a new blank block with proper state root setting.

func NewTrimmedFromReader

func NewTrimmedFromReader(br *io.BinReader) (*Block, error)

NewTrimmedFromReader returns a new block from trimmed data. This is commonly used to create a block from stored data. Blocks created from trimmed data will have their Trimmed field set to true.

func (*Block) ComputeMerkleRoot

func (b *Block) ComputeMerkleRoot() common.Hash

ComputeMerkleRoot computes Merkle tree root hash based on actual block's data.

func (*Block) DecodeBinary

func (b *Block) DecodeBinary(br *io.BinReader)

DecodeBinary decodes the block from the given BinReader, implementing Serializable interface.

func (*Block) EncodeBinary

func (b *Block) EncodeBinary(bw *io.BinWriter)

EncodeBinary encodes the block to the given BinWriter, implementing Serializable interface.

func (*Block) EncodeTrimmed

func (b *Block) EncodeTrimmed(w *io.BinWriter)

EncodeTrimmed writes trimmed representation of the block data into w. Trimmed blocks do not store complete transactions, instead they only store their hashes.

func (*Block) GetExpectedBlockSize

func (b *Block) GetExpectedBlockSize() int

GetExpectedBlockSize returns expected block size which should be equal to io.GetVarSize(b).

func (*Block) GetExpectedBlockSizeWithoutTransactions

func (b *Block) GetExpectedBlockSizeWithoutTransactions(txCount int) int

GetExpectedBlockSizeWithoutTransactions returns expected block size without transactions size.

func (Block) MarshalJSON

func (b Block) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*Block) RebuildMerkleRoot

func (b *Block) RebuildMerkleRoot()

RebuildMerkleRoot rebuilds the merkleroot of the block.

func (*Block) UnmarshalJSON

func (b *Block) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface.

type Header struct {
	// Version of the block.
	Version uint32

	// hash of the previous block.
	PrevHash common.Hash

	// Root hash of a transaction list.
	MerkleRoot common.Hash

	// Timestamp is a unix timestamp.
	// The time stamp of each block must be later than previous block's time stamp.
	// Generally the difference of two block's time stamp is about 15 seconds and imprecision is allowed.
	// The height of the block must be exactly equal to the height of the previous block plus 1.
	Timestamp uint64

	// Nonce is block random number.
	Nonce uint64

	// index/height of the block
	Index uint32

	// Contract address of the next miner
	NextConsensus common.Address

	// Script used to validate the block
	Witness transaction.Witness

	// PrimaryIndex is the index of primary consensus node for this block.
	PrimaryIndex byte
	// contains filtered or unexported fields
}

Header holds the base info of a block.

func (*Header) DecodeBinary

func (b *Header) DecodeBinary(br *io.BinReader)

DecodeBinary implements Serializable interface.

func (*Header) EncodeBinary

func (b *Header) EncodeBinary(bw *io.BinWriter)

EncodeBinary implements Serializable interface.

func (*Header) Hash

func (b *Header) Hash() common.Hash

Hash returns the hash of the block.

func (Header) MarshalJSON

func (b Header) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*Header) UnmarshalJSON

func (b *Header) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface.

Jump to

Keyboard shortcuts

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