block

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2019 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidHash      = id.Hash{}
	InvalidSignature = id.Signature{}
	InvalidSignatory = id.Signatory{}
	InvalidBlock     = Block{}
	InvalidRound     = Round(-1)
	InvalidHeight    = Height(-1)
)

Define some default invalid values.

Functions

func ComputeHash added in v0.2.0

func ComputeHash(header Header, txs Txs, plan Plan, prevState State) id.Hash

ComputeHash of a block basing on its header, data and previous state.

Types

type Block

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

A Block is the atomic unit upon which consensus is reached. Consensus guarantees a consistent ordering of Blocks that is agreed upon by all members in a distributed network, even when some of the members are malicious.

func New

func New(header Header, txs Txs, plan Plan, prevState State) Block

New Block with the Header, Txs, Plan, and State of the Block parent. The Block Hash will automatically be computed and set.

func (Block) Equal

func (block Block) Equal(other Block) bool

Equal compares one Block with another by checking that their Hashes are the equal, and their Notes are equal.

func (Block) Hash added in v0.2.0

func (block Block) Hash() id.Hash

Hash returns the 256-bit SHA2 Hash of the Header and Data.

func (Block) Header

func (block Block) Header() Header

Header of the Block.

func (Block) MarshalBinary added in v0.2.0

func (block Block) MarshalBinary() ([]byte, error)

MarshalBinary implements the `encoding.BinaryMarshaler` interface for the Block type.

func (Block) MarshalJSON added in v0.2.0

func (block Block) MarshalJSON() ([]byte, error)

MarshalJSON implements the `json.Marshaler` interface for the Block type.

func (Block) Plan added in v0.3.0

func (block Block) Plan() Plan

Plan embedded in the Block for application-specific purposes.

func (Block) PreviousState added in v0.2.0

func (block Block) PreviousState() State

PreviousState embedded in the Block for application-specific state after the execution of the Block parent.

func (Block) String

func (block Block) String() string

String implements the `fmt.Stringer` interface for the Block type.

func (Block) Txs

func (block Block) Txs() Txs

Txs embedded in the Block for application-specific purposes.

func (*Block) UnmarshalBinary added in v0.2.0

func (block *Block) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the `encoding.BinaryUnmarshaler` interface for the Block type.

func (*Block) UnmarshalJSON added in v0.2.0

func (block *Block) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the `json.Unmarshaler` interface for the Block type.

type Blocks added in v0.2.0

type Blocks []Block

Blocks defines a wrapper type around the []Block type.

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

A Header defines properties of a Block that are not application-specific. These properties are required by, or produced by, the consensus algorithm.

func NewHeader added in v0.2.0

func NewHeader(kind Kind, parentHash, baseHash, txsRef, planRef, prevStateRef id.Hash, height Height, round Round, timestamp Timestamp, signatories id.Signatories) Header

NewHeader returns a Header. It will panic if a pre-condition for Header validity is violated.

func (Header) BaseHash added in v0.2.0

func (header Header) BaseHash() id.Hash

BaseHash of the Block.

func (Header) Height added in v0.2.0

func (header Header) Height() Height

Height of the Block.

func (Header) Kind added in v0.2.0

func (header Header) Kind() Kind

Kind of the Block.

func (Header) MarshalBinary added in v0.2.0

func (header Header) MarshalBinary() ([]byte, error)

MarshalBinary implements the `encoding.BinaryMarshaler` interface for the Header type.

func (Header) MarshalJSON added in v0.2.0

func (header Header) MarshalJSON() ([]byte, error)

MarshalJSON implements the `json.Marshaler` interface for the Header type.

func (Header) ParentHash added in v0.2.0

func (header Header) ParentHash() id.Hash

ParentHash of the Block.

func (Header) PlanRef added in v0.3.0

func (header Header) PlanRef() id.Hash

PlanRef of the Block.

func (Header) PrevStateRef added in v0.3.0

func (header Header) PrevStateRef() id.Hash

PrevStateRef of the Block.

func (Header) Round added in v0.2.0

func (header Header) Round() Round

Round of the Block.

func (Header) Signatories added in v0.2.0

func (header Header) Signatories() id.Signatories

Signatories of the Block.

func (Header) String added in v0.2.0

func (header Header) String() string

String implements the `fmt.Stringer` interface for the Header type.

func (Header) Timestamp added in v0.2.0

func (header Header) Timestamp() Timestamp

Timestamp of the Block in seconds since Unix Epoch.

func (Header) TxsRef added in v0.3.0

func (header Header) TxsRef() id.Hash

TxsRef of the Block.

func (*Header) UnmarshalBinary added in v0.2.0

func (header *Header) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the `encoding.BinaryUnmarshaler` interface for the Header type.

func (*Header) UnmarshalJSON added in v0.2.0

func (header *Header) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the `json.Unmarshaler` interface for the Header type.

type Height

type Height int64

Height of a Block.

type Kind added in v0.2.0

type Kind uint8

Kind defines the different kinds of Block that exist.

const (
	// Invalid defines an invalid Kind that must not be used.
	Invalid Kind = iota

	// Standard Blocks are used when reaching consensus on the ordering of
	// application-specific data. Standard Blocks must have nil Header
	// Signatories. This is the most common Block Kind.
	Standard
	// Rebase Blocks are used when reaching consensus about a change to the
	// Header Signatories that oversee the consensus algorithm. Rebase Blocks
	// must include non-empty Header Signatories.
	Rebase
	// Base Blocks are used to finalise Rebase Blocks. Base Blocks must come
	// immediately after a Rebase Block, must have no Content, and must have the
	// same Header Signatories as their parent.
	Base
)

func (Kind) String added in v0.2.0

func (kind Kind) String() string

String implements the `fmt.Stringer` interface for the Kind type.

type Plan added in v0.3.0

type Plan []byte

Plan stores application-specific plan data used in Blocks and Notes (must be nil in Rebase Blocks and Base Blocks).

func (Plan) Hash added in v0.3.0

func (plan Plan) Hash() id.Hash

Hash of a Plan object.

func (Plan) String added in v0.3.0

func (plan Plan) String() string

String implements the `fmt.Stringer` interface for the Plan type.

type Round

type Round int64

Round in which a Block was proposed.

type State added in v0.2.0

type State []byte

State stores application-specific state after the execution of a Block.

func (State) Hash added in v0.3.0

func (state State) Hash() id.Hash

Hash of a State object.

func (State) String added in v0.2.0

func (state State) String() string

String implements the `fmt.Stringer` interface for the State type.

type Timestamp added in v0.2.0

type Timestamp uint64

Timestamp represents seconds since Unix Epoch.

type Txs added in v0.3.0

type Txs []byte

Txs stores application-specific transaction data used in Blocks and Notes (must be nil in Rebase Blocks and Base Blocks).

func (Txs) Hash added in v0.3.0

func (txs Txs) Hash() id.Hash

Hash of a Txs object.

func (Txs) String added in v0.3.0

func (txs Txs) String() string

String implements the `fmt.Stringer` interface for the Txs type.

Jump to

Keyboard shortcuts

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