block

package
v0.107.2 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 12 Imported by: 16

Documentation

Overview

Package block contains Neo block definition.

This is one of the core structures of Neo blockchain.

Index

Constants

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

VersionInitial is the default Neo block version.

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 (with a proper
	// header and hashes-only transactions). Not a part of a real
	// block and is used only by internal packages.
	Trimmed bool
}

Block represents one block in the chain.

func New added in v0.90.0

func New(stateRootEnabled bool) *Block

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

func NewTrimmedFromReader added in v0.98.1

func NewTrimmedFromReader(stateRootEnabled bool, 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 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) EncodeTrimmed added in v0.98.2

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

func (b *Block) GetExpectedBlockSize() int

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

func (*Block) GetExpectedBlockSizeWithoutTransactions added in v0.94.0

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

GetExpectedBlockSizeWithoutTransactions returns the expected block size without transactions size.

func (Block) MarshalJSON added in v0.75.0

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

MarshalJSON implements the json.Marshaler interface.

func (*Block) RebuildMerkleRoot

func (b *Block) RebuildMerkleRoot()

RebuildMerkleRoot rebuilds the merkleroot of the block.

func (*Block) ToStackItem added in v0.99.1

func (b *Block) ToStackItem() stackitem.Item

ToStackItem converts Block to stackitem.Item.

func (*Block) UnmarshalJSON added in v0.75.0

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

UnmarshalJSON implements the json.Unmarshaler interface.

type Header struct {
	// Version of the block, currently only 0.
	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 the previous block's time stamp.
	// Generally, the difference between two block's time stamps 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 util.Uint160

	// Witness scripts used for block validation. These scripts
	// are not a part of a hashable field set.
	Script transaction.Witness

	// StateRootEnabled specifies if the header contains state root.
	// It's NeoGo-specific, and is not a part of a standard Neo N3 header,
	// it's also never serialized into P2P payload. When it's false
	// PrevStateRoot is always zero, when true it works as intended.
	StateRootEnabled bool
	// PrevStateRoot is the state root of the previous block. This field
	// is relevant only if StateRootEnabled is true which is a
	// NeoGo-specific extension of the protocol.
	PrevStateRoot util.Uint256
	// PrimaryIndex is the index of the primary consensus node for this block.
	PrimaryIndex byte
	// contains filtered or unexported fields
}

Header holds the base info of a block. Fields follow the P2P format of the N3 block header unless noted specifically.

func (*Header) DecodeBinary

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

DecodeBinary implements the io.Serializable interface. Notice that it also automatically updates the internal hash cache, see Header.Hash.

func (*Header) EncodeBinary

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

EncodeBinary implements the Serializable interface.

func (*Header) Hash added in v0.94.0

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

Hash returns the hash of the block. Notice that it is cached internally, so no matter how you change the Header after the first invocation of this method it won't change. To get an updated hash in case you're changing the Header please encode/decode it.

func (Header) MarshalJSON added in v0.94.0

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

MarshalJSON implements the json.Marshaler interface.

func (*Header) UnmarshalJSON added in v0.94.0

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

UnmarshalJSON implements the json.Unmarshaler interface.

Jump to

Keyboard shortcuts

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