common

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2021 License: LGPL-3.0 Imports: 16 Imported by: 7

Documentation

Overview

Copyright 2019 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 (
	// HashLength is the expected length of the common.Hash type
	HashLength = 32
)

Variables

View Source
var (
	// BestBlockHashKey is the db location the hash of the best (unfinalized) block header.
	BestBlockHashKey = []byte("best_hash")
	// LatestStorageHashKey is the db location of the hash of the latest storage trie.
	LatestStorageHashKey = []byte("latest_storage_hash")
	// FinalizedBlockHashKey is the db location of the hash of the latest finalized block header.
	FinalizedBlockHashKey = []byte("finalized_head")
	// GenesisDataKey is the db location of the genesis data.
	GenesisDataKey = []byte("genesis_data")
	// BlockTreeKey is the db location of the encoded block tree structure.
	BlockTreeKey = []byte("block_tree")
	// LatestFinalizedRoundKey is the key where the last finalized grandpa round is stored
	LatestFinalizedRoundKey = []byte("latest_finalized_round")
	// WorkingStorageHashKey is the storage key that the runtime uses to store the latest working state root.
	WorkingStorageHashKey = []byte("working_storage_hash")
)
View Source
var (
	// CodeKey is the key where runtime code is stored in the trie
	CodeKey = []byte(":code")
)
View Source
var ErrNoPrefix = errors.New("could not byteify non 0x prefixed string")

ErrNoPrefix is returned when trying to convert a hex-encoded string with no 0x prefix

View Source
var MaxUint128 = &Uint128{
	Upper: ^uint64(0),
	Lower: ^uint64(0),
}

MaxUint128 is the maximum uint128 value

Functions

func AppendZeroes

func AppendZeroes(in []byte, l int) []byte

AppendZeroes appends zeroes to the input byte array up until it has length l

func BalanceKey

func BalanceKey(key [32]byte) ([]byte, error)

BalanceKey returns the storage trie key for the balance of the account with the given public key

func Blake2b128

func Blake2b128(in []byte) ([]byte, error)

Blake2b128 returns the 128-bit blake2b hash of the input data

func BytesToHex

func BytesToHex(in []byte) string

BytesToHex turns a byte slice into a 0x prefixed hex string

func BytesToStringArray

func BytesToStringArray(in [][]byte) []string

BytesToStringArray turns an array of byte arrays into an array strings

func Concat

func Concat(s1 []byte, s2 ...byte) []byte

Concat concatenates two byte arrays used instead of append to prevent modifying the original byte array

func HashValidator added in v0.3.0

func HashValidator(field reflect.Value) interface{}

HashValidator validates hash fields

func HexToBytes

func HexToBytes(in string) ([]byte, error)

HexToBytes turns a 0x prefixed hex string into a byte slice

func MustHexToBytes added in v0.2.0

func MustHexToBytes(in string) []byte

MustHexToBytes turns a 0x prefixed hex string into a byte slice it panic if it cannot decode the string

func NonceKey

func NonceKey(key [32]byte) ([]byte, error)

NonceKey returns the storage trie key for the nonce of the account with the given public key

func Read32Bytes

func Read32Bytes(r io.Reader) ([32]byte, error)

Read32Bytes reads 32 bytes from the reader and returns it

func Read4Bytes added in v0.3.0

func Read4Bytes(r io.Reader) ([]byte, error)

Read4Bytes reads 4 bytes from the reader and returns it

func Read64Bytes added in v0.3.0

func Read64Bytes(r io.Reader) ([64]byte, error)

Read64Bytes reads 64 bytes from the reader and returns it

func Read8Bytes added in v0.3.0

func Read8Bytes(r io.Reader) ([8]byte, error)

Read8Bytes reads 8 bytes from the reader and returns it

func ReadByte

func ReadByte(r io.Reader) (byte, error)

ReadByte reads a byte from the reader and returns it

func ReadBytes added in v0.3.0

func ReadBytes(r io.Reader, n int) ([]byte, error)

ReadBytes reads the given number bytes from the reader and returns it

func ReadUint32

func ReadUint32(r io.Reader) (uint32, error)

ReadUint32 reads a 4-byte uint32 from the reader and returns it

func ReadUint64

func ReadUint64(r io.Reader) (uint64, error)

ReadUint64 reads an 8-byte uint32 from the reader and returns it

func StringArrayToBytes

func StringArrayToBytes(in []string) [][]byte

StringArrayToBytes turns an array of strings into an array of byte arrays

func StringToInts

func StringToInts(in string) ([]int, error)

StringToInts turns a string consisting of ints separated by commas into an int array

func SwapByteNibbles

func SwapByteNibbles(b byte) byte

SwapByteNibbles swaps the two nibbles of a byte

func SwapNibbles

func SwapNibbles(k []byte) []byte

SwapNibbles swaps the nibbles for each byte in the byte array

func Twox128Hash added in v0.2.0

func Twox128Hash(msg []byte) ([]byte, error)

Twox128Hash computes xxHash64 twice with seeds 0 and 1 applied on given byte array

func Twox64 added in v0.2.0

func Twox64(in []byte) ([]byte, error)

Twox64 returns the xx64 hash of the input data

func Uint16ToBytes

func Uint16ToBytes(in uint16) (out []byte)

Uint16ToBytes converts a uint16 into a 2-byte slice

Types

type Address

type Address string

Address represents a base58 encoded public key

type Hash

type Hash [32]byte

Hash used to store a blake2b hash

func Blake2bHash

func Blake2bHash(in []byte) (Hash, error)

Blake2bHash returns the 256-bit blake2b hash of the input data

func BytesToHash

func BytesToHash(b []byte) Hash

BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.

func HexToHash

func HexToHash(in string) (Hash, error)

HexToHash turns a 0x prefixed hex string into type Hash

func Keccak256

func Keccak256(in []byte) (Hash, error)

Keccak256 returns the keccak256 hash of the input data

func MustBlake2bHash added in v0.3.0

func MustBlake2bHash(in []byte) Hash

MustBlake2bHash returns the 256-bit blake2b hash of the input data. It panics if it fails to hash.

func MustHexToHash added in v0.2.0

func MustHexToHash(in string) Hash

MustHexToHash turns a 0x prefixed hex string into type Hash it panics if it cannot turn the string into a Hash

func NewHash

func NewHash(in []byte) (res Hash)

NewHash casts a byte array to a Hash if the input is longer than 32 bytes, it takes the first 32 bytes

func ReadHash

func ReadHash(r io.Reader) (Hash, error)

ReadHash reads a 32-byte hash from the reader and returns it

func Sha256 added in v0.3.0

func Sha256(in []byte) Hash

Sha256 returns the SHA2-256 hash of the input data

func Twox256 added in v0.2.0

func Twox256(in []byte) (Hash, error)

Twox256 returns the twox256 hash of the input data

func (Hash) Equal

func (h Hash) Equal(g Hash) bool

Equal compares two hashes

func (*Hash) MarshalJSON added in v0.3.0

func (h *Hash) MarshalJSON() ([]byte, error)

MarshalJSON converts hash to hex data

func (*Hash) SetBytes

func (h *Hash) SetBytes(b []byte)

SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.

func (Hash) String

func (h Hash) String() string

String returns the hex string for the hash

func (Hash) ToBytes

func (h Hash) ToBytes() []byte

ToBytes turns a hash to a byte array

func (*Hash) UnmarshalJSON added in v0.3.0

func (h *Hash) UnmarshalJSON(data []byte) error

UnmarshalJSON converts hex data to hash

type Health

type Health struct {
	Peers           int
	IsSyncing       bool
	ShouldHavePeers bool
}

Health is network information about host needed for the rpc server

type NetworkState

type NetworkState struct {
	PeerID     string
	Multiaddrs []ma.Multiaddr
}

NetworkState is network information about host needed for the rpc server and the runtime

type PeerInfo

type PeerInfo struct {
	PeerID     string
	Roles      byte
	BestHash   Hash
	BestNumber uint64
}

PeerInfo is network information about peers needed for the rpc server

type Uint128 added in v0.3.0

type Uint128 struct {
	Upper uint64
	Lower uint64
}

Uint128 represents an unsigned 128 bit integer

func Uint128FromBigInt added in v0.3.0

func Uint128FromBigInt(in *big.Int) *Uint128

Uint128FromBigInt returns a new Uint128 from a *big.Int

func Uint128FromLEBytes added in v0.3.0

func Uint128FromLEBytes(in []byte) *Uint128

Uint128FromLEBytes returns a new Uint128 from a little-endian byte slice If the slice is greater than 16 bytes long, it only uses the first 16 bytes

func (*Uint128) Cmp added in v0.3.0

func (u *Uint128) Cmp(other *Uint128) int

Cmp returns 1 if the receiver is greater than other, 0 if they are equal, and -1 otherwise.

func (*Uint128) ToBEBytes added in v0.3.0

func (u *Uint128) ToBEBytes() []byte

ToBEBytes returns the Uint128 as a big endian byte slice

func (*Uint128) ToLEBytes added in v0.3.0

func (u *Uint128) ToLEBytes() []byte

ToLEBytes returns the Uint128 as a little endian byte slice

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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