substrate

package module
v0.4.14 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

README

substrate-api-rpc

Contents

Install

go get github.com/m0ssc0de/substrate-api-rpc

Usage

Codec
Extrinsic Decode
metadataRaw := "" // rpc state_getMetadata
specVersion := 0  // rpc chain_getRuntimeVersion
encodeExtrinsic := []string{"0x280402000b10449a7e7301", "0x1c0407005e8b4100"}
decodeExtrinsics, err := substrate.DecodeExtrinsic(encodeExtrinsic, metadata.Process(metadataRaw), specVersion)
Event Decode
metadataRaw := "" // rpc state_getMetadata
specVersion := 0  // rpc chain_getRuntimeVersion
event = "0x080000000000000080e36a09000000000200000001000000000000ca9a3b00000000020000"
substrate.DecodeEvent(event, metadataInstant, specVersion)
Log Decode
logs := ["0x054241424501014a7024ec6c4be378c35c254860d8f4ddc6f9d53ea8ce42ca00bc77c280511f1cb4c93fbd825e3c7dcabb36221372a9b5359c496e095d31afc359bdb9fac45487"]
substrate.DecodeLogDigest(logs)
Storage Decode
raw := "0x2efb"
storage.Decode(raw, "i16", nil)
RPC
Substrate RPC

Example

state_getMetadata

blockHash := ""
rpc.GetMetadataByHash(conn, blockHash)

state_getStorage

validatorsRaw, err := rpc.ReadStorage(conn, "Session", "Validators", blockHash)
validatorList := validatorsRaw.ToStringSlice()

More information can be viewed https://polkadot.js.org/api/substrate/rpc.html

Contributions

We welcome contributions of any kind. Issues labeled can be good (first) contributions.

LICENSE

GPL-3.0

Documentation

Index

Constants

View Source
const (
	CidAura = 0x61727561
	CidBabe = 0x45424142
)

Variables

This section is empty.

Functions

func DecodeEvent

func DecodeEvent(rawList string, metadata *metadata.Instant, spec int) (r interface{}, err error)

Event decode

func DecodeExtrinsic

func DecodeExtrinsic(rawList []string, metadata *metadata.Instant, spec int) (r []map[string]interface{}, err error)

Extrinsic decode

func DecodeLogDigest

func DecodeLogDigest(rawList []string) (r []storage.DecoderLog, err error)

LogDigest decode

func ExtractAuthor

func ExtractAuthor(data []byte, sessionValidators []string) string

func RegCustomTypes

func RegCustomTypes(sourceCode []byte)

Types

type Mortal

type Mortal struct {
	Period uint64
	Phase  uint64
}

func DecodeMortal

func DecodeMortal(era string) *Mortal

func (*Mortal) Birth

func (m *Mortal) Birth(current uint64) uint64

func (*Mortal) Death

func (m *Mortal) Death(current uint64) uint64

type PreRuntime

type PreRuntime struct {
	Data   string `json:"data"`
	Engine int64  `json:"engine"`
}

Directories

Path Synopsis
pkg
recws
Package recws provides websocket client based on gorilla/websocket that will automatically reconnect if the connection is dropped.
Package recws provides websocket client based on gorilla/websocket that will automatically reconnect if the connection is dropped.

Jump to

Keyboard shortcuts

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