types

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: LGPL-3.0 Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

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 PreRuntimeDigestType = byte(6)

PreRuntimeDigestType is the byte representation of PreRuntimeDigest

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 AuthorityData

type AuthorityData struct {
	ID     *sr25519.PublicKey
	Weight uint64
}

AuthorityData represents a BABE authority

func NewAuthorityData

func NewAuthorityData(pub *sr25519.PublicKey, weight uint64) *AuthorityData

NewAuthorityData returns AuthorityData with the given id and weight

func (*AuthorityData) Decode

func (a *AuthorityData) Decode(r io.Reader) error

Decode sets the AuthorityData to the SCALE decoded input.

func (*AuthorityData) Encode

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

Encode returns the SCALE encoding of the AuthorityData.

func (*AuthorityData) FromRaw

func (a *AuthorityData) FromRaw(raw *AuthorityDataRaw) error

FromRaw sets the AuthorityData given AuthorityDataRaw. It converts the byte representations of the authority public keys into a sr25519.PublicKey.

func (*AuthorityData) ToRaw

func (a *AuthorityData) ToRaw() *AuthorityDataRaw

ToRaw returns the AuthorityData as AuthorityDataRaw. It encodes the authority public keys.

type AuthorityDataRaw

type AuthorityDataRaw struct {
	ID     [sr25519.PublicKeyLength]byte
	Weight uint64
}

AuthorityDataRaw represents a BABE authority where their key is a byte array

func (*AuthorityDataRaw) Decode

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

Decode will decode the Reader into a AuthorityDataRaw

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 []*AuthorityDataRaw
	Randomness         byte // TODO: change to [RandomnessLength]byte when updating to new runtime
	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(in []byte) 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

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

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

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

Decode will decode into ConsensusEngineID and Data

func (*ConsensusDigest) Encode

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

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
	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 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 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(in []byte) 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) String

func (bh *Header) String() string

String returns the formatted header as a string

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

Encode will encode PreRuntimeDigest ConsensusEngineID and Data

func (*PreRuntimeDigest) Type

func (d *PreRuntimeDigest) Type() byte

Type will return PreRuntimeDigestType

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

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