block

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2019 License: Apache-2.0 Imports: 19 Imported by: 33

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Header
	Footer

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

	WorkingSet factory.WorkingSet
}

Block defines the struct of block

func NewBlockDeprecated

func NewBlockDeprecated(
	chainID uint32,
	height uint64,
	prevBlockHash hash.Hash32B,
	timestamp int64,
	producer keypair.PublicKey,
	actions []action.SealedEnvelope,
) *Block

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

func (*Block) ByteStream

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

ByteStream returns a byte stream of the block

func (*Block) CalculateTxRoot

func (b *Block) CalculateTxRoot() hash.Hash32B

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

func (*Block) ConvertFromBlockHeaderPb

func (b *Block) ConvertFromBlockHeaderPb(pbBlock *iproto.BlockPb)

ConvertFromBlockHeaderPb converts BlockHeaderPb to BlockHeader

func (*Block) ConvertFromBlockPb

func (b *Block) ConvertFromBlockPb(pbBlock *iproto.BlockPb) error

ConvertFromBlockPb converts BlockPb to Block

func (*Block) ConvertToBlockHeaderPb

func (b *Block) ConvertToBlockHeaderPb() *iproto.BlockHeaderPb

ConvertToBlockHeaderPb converts BlockHeader to BlockHeaderPb

func (*Block) ConvertToBlockPb

func (b *Block) ConvertToBlockPb() *iproto.BlockPb

ConvertToBlockPb converts Block to BlockPb

func (*Block) Deserialize

func (b *Block) Deserialize(buf []byte) error

Deserialize parses the byte stream into a Block

func (*Block) Finalize

func (b *Block) Finalize(set *endorsement.Set, ts time.Time) error

Finalize creates a footer for the block

func (*Block) FooterLogger

func (b *Block) FooterLogger(l *zap.Logger) *zap.Logger

FooterLogger logs the endorsements in block footer

func (*Block) HashBlock

func (b *Block) HashBlock() hash.Hash32B

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

func (*Block) ProducerAddress

func (b *Block) ProducerAddress() string

ProducerAddress returns the address of producer

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

func (b *Block) VerifyDeltaStateDigest(digest hash.Hash32B) error

VerifyDeltaStateDigest verifies the delta state digest in header

func (*Block) VerifyReceiptRoot

func (b *Block) VerifyReceiptRoot(root hash.Hash32B) error

VerifyReceiptRoot verifies the receipt root in header

func (*Block) VerifySignature

func (b *Block) VerifySignature() bool

VerifySignature verifies the signature saved in block header

func (*Block) VerifyStateRoot

func (b *Block) VerifyStateRoot(root hash.Hash32B) error

VerifyStateRoot verifies the state root in header

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

func (b *Builder) SetChainID(c uint32) *Builder

SetChainID sets the chain id for block which is building.

func (*Builder) SetDeltaStateDigest

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

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

func (*Builder) SetPrevBlockHash

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

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

func (*Builder) SetReceiptRoot

func (b *Builder) SetReceiptRoot(h hash.Hash32B) *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) SetStateRoot

func (b *Builder) SetStateRoot(h hash.Hash32B) *Builder

SetStateRoot sets the new state root after running actions included in this building block.

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(signerPubKey keypair.PublicKey, signerPriKey keypair.PrivateKey) (Block, error)

SignAndBuild signs and then builds a block.

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

Footer defines a set of proof of this block

func (*Footer) CommitTime

func (f *Footer) CommitTime() int64

CommitTime returns the timestamp the block was committed

func (*Footer) ConvertFromBlockFooterPb

func (f *Footer) ConvertFromBlockFooterPb(pb *iproto.BlockFooterPb) error

ConvertFromBlockFooterPb converts BlockFooterPb to BlockFooter

func (*Footer) ConvertToBlockFooterPb

func (f *Footer) ConvertToBlockFooterPb() *iproto.BlockFooterPb

ConvertToBlockFooterPb converts BlockFooterPb

func (*Footer) NumOfDelegateEndorsements

func (f *Footer) NumOfDelegateEndorsements(delegates []string) int

NumOfDelegateEndorsements returns the number of commit endorsements froms delegates

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

func (h Header) ByteStream() []byte

ByteStream returns a byte stream of the header.

func (Header) ChainID

func (h Header) ChainID() uint32

ChainID returns the chain id of this block.

func (Header) DeltaStateDigest

func (h Header) DeltaStateDigest() hash.Hash32B

DeltaStateDigest returns the delta sate digest after applying this block.

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

func (h Header) PrevHash() hash.Hash32B

PrevHash returns the hash of prev block.

func (Header) PublicKey

func (h Header) PublicKey() keypair.PublicKey

PublicKey returns the public key of this header.

func (Header) ReceiptRoot

func (h Header) ReceiptRoot() hash.Hash32B

ReceiptRoot returns the receipt root after apply this block

func (Header) StateRoot

func (h Header) StateRoot() hash.Hash32B

StateRoot returns the state root after applying this block.

func (Header) Timestamp

func (h Header) Timestamp() int64

Timestamp returns the Timestamp of this block.

func (Header) TxRoot

func (h Header) TxRoot() hash.Hash32B

TxRoot returns the hash of all actions in this block.

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

func (ra RunnableActions) BlockHeight() uint64

BlockHeight returns block height.

func (RunnableActions) BlockProducerAddr

func (ra RunnableActions) BlockProducerAddr() string

BlockProducerAddr returns BlockProducerAddr.

func (RunnableActions) BlockProducerPubKey

func (ra RunnableActions) BlockProducerPubKey() keypair.PublicKey

BlockProducerPubKey return BlockProducerPubKey.

func (RunnableActions) BlockTimeStamp

func (ra RunnableActions) BlockTimeStamp() int64

BlockTimeStamp returns blockTimeStamp.

func (RunnableActions) TxHash

func (ra RunnableActions) TxHash() hash.Hash32B

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

func (b *RunnableActionsBuilder) Build(producerAddr string, producerPubKey keypair.PublicKey) RunnableActions

Build signs and then builds a block.

func (*RunnableActionsBuilder) SetHeight

SetHeight sets the block height for block which is building.

func (*RunnableActionsBuilder) SetTimeStamp

SetTimeStamp sets the time stamp for block which is building.

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

func (b *TestingBuilder) SetChainID(c uint32) *TestingBuilder

SetChainID sets the chain id 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.Hash32B) *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) SetStateRoot

func (b *TestingBuilder) SetStateRoot(h hash.Hash32B) *TestingBuilder

SetStateRoot sets the new state root after running actions included in this building block.

func (*TestingBuilder) SetTimeStamp

func (b *TestingBuilder) SetTimeStamp(ts int64) *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(signerPubKey keypair.PublicKey, signerPriKey keypair.PrivateKey) (Block, error)

SignAndBuild signs and then builds a block.

Jump to

Keyboard shortcuts

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