block

package
v0.94.0-pre Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2021 License: MIT Imports: 12 Imported by: 16

Documentation

Index

Constants

View Source
const (
	// MaxContentsPerBlock is the maximum number of contents (transactions + consensus data) per block.
	MaxContentsPerBlock = math.MaxUint16
	// MaxTransactionsPerBlock is the maximum number of transactions per block.
	MaxTransactionsPerBlock = MaxContentsPerBlock - 1
)

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 Base

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

	// hash of the previous block.
	PrevHash util.Uint256

	// Root hash of a transaction list.
	MerkleRoot util.Uint256

	// Timestamp is a millisecond-precision 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

	// index/height of the block
	Index uint32

	// Contract address of the next miner
	NextConsensus util.Uint160

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

	// Network magic number this block belongs to. This one actually is not
	// a part of the wire-representation of Block, but it's absolutely
	// necessary for correct signing/verification.
	Network netmode.Magic

	// StateRootEnabled specifies if header contains state root.
	StateRootEnabled bool
	// PrevStateRoot is state root of the previous block.
	PrevStateRoot util.Uint256
	// contains filtered or unexported fields
}

Base holds the base info of a block

func (*Base) DecodeBinary

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

DecodeBinary implements Serializable interface.

func (*Base) EncodeBinary

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

EncodeBinary implements Serializable interface

func (*Base) GetSignedHash added in v0.92.0

func (b *Base) GetSignedHash() util.Uint256

GetSignedHash returns a hash of the block used to verify it.

func (*Base) GetSignedPart added in v0.90.0

func (b *Base) GetSignedPart() []byte

GetSignedPart returns serialized hashable data of the block.

func (*Base) Hash

func (b *Base) Hash() util.Uint256

Hash returns the hash of the block.

func (Base) MarshalJSON added in v0.75.0

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

MarshalJSON implements json.Marshaler interface.

func (*Base) UnmarshalJSON added in v0.75.0

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

UnmarshalJSON implements json.Unmarshaler interface.

type Block

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

	// Primary index and nonce
	ConsensusData ConsensusData `json:"consensusdata"`

	// 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 added in v0.90.0

func New(network netmode.Magic, stateRootEnabled bool) *Block

New creates a new blank block tied to the specific network.

func NewBlockFromTrimmedBytes

func NewBlockFromTrimmedBytes(network netmode.Magic, stateRootEnabled bool, b []byte) (*Block, error)

NewBlockFromTrimmedBytes 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) Compare

func (b *Block) Compare(item queue.Item) int

Compare implements the queue Item interface.

func (*Block) ComputeMerkleRoot added in v0.92.0

func (b *Block) ComputeMerkleRoot() util.Uint256

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

func (b *Block) Header() *Header

Header returns the Header of the Block.

func (Block) MarshalJSON added in v0.75.0

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

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

Trim returns a subset of the block data to save up space in storage. Notice that only the hashes of the transactions are stored.

func (*Block) UnmarshalJSON added in v0.75.0

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

UnmarshalJSON implements json.Unmarshaler interface.

type ConsensusData added in v0.90.0

type ConsensusData struct {
	// Primary index
	PrimaryIndex uint32
	// Random number
	Nonce uint64
	// contains filtered or unexported fields
}

ConsensusData represents primary index and nonce of block in the chain.

func (*ConsensusData) DecodeBinary added in v0.90.0

func (c *ConsensusData) DecodeBinary(br *io.BinReader)

DecodeBinary implements Serializable interface.

func (*ConsensusData) EncodeBinary added in v0.90.0

func (c *ConsensusData) EncodeBinary(bw *io.BinWriter)

EncodeBinary encodes implements Serializable interface.

func (*ConsensusData) Hash added in v0.90.0

func (c *ConsensusData) Hash() util.Uint256

Hash returns the hash of the consensus data.

func (ConsensusData) MarshalJSON added in v0.90.0

func (c ConsensusData) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*ConsensusData) UnmarshalJSON added in v0.90.0

func (c *ConsensusData) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface.

type Header struct {
	// Base of the block.
	Base
}

Header holds the head info of a block.

func (*Header) DecodeBinary

func (h *Header) DecodeBinary(r *io.BinReader)

DecodeBinary implements Serializable interface.

func (*Header) EncodeBinary

func (h *Header) EncodeBinary(w *io.BinWriter)

EncodeBinary implements Serializable interface.

Jump to

Keyboard shortcuts

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