block

package
v1.22.61 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package block implements block structure for the DEX VM.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBlockTooLarge    = errors.New("block exceeds maximum size")
	ErrTooManyTxs       = errors.New("block contains too many transactions")
	ErrInvalidBlockTime = errors.New("invalid block timestamp")
	ErrInvalidParent    = errors.New("invalid parent block")
	ErrBlockNotVerified = errors.New("block not verified")
)

Functions

This section is empty.

Types

type Block

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

Block represents a block in the DEX VM.

func NewBlock

func NewBlock(
	parentID ids.ID,
	height uint64,
	timestamp int64,
	transactions []txs.Tx,
	producer ids.NodeID,
) *Block

NewBlock creates a new block.

func (*Block) Accept

func (b *Block) Accept(ctx context.Context) error

Accept marks the block as accepted.

func (*Block) Bytes

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

Bytes returns the serialized block.

func (*Block) Height

func (b *Block) Height() uint64

Height returns the block height.

func (*Block) ID

func (b *Block) ID() ids.ID

ID returns the block's unique identifier.

func (*Block) Parent

func (b *Block) Parent() ids.ID

Parent returns the parent block ID.

func (*Block) Producer

func (b *Block) Producer() ids.NodeID

Producer returns the node that produced this block.

func (*Block) Reject

func (b *Block) Reject(ctx context.Context) error

Reject marks the block as rejected.

func (*Block) SetStatus

func (b *Block) SetStatus(status Status)

SetStatus sets the verification status.

func (*Block) StateRoot

func (b *Block) StateRoot() ids.ID

StateRoot returns the state root after applying this block.

func (*Block) Status

func (b *Block) Status() Status

Status returns the verification status.

func (*Block) Timestamp

func (b *Block) Timestamp() time.Time

Timestamp returns the block timestamp.

func (*Block) TimestampNano

func (b *Block) TimestampNano() int64

TimestampNano returns the block timestamp in nanoseconds.

func (*Block) Transactions

func (b *Block) Transactions() []txs.Tx

Transactions returns the transactions in the block.

func (*Block) TxCount

func (b *Block) TxCount() int

TxCount returns the number of transactions in the block.

func (*Block) TxRoot

func (b *Block) TxRoot() ids.ID

TxRoot returns the merkle root of transactions.

func (*Block) Verify

func (b *Block) Verify(ctx context.Context) error

Verify verifies the block's validity.

type BlockParser

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

BlockParser parses blocks from bytes.

func NewBlockParser

func NewBlockParser() *BlockParser

NewBlockParser creates a new block parser.

func (*BlockParser) Parse

func (p *BlockParser) Parse(data []byte) (*Block, error)

Parse parses a block from bytes.

type Builder

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

Builder builds new blocks.

func NewBuilder

func NewBuilder(parentID ids.ID, height uint64, maxBlockSize uint64, maxTxsPerBlock uint32) *Builder

NewBuilder creates a new block builder.

func (*Builder) AddTx

func (b *Builder) AddTx(tx txs.Tx) error

AddTx adds a transaction to the pending block.

func (*Builder) Build

func (b *Builder) Build(producer ids.NodeID) *Block

Build builds the block.

func (*Builder) Clear

func (b *Builder) Clear(parentID ids.ID, height uint64)

Clear clears the builder for reuse.

func (*Builder) CurrentSize

func (b *Builder) CurrentSize() uint64

CurrentSize returns the current block size.

func (*Builder) TxCount

func (b *Builder) TxCount() int

TxCount returns the number of pending transactions.

type Status

type Status uint8

Status represents the verification status of a block.

const (
	StatusPending Status = iota
	StatusProcessing
	StatusAccepted
	StatusRejected
)

func (Status) String

func (s Status) String() string

Jump to

Keyboard shortcuts

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