types

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: LGPL-3.0 Imports: 12 Imported by: 2

Documentation

Overview

Copyright 2020 ChainSafe Systems (ON) Corp. This file is part of gossamer.

The gossamer library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

The gossamer library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with the gossamer library. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	// NoNetworkRole runs a node without networking
	NoNetworkRole = byte(0)
	// FullNodeRole runs a full node
	FullNodeRole = byte(1)
	// LightClientRole runs a light client
	LightClientRole = byte(2)
	// AuthorityRole runs the node as a block-producing and finalizing node
	AuthorityRole = byte(4)
)
View Source
const RandomnessLength = 32

RandomnessLength is the length of the epoch randomness (32 bytes)

Variables

View Source
var (
	Timstap0 = []byte("timstap0")
	Babeslot = []byte("babeslot")
	Finalnum = []byte("finalnum")
	Uncles00 = []byte("uncles00")
)

nolint

View Source
var BabeEngineID = ConsensusEngineID{'B', 'A', 'B', 'E'}

BabeEngineID is the hard-coded babe ID

View Source
var ChangesTrieRootDigestType = byte(2)

ChangesTrieRootDigestType is the byte representation of ChangesTrieRootDigest

View Source
var ConsensusDigestType = byte(4)

ConsensusDigestType is the byte representation of ConsensusDigest

View Source
var ForcedChangeType = byte(2)

ForcedChangeType identifies a ForcedChange consensus digest

View Source
var GrandpaEngineID = ConsensusEngineID{'F', 'R', 'N', 'K'}

GrandpaEngineID is the hard-coded grandpa ID

View Source
var OnDisabledType = byte(3)

OnDisabledType identifies a DisabledChange consensus digest

View Source
var PauseType = byte(4)

PauseType identifies a Pause consensus digest

View Source
var PreRuntimeDigestType = byte(6)

PreRuntimeDigestType is the byte representation of PreRuntimeDigest

View Source
var ResumeType = byte(5)

ResumeType identifies a Resume consensus digest

View Source
var ScheduledChangeType = byte(1)

ScheduledChangeType identifies a ScheduledChange consensus digest

View Source
var SealDigestType = byte(5)

SealDigestType is the byte representation of SealDigest

Functions

func EncodeBlockDataArray

func EncodeBlockDataArray(bds []*BlockData) ([]byte, error)

EncodeBlockDataArray encodes an array of BlockData using SCALE

func ExtrinsicsArrayToBytesArray

func ExtrinsicsArrayToBytesArray(exts []Extrinsic) [][]byte

ExtrinsicsArrayToBytesArray converts an array of extrinsics into an array of byte arrays

Types

type Authority added in v0.2.0

type Authority struct {
	Key    crypto.PublicKey
	Weight uint64
}

Authority struct to hold authority data

func BABEAuthorityRawToAuthority added in v0.2.0

func BABEAuthorityRawToAuthority(adr []*AuthorityRaw) ([]*Authority, error)

BABEAuthorityRawToAuthority turns a slice of BABE AuthorityRaw into a slice of Authority

func GrandpaAuthorityDataRawToAuthorityData added in v0.2.0

func GrandpaAuthorityDataRawToAuthorityData(adr []*GrandpaAuthorityDataRaw) ([]*Authority, error)

GrandpaAuthorityDataRawToAuthorityData turns a slice of GrandpaAuthorityDataRaw into a slice of Authority

func NewAuthority added in v0.2.0

func NewAuthority(pub crypto.PublicKey, weight uint64) *Authority

NewAuthority function to create Authority object

func (*Authority) DecodeSr25519 added in v0.2.0

func (a *Authority) DecodeSr25519(r io.Reader) error

DecodeSr25519 sets the Authority to the SCALE decoded input for Authority containing SR25519 Keys.

func (*Authority) Encode added in v0.2.0

func (a *Authority) Encode() []byte

Encode returns the SCALE encoding of the BABEAuthorityData.

func (*Authority) FromRawEd25519 added in v0.2.0

func (a *Authority) FromRawEd25519(raw *GrandpaAuthorityDataRaw) error

FromRawEd25519 sets the Authority given GrandpaAuthorityDataRaw. It converts the byte representations of the authority public keys into a ed25519.PublicKey.

func (*Authority) FromRawSr25519 added in v0.2.0

func (a *Authority) FromRawSr25519(raw *AuthorityRaw) error

FromRawSr25519 sets the Authority given AuthorityRaw. It converts the byte representations of the authority public keys into a sr25519.PublicKey.

func (*Authority) ToRaw added in v0.2.0

func (a *Authority) ToRaw() *AuthorityRaw

ToRaw returns the BABEAuthorityData as BABEAuthorityDataRaw. It encodes the authority public keys.

type AuthorityRaw added in v0.2.0

type AuthorityRaw struct {
	Key    [sr25519.PublicKeyLength]byte
	Weight uint64
}

AuthorityRaw struct to hold raw authority data

func (*AuthorityRaw) Decode added in v0.2.0

func (a *AuthorityRaw) Decode(r io.Reader) (*AuthorityRaw, error)

Decode will decode the Reader into a AuthorityRaw

type BABEForcedChange added in v0.2.0

type BABEForcedChange struct {
	Auths []*AuthorityRaw
	Delay uint32
}

BABEForcedChange represents a BABE forced authority change

func (*BABEForcedChange) Encode added in v0.2.0

func (fc *BABEForcedChange) Encode() ([]byte, error)

Encode returns a SCALE encoded BABEForcedChange with first type byte

type BABEScheduledChange added in v0.2.0

type BABEScheduledChange struct {
	Auths []*AuthorityRaw
	Delay uint32
}

BABEScheduledChange represents a BABE scheduled authority change

func (*BABEScheduledChange) Encode added in v0.2.0

func (sc *BABEScheduledChange) Encode() ([]byte, error)

Encode returns a SCALE encoded BABEScheduledChange with first type byte

type BabeConfiguration

type BabeConfiguration struct {
	SlotDuration       uint64 // milliseconds
	EpochLength        uint64 // duration of epoch in slots
	C1                 uint64 // (1-(c1/c2)) is the probability of a slot being empty
	C2                 uint64
	GenesisAuthorities []*AuthorityRaw
	Randomness         [32]byte
	SecondarySlots     bool
}

BabeConfiguration contains the genesis data for BABE see: https://github.com/paritytech/substrate/blob/426c26b8bddfcdbaf8d29f45b128e0864b57de1c/core/consensus/babe/primitives/src/lib.rs#L132

type BabeHeader

type BabeHeader struct {
	VrfOutput          [sr25519.VrfOutputLength]byte
	VrfProof           [sr25519.VrfProofLength]byte
	BlockProducerIndex uint64
	SlotNumber         uint64
}

BabeHeader as defined in Polkadot RE Spec, definition 5.10 in section 5.1.4

func (*BabeHeader) Decode

func (bh *BabeHeader) Decode(in []byte) error

Decode performs SCALE decoding of an encoded BabeHeader

func (*BabeHeader) Encode

func (bh *BabeHeader) Encode() []byte

Encode performs SCALE encoding of a BabeHeader

type Block

type Block struct {
	Header *Header
	Body   *Body
}

Block defines a state block

func NewBlock

func NewBlock(header *Header, body *Body) *Block

NewBlock returns a new Block

func NewEmptyBlock

func NewEmptyBlock() *Block

NewEmptyBlock returns a new Block with an initialized but empty Header and Body

func (*Block) Decode

func (b *Block) Decode(r io.Reader) error

Decode decodes the SCALE encoded input into this block

func (*Block) DeepCopy

func (b *Block) DeepCopy() *Block

DeepCopy returns a copy of the block

func (*Block) Encode

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

Encode returns the SCALE encoding of a block

func (*Block) MustEncode added in v0.2.0

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

MustEncode returns the SCALE encoded block and panics if it fails to encode

type BlockData

type BlockData struct {
	Hash          common.Hash
	Header        *optional.Header
	Body          *optional.Body
	Receipt       *optional.Bytes
	MessageQueue  *optional.Bytes
	Justification *optional.Bytes
}

BlockData is stored within the BlockDB

func DecodeBlockDataArray

func DecodeBlockDataArray(r io.Reader) ([]*BlockData, error)

DecodeBlockDataArray decodes a SCALE encoded BlockData array

func (*BlockData) Decode

func (bd *BlockData) Decode(r io.Reader) error

Decode decodes the SCALE encoded input to BlockData

func (*BlockData) Encode

func (bd *BlockData) Encode() ([]byte, error)

Encode performs SCALE encoding of the BlockData

type Body

type Body []byte

Body is the encoded extrinsics inside a state block

func NewBody

func NewBody(b []byte) *Body

NewBody returns a Body from a byte array

func NewBodyFromExtrinsicStrings

func NewBodyFromExtrinsicStrings(ss []string) (*Body, error)

NewBodyFromExtrinsicStrings creates a block body given an array of hex-encoded 0x-prefixed strings.

func NewBodyFromExtrinsics

func NewBodyFromExtrinsics(exts []Extrinsic) (*Body, error)

NewBodyFromExtrinsics creates a block body given an array of extrinsics.

func NewBodyFromOptional

func NewBodyFromOptional(ob *optional.Body) (*Body, error)

NewBodyFromOptional returns a Body given an optional.Body. If the optional.Body is None, an error is returned.

func (*Body) AsExtrinsics

func (b *Body) AsExtrinsics() ([]Extrinsic, error)

AsExtrinsics decodes the body into an array of extrinsics

func (*Body) AsOptional

func (b *Body) AsOptional() *optional.Body

AsOptional returns the Body as an optional.Body

type ChangesTrieRootDigest

type ChangesTrieRootDigest struct {
	Hash common.Hash
}

ChangesTrieRootDigest contains the root of the changes trie at a given block, if the runtime supports it.

func (*ChangesTrieRootDigest) Decode

func (d *ChangesTrieRootDigest) Decode(in []byte) error

Decode will decode into ChangesTrieRootDigest Hash

func (*ChangesTrieRootDigest) Encode

func (d *ChangesTrieRootDigest) Encode() ([]byte, error)

Encode will encode the ChangesTrieRootDigestType into byte array

func (*ChangesTrieRootDigest) Type

func (d *ChangesTrieRootDigest) Type() byte

Type returns the type

type ConsensusDigest

type ConsensusDigest struct {
	ConsensusEngineID ConsensusEngineID
	Data              []byte
}

ConsensusDigest contains messages from the runtime to the consensus engine.

func (*ConsensusDigest) DataType added in v0.2.0

func (d *ConsensusDigest) DataType() byte

DataType returns the data type of the runtime-to-consensus engine message

func (*ConsensusDigest) Decode

func (d *ConsensusDigest) Decode(in []byte) error

Decode will decode into ConsensusEngineID and Data

func (*ConsensusDigest) Encode

func (d *ConsensusDigest) Encode() ([]byte, error)

Encode will encode ConsensusDigest ConsensusEngineID and Data

func (*ConsensusDigest) Type

func (d *ConsensusDigest) Type() byte

Type returns the ConsensusDigest type

type ConsensusEngineID

type ConsensusEngineID [4]byte

ConsensusEngineID is a 4-character identifier of the consensus engine that produced the digest.

func NewConsensusEngineID

func NewConsensusEngineID(in []byte) (res ConsensusEngineID)

NewConsensusEngineID casts a byte array to ConsensusEngineID if the input is longer than 4 bytes, it takes the first 4 bytes

func (ConsensusEngineID) ToBytes

func (h ConsensusEngineID) ToBytes() []byte

ToBytes turns ConsensusEngineID to a byte array

type DigestItem

type DigestItem interface {
	Type() byte
	Encode() ([]byte, error)
	Decode([]byte) error // Decode assumes the type byte (first byte) has been removed from the encoding.
}

DigestItem can be of one of four types of digest: ChangesTrieRootDigest, PreRuntimeDigest, ConsensusDigest, or SealDigest. see https://github.com/paritytech/substrate/blob/f548309478da3935f72567c2abc2eceec3978e9f/primitives/runtime/src/generic/digest.rs#L77

func DecodeDigestItem

func DecodeDigestItem(in []byte) (DigestItem, error)

DecodeDigestItem will decode byte array to DigestItem

type EpochInfo added in v0.2.0

type EpochInfo struct {
	Duration   uint64 // number of slots in the epoch
	FirstBlock uint64 // number of the first block in the epoch
	Randomness [RandomnessLength]byte
}

EpochInfo is internal BABE information for a given epoch

type Extrinsic

type Extrinsic []byte

Extrinsic is a generic transaction whose format is verified in the runtime

func BytesArrayToExtrinsics

func BytesArrayToExtrinsics(b [][]byte) []Extrinsic

BytesArrayToExtrinsics converts an array of byte arrays into an array of extrinsics

func NewExtrinsic

func NewExtrinsic(e []byte) Extrinsic

NewExtrinsic creates a new Extrinsic given a byte slice

func (Extrinsic) Hash

func (e Extrinsic) Hash() common.Hash

Hash returns the blake2b hash of the extrinsic

type GrandpaAuthorityDataRaw added in v0.2.0

type GrandpaAuthorityDataRaw struct {
	Key [ed25519.PublicKeyLength]byte
	ID  uint64
}

GrandpaAuthorityDataRaw represents a GRANDPA authority where their key is a byte array

func (*GrandpaAuthorityDataRaw) Decode added in v0.2.0

Decode will decode the Reader into a GrandpaAuthorityDataRaw

type GrandpaForcedChange added in v0.2.0

type GrandpaForcedChange struct {
	Auths []*GrandpaAuthorityDataRaw
	Delay uint32
}

GrandpaForcedChange represents a GRANDPA forced authority change

func (*GrandpaForcedChange) Encode added in v0.2.0

func (fc *GrandpaForcedChange) Encode() ([]byte, error)

Encode returns a SCALE encoded GrandpaForcedChange with first type byte

type GrandpaScheduledChange added in v0.2.0

type GrandpaScheduledChange struct {
	Auths []*GrandpaAuthorityDataRaw
	Delay uint32
}

GrandpaScheduledChange represents a GRANDPA scheduled authority change

func (*GrandpaScheduledChange) Encode added in v0.2.0

func (sc *GrandpaScheduledChange) Encode() ([]byte, error)

Encode returns a SCALE encoded GrandpaScheduledChange with first type byte

type Header struct {
	ParentHash     common.Hash `json:"parentHash"`
	Number         *big.Int    `json:"number"`
	StateRoot      common.Hash `json:"stateRoot"`
	ExtrinsicsRoot common.Hash `json:"extrinsicsRoot"`
	Digest         [][]byte    `json:"digest"`
	// contains filtered or unexported fields
}

Header is a state block header

func NewHeader

func NewHeader(parentHash common.Hash, number *big.Int, stateRoot common.Hash, extrinsicsRoot common.Hash, digest [][]byte) (*Header, error)

NewHeader creates a new block header and sets its hash field

func NewHeaderFromOptional

func NewHeaderFromOptional(oh *optional.Header) (*Header, error)

NewHeaderFromOptional returns a Header given an optional.Header. If the optional.Header is None, an error is returned.

func (*Header) AsOptional

func (bh *Header) AsOptional() *optional.Header

AsOptional returns the Header as an optional.Header

func (*Header) Decode

func (bh *Header) Decode(r io.Reader) (*Header, error)

Decode decodes the SCALE encoded input into this header

func (*Header) DeepCopy

func (bh *Header) DeepCopy() *Header

DeepCopy returns a deep copy of the header to prevent side effects down the road

func (*Header) Encode

func (bh *Header) Encode() ([]byte, error)

Encode returns the SCALE encoding of a header

func (*Header) Hash

func (bh *Header) Hash() common.Hash

Hash returns the hash of the block header If the internal hash field is nil, it hashes the block and sets the hash field. If hashing the header errors, this will panic.

func (*Header) MustEncode added in v0.2.0

func (bh *Header) MustEncode() []byte

MustEncode returns the SCALE encoded header and panics if it fails to encode

func (*Header) String

func (bh *Header) String() string

String returns the formatted header as a string

type InherentsData added in v0.2.0

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

InherentsData contains a mapping of inherent keys to values keys must be 8 bytes, values are a scale-encoded byte array

func NewInherentsData added in v0.2.0

func NewInherentsData() *InherentsData

NewInherentsData returns InherentsData

func (*InherentsData) Encode added in v0.2.0

func (d *InherentsData) Encode() ([]byte, error)

Encode will encode a given []byte using scale.Encode

func (*InherentsData) SetBigIntInherent added in v0.2.0

func (d *InherentsData) SetBigIntInherent(key []byte, data *big.Int) error

SetBigIntInherent set as a big.Int (compact int) inherent

func (*InherentsData) SetInt64Inherent added in v0.2.0

func (d *InherentsData) SetInt64Inherent(key []byte, data uint64) error

SetInt64Inherent set the Int64 scale.Encode for a given data

func (*InherentsData) String added in v0.2.0

func (d *InherentsData) String() string

type OnDisabled added in v0.2.0

type OnDisabled struct {
	ID uint64
}

OnDisabled represents a GRANDPA authority being disabled

func (*OnDisabled) Encode added in v0.2.0

func (od *OnDisabled) Encode() ([]byte, error)

Encode returns a SCALE encoded OnDisabled with first type byte

type Pause added in v0.2.0

type Pause struct {
	Delay uint32
}

Pause represents an authority set pause

func (*Pause) Encode added in v0.2.0

func (p *Pause) Encode() ([]byte, error)

Encode returns a SCALE encoded Pause with first type byte

type PreRuntimeDigest

type PreRuntimeDigest struct {
	ConsensusEngineID ConsensusEngineID
	Data              []byte
}

PreRuntimeDigest contains messages from the consensus engine to the runtime.

func (*PreRuntimeDigest) Decode

func (d *PreRuntimeDigest) Decode(in []byte) error

Decode will decode PreRuntimeDigest ConsensusEngineID and Data

func (*PreRuntimeDigest) Encode

func (d *PreRuntimeDigest) Encode() ([]byte, error)

Encode will encode PreRuntimeDigest ConsensusEngineID and Data

func (*PreRuntimeDigest) Type

func (d *PreRuntimeDigest) Type() byte

Type will return PreRuntimeDigestType

type Resume added in v0.2.0

type Resume struct {
	Delay uint32
}

Resume represents an authority set resume

func (*Resume) Encode added in v0.2.0

func (r *Resume) Encode() ([]byte, error)

Encode returns a SCALE encoded Resume with first type byte

type SealDigest

type SealDigest struct {
	ConsensusEngineID ConsensusEngineID
	Data              []byte
}

SealDigest contains the seal or signature. This is only used by native code.

func (*SealDigest) Decode

func (d *SealDigest) Decode(in []byte) error

Decode will decode into SealDigest ConsensusEngineID and Data

func (*SealDigest) Encode

func (d *SealDigest) Encode() ([]byte, error)

Encode will encode SealDigest ConsensusEngineID and Data

func (*SealDigest) Type

func (d *SealDigest) Type() byte

Type will return SealDigest type

type SystemInfo

type SystemInfo struct {
	SystemName       string
	SystemVersion    string
	NodeName         string
	SystemProperties map[string]interface{}
}

SystemInfo struct to hold system related information

Jump to

Keyboard shortcuts

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