block

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: LGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ComplexSigSize = 81 + 65
)

Variables

This section is empty.

Functions

func Number

func Number(blockID thor.Bytes32) uint32

Number extract block number from block id.

Types

type Block

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

Block is an immutable block type.

func Compose

func Compose(header *Header, txs tx.Transactions) *Block

Compose compose a block with all needed components Note: This method is usually to recover a block by its portions, and the TxsRoot is not verified. To build up a block, use a Builder.

func (*Block) Body

func (b *Block) Body() *Body

Body returns body of a block.

func (*Block) DecodeRLP

func (b *Block) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder.

func (*Block) EncodeRLP

func (b *Block) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

func (*Block) Header

func (b *Block) Header() *Header

Header returns the block header.

func (*Block) Size

func (b *Block) Size() metric.StorageSize

Size returns block size in bytes.

func (*Block) String

func (b *Block) String() string

func (*Block) Transactions

func (b *Block) Transactions() tx.Transactions

Transactions returns a copy of transactions.

func (*Block) WithSignature

func (b *Block) WithSignature(sig []byte) *Block

WithSignature create a new block object with signature set.

type Body

type Body struct {
	Txs tx.Transactions
}

Body defines body of a block.

type Builder

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

Builder to make it easy to build a block object.

func (*Builder) Alpha

func (b *Builder) Alpha(alpha []byte) *Builder

Alpha set the alpha.

func (*Builder) Beneficiary

func (b *Builder) Beneficiary(addr thor.Address) *Builder

Beneficiary set recipient of reward.

func (*Builder) Build

func (b *Builder) Build() *Block

Build build a block object.

func (*Builder) COM

func (b *Builder) COM() *Builder

COM enables COM.

func (*Builder) GasLimit

func (b *Builder) GasLimit(limit uint64) *Builder

GasLimit set gas limit.

func (*Builder) GasUsed

func (b *Builder) GasUsed(used uint64) *Builder

GasUsed set gas used.

func (*Builder) ParentID

func (b *Builder) ParentID(id thor.Bytes32) *Builder

ParentID set parent id.

func (*Builder) ReceiptsRoot

func (b *Builder) ReceiptsRoot(hash thor.Bytes32) *Builder

ReceiptsRoot set receipts root.

func (*Builder) StateRoot

func (b *Builder) StateRoot(hash thor.Bytes32) *Builder

StateRoot set state root.

func (*Builder) Timestamp

func (b *Builder) Timestamp(ts uint64) *Builder

Timestamp set timestamp.

func (*Builder) TotalScore

func (b *Builder) TotalScore(score uint64) *Builder

TotalScore set total score.

func (*Builder) Transaction

func (b *Builder) Transaction(tx *tx.Transaction) *Builder

Transaction add a transaction.

func (*Builder) TransactionFeatures

func (b *Builder) TransactionFeatures(features tx.Features) *Builder

TransactionFeatures set supported transaction features

type ComplexSignature

type ComplexSignature []byte

ComplexSignature is the signature composed by[ECDSA(Secp256k1) Signature(65 bytes)+VRF Proof(81 bytes)]

func NewComplexSignature

func NewComplexSignature(signature, proof []byte) (ComplexSignature, error)

NewComplexSignature creates a new signature.

func (ComplexSignature) Proof

func (ms ComplexSignature) Proof() []byte

Proof returns the VRF proof.

func (ComplexSignature) Signature

func (ms ComplexSignature) Signature() []byte

Signature returns the ECDSA signature.

type GasLimit

type GasLimit uint64

GasLimit to support block gas limit validation and adjustment.

func (GasLimit) Adjust

func (gl GasLimit) Adjust(delta int64) uint64

Adjust suppose the receiver is parent gas limit, and calculate a valid gas limit value by apply `delta`.

func (GasLimit) IsValid

func (gl GasLimit) IsValid(parentGasLimit uint64) bool

IsValid returns if the receiver is valid according to parent gas limit.

func (GasLimit) Qualify

func (gl GasLimit) Qualify(parentGasLimit uint64) uint64

Qualify qualify the receiver according to parent gas limit, and returns the qualified gas limit value.

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

Header contains almost all information about a block, except block body. It's immutable.

func (*Header) Alpha

func (h *Header) Alpha() []byte

Alpha returns the alpha in the header.

func (*Header) Beneficiary

func (h *Header) Beneficiary() thor.Address

Beneficiary returns reward recipient.

func (*Header) Beta

func (h *Header) Beta() (beta []byte, err error)

Beta verifies the VRF proof in header's signature and returns the beta.

func (*Header) BetterThan

func (h *Header) BetterThan(other *Header) bool

BetterThan return if this block is better than other one.

func (*Header) COM

func (h *Header) COM() bool

COM returns whether the packer votes COM.

func (*Header) DecodeRLP

func (h *Header) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder.

func (*Header) EncodeRLP

func (h *Header) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder

func (*Header) GasLimit

func (h *Header) GasLimit() uint64

GasLimit returns gas limit of this block.

func (*Header) GasUsed

func (h *Header) GasUsed() uint64

GasUsed returns gas used by txs.

func (*Header) ID

func (h *Header) ID() (id thor.Bytes32)

ID computes id of block. The block ID is defined as: blockNumber + hash(signingHash, signer)[4:].

func (*Header) Number

func (h *Header) Number() uint32

Number returns sequential number of this block.

func (*Header) ParentID

func (h *Header) ParentID() thor.Bytes32

ParentID returns id of parent block.

func (*Header) ReceiptsRoot

func (h *Header) ReceiptsRoot() thor.Bytes32

ReceiptsRoot returns merkle root of tx receipts.

func (*Header) Signature

func (h *Header) Signature() []byte

Signature returns signature.

func (*Header) Signer

func (h *Header) Signer() (thor.Address, error)

Signer extract signer of the block from signature.

func (*Header) SigningHash

func (h *Header) SigningHash() (hash thor.Bytes32)

SigningHash computes hash of all header fields excluding signature.

func (*Header) StateRoot

func (h *Header) StateRoot() thor.Bytes32

StateRoot returns account state merkle root just after this block being applied.

func (*Header) String

func (h *Header) String() string

func (*Header) Timestamp

func (h *Header) Timestamp() uint64

Timestamp returns timestamp of this block.

func (*Header) TotalScore

func (h *Header) TotalScore() uint64

TotalScore returns total score that cumulated from genesis block to this one.

func (*Header) TxsFeatures

func (h *Header) TxsFeatures() tx.Features

TxsFeatures returns supported txs features.

func (*Header) TxsRoot

func (h *Header) TxsRoot() thor.Bytes32

TxsRoot returns merkle root of txs contained in this block.

Jump to

Keyboard shortcuts

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