block

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2018 License: LGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

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

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

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

Beneficiary returns reward recipient.

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() (signer thor.Address, err 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 afert 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) TxsRoot

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

TxsRoot returns merkle root of txs contained in this block.

type Raw

type Raw []byte

Raw allows to partially decode components of a block.

func (Raw) DecodeBody

func (r Raw) DecodeBody() (*Body, error)

DecodeBody decode only the body.

func (Raw) DecodeHeader

func (r Raw) DecodeHeader() (*Header, error)

DecodeHeader decode only the header.

Jump to

Keyboard shortcuts

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