block

package
v1.13.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: Apache-2.0 Imports: 19 Imported by: 33

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTxRootMismatch      = errors.New("transaction merkle root does not match")
	ErrDeltaStateMismatch  = errors.New("delta state digest doesn't match")
	ErrReceiptRootMismatch = errors.New("receipt root hash does not match")
)

Errors

Functions

func DeserializeBlockStoresPb added in v1.1.2

func DeserializeBlockStoresPb(buf []byte) (*iotextypes.BlockStores, error)

DeserializeBlockStoresPb decode byte stream into BlockStores pb message

func DeserializeSystemLogPb added in v1.1.0

func DeserializeSystemLogPb(buf []byte) (*iotextypes.TransactionLogs, error)

DeserializeSystemLogPb parse the byte stream into TransactionLogs Pb message

func GenesisHash added in v1.2.0

func GenesisHash() hash.Hash256

GenesisHash returns the genesis block's hash

func LoadGenesisHash added in v1.2.0

func LoadGenesisHash(g *genesis.Genesis)

LoadGenesisHash is done once to compute and save the genesis'es hash

Types

type BlkTransactionLog added in v1.1.0

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

BlkTransactionLog is transaction log in one block

func (*BlkTransactionLog) Serialize added in v1.1.0

func (log *BlkTransactionLog) Serialize() []byte

Serialize returns a serialized byte stream for BlkTransactionLog

type Block

type Block struct {
	Header
	Body
	Footer

	// TODO: move receipts out of block struct
	Receipts []*action.Receipt
}

Block defines the struct of block

func GenesisBlock added in v1.2.0

func GenesisBlock() *Block

GenesisBlock returns the genesis block

func NewBlockDeprecated

func NewBlockDeprecated(
	chainID uint32,
	height uint64,
	prevBlockHash hash.Hash256,
	timestamp time.Time,
	producer crypto.PublicKey,
	actions []action.SealedEnvelope,
) *Block

NewBlockDeprecated returns a new block This method is deprecated. Only used in old tests.

func (*Block) ConvertToBlockPb

func (b *Block) ConvertToBlockPb() *iotextypes.Block

ConvertToBlockPb converts Block to Block

func (*Block) Finalize

func (b *Block) Finalize(endorsements []*endorsement.Endorsement, ts time.Time) error

Finalize creates a footer for the block

func (*Block) RunnableActions

func (b *Block) RunnableActions() RunnableActions

RunnableActions abstructs RunnableActions from a Block.

func (*Block) Serialize

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

Serialize returns the serialized byte stream of the block

func (*Block) TransactionLog added in v1.1.0

func (b *Block) TransactionLog() *BlkTransactionLog

TransactionLog returns transaction logs in the block

func (*Block) VerifyTxRoot added in v1.1.2

func (b *Block) VerifyTxRoot() error

VerifyTxRoot verifies the transaction root hash

type Body added in v0.5.0

type Body struct {
	Actions []action.SealedEnvelope
}

Body defines the struct of body

func (*Body) CalculateTransferAmount added in v0.9.0

func (b *Body) CalculateTransferAmount() *big.Int

CalculateTransferAmount returns the calculated transfer amount in this block.

func (*Body) CalculateTxRoot added in v0.5.0

func (b *Body) CalculateTxRoot() (hash.Hash256, error)

CalculateTxRoot returns the Merkle root of all txs and actions in this block.

func (*Body) Proto added in v0.5.0

func (b *Body) Proto() *iotextypes.BlockBody

Proto converts Body to Protobuf

func (*Body) Serialize added in v0.5.0

func (b *Body) Serialize() ([]byte, error)

Serialize returns the serialized byte stream of the block

type Builder

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

Builder is used to construct Block.

func NewBuilder

func NewBuilder(ra RunnableActions) *Builder

NewBuilder creates a Builder.

func (*Builder) GetCurrentBlockHeader added in v0.11.0

func (b *Builder) GetCurrentBlockHeader() Header

GetCurrentBlockHeader returns the current hash of Block Header Core

func (*Builder) SetDeltaStateDigest

func (b *Builder) SetDeltaStateDigest(h hash.Hash256) *Builder

SetDeltaStateDigest sets the new delta state digest after running actions included in this building block

func (*Builder) SetHeight added in v0.11.0

func (b *Builder) SetHeight(h uint64) *Builder

SetHeight sets the block height

func (*Builder) SetLogsBloom added in v0.7.1

func (b *Builder) SetLogsBloom(f bloom.BloomFilter) *Builder

SetLogsBloom sets the logs bloom filter value after running actions included in this building block.

func (*Builder) SetPrevBlockHash

func (b *Builder) SetPrevBlockHash(h hash.Hash256) *Builder

SetPrevBlockHash sets the previous block hash for block which is building.

func (*Builder) SetReceiptRoot

func (b *Builder) SetReceiptRoot(h hash.Hash256) *Builder

SetReceiptRoot sets the receipt root after running actions included in this building block.

func (*Builder) SetReceipts

func (b *Builder) SetReceipts(receipts []*action.Receipt) *Builder

SetReceipts sets the receipts after running actions included in this building block.

func (*Builder) SetTimestamp added in v0.11.0

func (b *Builder) SetTimestamp(ts time.Time) *Builder

SetTimestamp sets the block timestamp

func (*Builder) SetVersion

func (b *Builder) SetVersion(v uint32) *Builder

SetVersion sets the protocol version for block which is building.

func (*Builder) SignAndBuild

func (b *Builder) SignAndBuild(signerPrvKey crypto.PrivateKey) (Block, error)

SignAndBuild signs and then builds a block.

type Deserializer added in v1.8.0

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

Deserializer de-serializes a block

It's a wrapper to set certain parameters in order to correctly de-serialize a block Currently the parameter is EVM network ID for tx in web3 format, it is called like

blk, err := (&Deserializer{}).SetEvmNetworkID(id).FromBlockProto(pbBlock) blk, err := (&Deserializer{}).SetEvmNetworkID(id).DeserializeBlock(buf)

func NewDeserializer added in v1.8.2

func NewDeserializer(evmNetworkID uint32) *Deserializer

NewDeserializer creates a new deserializer

func (*Deserializer) DeserializeBlock added in v1.8.0

func (bd *Deserializer) DeserializeBlock(buf []byte) (*Block, error)

DeserializeBlock de-serializes a block

func (*Deserializer) DeserializeBlockStore added in v1.8.2

func (bd *Deserializer) DeserializeBlockStore(buf []byte) (*Store, error)

DeserializeBlockStore de-serializes a block store

func (*Deserializer) DeserializeBody added in v1.8.0

func (bd *Deserializer) DeserializeBody(buf []byte) (*Body, error)

DeserializeBody de-serializes a block body

func (*Deserializer) EvmNetworkID added in v1.8.2

func (bd *Deserializer) EvmNetworkID() uint32

EvmNetworkID get evm network ID

func (*Deserializer) FromBlockProto added in v1.8.0

func (bd *Deserializer) FromBlockProto(pbBlock *iotextypes.Block) (*Block, error)

FromBlockProto converts protobuf to block

func (*Deserializer) FromBlockStoreProto added in v1.8.2

func (bd *Deserializer) FromBlockStoreProto(pb *iotextypes.BlockStore) (*Store, error)

FromBlockStoreProto converts protobuf to block store

func (*Deserializer) SetEvmNetworkID added in v1.8.2

func (bd *Deserializer) SetEvmNetworkID(id uint32) *Deserializer

SetEvmNetworkID sets the evm network ID for web3 actions

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

Footer defines a set of proof of this block

func (*Footer) CommitTime

func (f *Footer) CommitTime() time.Time

CommitTime returns the timestamp the block was committed

func (*Footer) ConvertFromBlockFooterPb

func (f *Footer) ConvertFromBlockFooterPb(pb *iotextypes.BlockFooter) error

ConvertFromBlockFooterPb converts BlockFooter to BlockFooter

func (*Footer) ConvertToBlockFooterPb

func (f *Footer) ConvertToBlockFooterPb() (*iotextypes.BlockFooter, error)

ConvertToBlockFooterPb converts BlockFooter

func (*Footer) Deserialize added in v0.5.0

func (f *Footer) Deserialize(buf []byte) error

Deserialize loads from the serialized byte stream

func (*Footer) Endorsements added in v0.5.0

func (f *Footer) Endorsements() []*endorsement.Endorsement

Endorsements returns the number of commit endorsements froms delegates

func (*Footer) Serialize added in v0.5.0

func (f *Footer) Serialize() ([]byte, error)

Serialize returns the serialized byte stream of the block footer

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

Header defines the struct of block header make sure the variable type and order of this struct is same as "BlockHeaderPb" in blockchain.pb.go

func (*Header) BlockHeaderCoreProto added in v0.5.0

func (h *Header) BlockHeaderCoreProto() *iotextypes.BlockHeaderCore

BlockHeaderCoreProto returns BlockHeaderCore proto.

func (*Header) DeltaStateDigest

func (h *Header) DeltaStateDigest() hash.Hash256

DeltaStateDigest returns the delta sate digest after applying this block.

func (*Header) Deserialize added in v0.5.0

func (h *Header) Deserialize(buf []byte) error

Deserialize loads from the serialized byte stream

func (*Header) HashBlock added in v0.5.0

func (h *Header) HashBlock() hash.Hash256

HashBlock return the hash of this block (actually hash of block header)

func (*Header) HashHeader added in v0.5.0

func (h *Header) HashHeader() hash.Hash256

HashHeader hashes the header

func (*Header) HashHeaderCore added in v0.5.0

func (h *Header) HashHeaderCore() hash.Hash256

HashHeaderCore hahes the header core.

func (*Header) HeaderLogger

func (h *Header) HeaderLogger(l *zap.Logger) *zap.Logger

HeaderLogger returns a new logger with block header fields' value.

func (*Header) Height

func (h *Header) Height() uint64

Height returns the height of this block.

func (*Header) LoadFromBlockHeaderProto added in v0.5.0

func (h *Header) LoadFromBlockHeaderProto(pb *iotextypes.BlockHeader) error

LoadFromBlockHeaderProto loads from protobuf

func (*Header) LogsBloomfilter added in v0.7.1

func (h *Header) LogsBloomfilter() bloom.BloomFilter

LogsBloomfilter return the bloom filter for all contract log events

func (*Header) PrevHash

func (h *Header) PrevHash() hash.Hash256

PrevHash returns the hash of prev block.

func (*Header) ProducerAddress added in v0.5.0

func (h *Header) ProducerAddress() string

ProducerAddress returns the address of producer

func (*Header) Proto added in v1.10.0

func (h *Header) Proto() *iotextypes.BlockHeader

Proto returns BlockHeader proto.

func (*Header) PublicKey

func (h *Header) PublicKey() crypto.PublicKey

PublicKey returns the public key of this header.

func (*Header) ReceiptRoot

func (h *Header) ReceiptRoot() hash.Hash256

ReceiptRoot returns the receipt root after apply this block

func (*Header) Serialize added in v0.5.0

func (h *Header) Serialize() ([]byte, error)

Serialize returns the serialized byte stream of the block header

func (*Header) SerializeCore added in v0.7.1

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

SerializeCore returns byte stream for header core.

func (*Header) Timestamp

func (h *Header) Timestamp() time.Time

Timestamp returns the Timestamp of this block.

func (*Header) TxRoot

func (h *Header) TxRoot() hash.Hash256

TxRoot returns the hash of all actions in this block.

func (*Header) VerifyDeltaStateDigest added in v1.7.1

func (h *Header) VerifyDeltaStateDigest(digest hash.Hash256) bool

VerifyDeltaStateDigest verifies the delta state digest in header

func (*Header) VerifyReceiptRoot added in v1.7.1

func (h *Header) VerifyReceiptRoot(root hash.Hash256) bool

VerifyReceiptRoot verifies the receipt root in header

func (*Header) VerifySignature added in v0.5.0

func (h *Header) VerifySignature() bool

VerifySignature verifies the signature saved in block header

func (*Header) VerifyTransactionRoot added in v1.7.1

func (h *Header) VerifyTransactionRoot(root hash.Hash256) bool

VerifyTransactionRoot verifies the delta state digest in header

func (*Header) Version

func (h *Header) Version() uint32

Version returns the version of this block.

type RunnableActions

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

RunnableActions is abstructed from block which contains information to execute all actions in a block.

func (RunnableActions) Actions

func (ra RunnableActions) Actions() []action.SealedEnvelope

Actions returns Actions.

func (RunnableActions) TxHash

func (ra RunnableActions) TxHash() hash.Hash256

TxHash returns TxHash.

type RunnableActionsBuilder

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

RunnableActionsBuilder is used to construct RunnableActions.

func NewRunnableActionsBuilder

func NewRunnableActionsBuilder() *RunnableActionsBuilder

NewRunnableActionsBuilder creates a RunnableActionsBuilder.

func (*RunnableActionsBuilder) AddActions

AddActions adds actions for block which is building.

func (*RunnableActionsBuilder) Build

Build signs and then builds a block.

type Store added in v1.1.2

type Store struct {
	Block    *Block
	Receipts []*action.Receipt
}

Store defines block storage schema

func (*Store) Serialize added in v1.1.2

func (in *Store) Serialize() ([]byte, error)

Serialize returns the serialized byte stream of Store

func (*Store) ToProto added in v1.1.2

func (in *Store) ToProto() *iotextypes.BlockStore

ToProto converts to proto message

type TestingBuilder

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

TestingBuilder is used to construct Block.

func NewTestingBuilder

func NewTestingBuilder() *TestingBuilder

NewTestingBuilder creates a Builder.

func (*TestingBuilder) AddActions

func (b *TestingBuilder) AddActions(acts ...action.SealedEnvelope) *TestingBuilder

AddActions adds actions for block which is building.

func (*TestingBuilder) SetHeight

func (b *TestingBuilder) SetHeight(h uint64) *TestingBuilder

SetHeight sets the block height for block which is building.

func (*TestingBuilder) SetPrevBlockHash

func (b *TestingBuilder) SetPrevBlockHash(h hash.Hash256) *TestingBuilder

SetPrevBlockHash sets the previous block hash for block which is building.

func (*TestingBuilder) SetReceipts

func (b *TestingBuilder) SetReceipts(receipts []*action.Receipt) *TestingBuilder

SetReceipts sets the receipts after running actions included in this building block.

func (*TestingBuilder) SetTimeStamp

func (b *TestingBuilder) SetTimeStamp(ts time.Time) *TestingBuilder

SetTimeStamp sets the time stamp for block which is building.

func (*TestingBuilder) SetVersion

func (b *TestingBuilder) SetVersion(v uint32) *TestingBuilder

SetVersion sets the protocol version for block which is building.

func (*TestingBuilder) SignAndBuild

func (b *TestingBuilder) SignAndBuild(signerPrvKey crypto.PrivateKey) (Block, error)

SignAndBuild signs and then builds a block.

type TokenTxRecord added in v1.1.0

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

TokenTxRecord is a token transaction record

func LogTokenTxRecord added in v1.1.0

func LogTokenTxRecord(l *action.TransactionLog) *TokenTxRecord

LogTokenTxRecord generates token transaction record from log

func NewTokenTxRecord added in v1.1.0

func NewTokenTxRecord(typ iotextypes.TransactionLogType, amount, sender, recipient string) *TokenTxRecord

NewTokenTxRecord creates a new TokenTxRecord

type TransactionLog added in v1.1.0

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

TransactionLog is transaction log in one action

func NewTransactionLog added in v1.1.0

func NewTransactionLog(actHash hash.Hash256, records []*TokenTxRecord) *TransactionLog

NewTransactionLog creates a new TransactionLog

func ReceiptTransactionLog added in v1.1.0

func ReceiptTransactionLog(r *action.Receipt) *TransactionLog

ReceiptTransactionLog generates transaction log from receipt

func (*TransactionLog) Proto added in v1.1.0

Proto returns the pb message

type Validator added in v0.11.0

type Validator interface {
	// Validate validates the given block's content
	Validate(ctx context.Context, block *Block) error
}

Validator is the interface of validator

func NewValidator added in v0.11.0

func NewValidator(subsequenceValidator Validator, validators ...action.SealedEnvelopeValidator) Validator

NewValidator creates a validator with a set of sealed envelope validators

Jump to

Keyboard shortcuts

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