rpc

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: LGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrResponseVersion = errors.New("unexpected response version received")
	ErrResponseError   = errors.New("response error received")
)

Functions

func Decode

func Decode(body []byte, target interface{}) error

Decode decodes []body into the target interface. It assumes that the response.Result is an optional JSON-encoded value.

func DecodeScaleUnmarshal added in v0.8.0

func DecodeScaleUnmarshal(body []byte, target any) error

DecodeScaleUnmarshal decodes []body into the result. It assumes that the response.Result is a SCALE-encoded value.

func EpochLength

func EpochLength(ctx context.Context, rpcPort string) (epochLength uint64, err error)

EpochLength Calls dev endpoint for epoch length

func GetBlock

func GetBlock(ctx context.Context, rpcPort string, hash common.Hash) (
	block *types.Block, err error)

GetBlock calls the endpoint chain_getBlock

func GetBlockHash

func GetBlockHash(ctx context.Context, rpcPort, num string) (hash common.Hash, err error)

GetBlockHash calls the endpoint chain_getBlockHash to get the latest chain head. It will block until a response is received or the context gets canceled.

func GetChainHead

func GetChainHead(ctx context.Context, rpcPort string) (header *types.Header, err error)

GetChainHead calls the endpoint chain_getHeader to get the latest chain head

func GetFinalizedHead

func GetFinalizedHead(ctx context.Context, rpcPort string) (
	hash common.Hash, err error)

GetFinalizedHead calls the endpoint chain_getFinalizedHead to get the latest finalised head

func GetFinalizedHeadByRound

func GetFinalizedHeadByRound(ctx context.Context, rpcPort string, round uint64) (
	hash common.Hash, err error)

GetFinalizedHeadByRound calls the endpoint chain_getFinalizedHeadByRound to get the finalised head at a given round TODO: add setID, hard-coded at 1 for now

func GetHealth

func GetHealth(ctx context.Context, address string) (
	health modules.SystemHealthResponse, err error)

GetHealth sends an RPC request to `system_health`.

func GetPeers

func GetPeers(ctx context.Context, rpcPort string) (peers []common.PeerInfo, err error)

GetPeers calls the endpoint system_peers

func NewEndpoint

func NewEndpoint(port string) string

NewEndpoint returns http://localhost:<port>

func PauseBABE

func PauseBABE(ctx context.Context, rpcPort string) error

PauseBABE calls the endpoint dev_control with the params ["babe", "stop"]

func Post

func Post(ctx context.Context, endpoint, method, params string) (data []byte, err error)

Post sends a payload using the method, host and params string given. It returns the response bytes and an eventual error.

func SlotDuration

func SlotDuration(ctx context.Context, rpcPort string) (
	slotDuration time.Duration, err error)

SlotDuration Calls dev endpoint for slot duration

Types

type Error

type Error struct {
	Message   string                 `json:"message"`
	ErrorCode int                    `json:"code"`
	Data      map[string]interface{} `json:"data"`
}

Error is a struct that holds the error message and the error code for a error

type ServerResponse

type ServerResponse struct {
	// JSON-RPC Version
	Version string `json:"jsonrpc"`
	// Method name called
	Method string `json:"method"`
	// Resulting values
	Result json.RawMessage `json:"result"`
	// Params values including results
	Params json.RawMessage `json:"params"`
	// Any generated errors
	Error        *Error           `json:"error"`
	Subscription *json.RawMessage `json:"subscription"`
	// Request id
	ID *json.RawMessage `json:"id"`
}

ServerResponse wraps the RPC response

Jump to

Keyboard shortcuts

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