modules

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: 17 Imported by: 2

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/>.

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

This section is empty.

Variables

View Source
var ErrSubscriptionTransport = errors.New("subscriptions are not available on this transport")

ErrSubscriptionTransport error sent when trying to access websocket subscriptions via http

Functions

This section is empty.

Types

type AuthorModule

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

AuthorModule holds a pointer to the API

func NewAuthorModule

func NewAuthorModule(logger log.Logger, coreAPI CoreAPI, runtimeAPI RuntimeAPI, txStateAPI TransactionStateAPI) *AuthorModule

NewAuthorModule creates a new Author module.

func (*AuthorModule) HasKey

func (cm *AuthorModule) HasKey(r *http.Request, req *[]string, res *bool) error

HasKey Checks if the keystore has private keys for the given public key and key type.

func (*AuthorModule) InsertKey

func (cm *AuthorModule) InsertKey(r *http.Request, req *KeyInsertRequest, res *KeyInsertResponse) error

InsertKey inserts a key into the keystore

func (*AuthorModule) PendingExtrinsics

func (cm *AuthorModule) PendingExtrinsics(r *http.Request, req *EmptyRequest, res *PendingExtrinsicsResponse) error

PendingExtrinsics Returns all pending extrinsics

func (*AuthorModule) RemoveExtrinsic

func (cm *AuthorModule) RemoveExtrinsic(r *http.Request, req *ExtrinsicOrHashRequest, res *RemoveExtrinsicsResponse) error

RemoveExtrinsic Remove given extrinsic from the pool and temporarily ban it to prevent reimporting

func (*AuthorModule) RotateKeys

func (cm *AuthorModule) RotateKeys(r *http.Request, req *EmptyRequest, res *KeyRotateResponse) error

RotateKeys Generate new session keys and returns the corresponding public keys

func (*AuthorModule) SubmitAndWatchExtrinsic

func (cm *AuthorModule) SubmitAndWatchExtrinsic(r *http.Request, req *Extrinsic, res *ExtrinsicStatus) error

SubmitAndWatchExtrinsic Submit and subscribe to watch an extrinsic until unsubscribed

func (*AuthorModule) SubmitExtrinsic

func (cm *AuthorModule) SubmitExtrinsic(r *http.Request, req *Extrinsic, res *ExtrinsicHashResponse) error

SubmitExtrinsic Submit a fully formatted extrinsic for block inclusion

type BlockAPI

type BlockAPI interface {
	GetHeader(hash common.Hash) (*types.Header, error)
	BestBlockHash() common.Hash
	GetBlockByHash(hash common.Hash) (*types.Block, error)
	GetBlockHash(blockNumber *big.Int) (*common.Hash, error)
	GetFinalizedHash(uint64, uint64) (common.Hash, error)
	RegisterImportedChannel(ch chan<- *types.Block) (byte, error)
	UnregisterImportedChannel(id byte)
	RegisterFinalizedChannel(ch chan<- *types.Header) (byte, error)
	UnregisterFinalizedChannel(id byte)
}

BlockAPI is the interface for the block state

type BlockProducerAPI added in v0.2.0

type BlockProducerAPI interface {
	Pause() error
	Resume() error
	SetAuthorities(data []*types.Authority) error
	SetRandomness([types.RandomnessLength]byte)
	SetThreshold(*big.Int)
}

BlockProducerAPI is the interface for BlockProducer methods

type ChainBlock

type ChainBlock struct {
	Header ChainBlockHeaderResponse `json:"header"`
	Body   []string                 `json:"extrinsics"`
}

ChainBlock struct to hold json instance of a block

type ChainBlockHeaderDigest

type ChainBlockHeaderDigest struct {
	Logs []string `json:"logs"`
}

ChainBlockHeaderDigest struct to hold digest logs

type ChainBlockHeaderResponse

type ChainBlockHeaderResponse struct {
	ParentHash     string                 `json:"parentHash"`
	Number         string                 `json:"number"`
	StateRoot      string                 `json:"stateRoot"`
	ExtrinsicsRoot string                 `json:"extrinsicsRoot"`
	Digest         ChainBlockHeaderDigest `json:"digest"`
}

ChainBlockHeaderResponse struct

func HeaderToJSON

func HeaderToJSON(header types.Header) ChainBlockHeaderResponse

HeaderToJSON converts types.Header to ChainBlockHeaderResponse

type ChainBlockNumberRequest

type ChainBlockNumberRequest interface{}

ChainBlockNumberRequest interface can accept string, float64 or []

type ChainBlockResponse

type ChainBlockResponse struct {
	Block ChainBlock `json:"block"`
}

ChainBlockResponse struct

type ChainHashRequest

type ChainHashRequest string

ChainHashRequest Hash as a string

type ChainHashResponse

type ChainHashResponse interface{}

ChainHashResponse interface to handle response

type ChainIntRequest added in v0.2.0

type ChainIntRequest uint64

ChainIntRequest represents an integer

type ChainModule

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

ChainModule is an RPC module providing access to storage API points.

func NewChainModule

func NewChainModule(api BlockAPI) *ChainModule

NewChainModule creates a new State module.

func (*ChainModule) GetBlock

func (cm *ChainModule) GetBlock(r *http.Request, req *ChainHashRequest, res *ChainBlockResponse) error

GetBlock Get header and body of a relay chain block. If no block hash is provided,

the latest block body will be returned.

func (*ChainModule) GetBlockHash

func (cm *ChainModule) GetBlockHash(r *http.Request, req *ChainBlockNumberRequest, res *ChainHashResponse) error

GetBlockHash Get hash of the 'n-th' block in the canon chain. If no parameters are provided,

the latest block hash gets returned.

func (*ChainModule) GetFinalizedHead

func (cm *ChainModule) GetFinalizedHead(r *http.Request, req *EmptyRequest, res *ChainHashResponse) error

GetFinalizedHead returns the most recently finalized block hash

func (*ChainModule) GetFinalizedHeadByRound added in v0.2.0

func (cm *ChainModule) GetFinalizedHeadByRound(r *http.Request, req *[]ChainIntRequest, res *ChainHashResponse) error

GetFinalizedHeadByRound returns the hash of the block finalized at the given round and setID

func (*ChainModule) GetHead

GetHead alias for GetBlockHash

func (*ChainModule) GetHeader

GetHeader Get header of a relay chain block. If no block hash is provided, the latest block header will be returned.

func (*ChainModule) SubscribeFinalizedHeads

func (cm *ChainModule) SubscribeFinalizedHeads(r *http.Request, req *EmptyRequest, res *ChainBlockHeaderResponse) error

SubscribeFinalizedHeads handled by websocket handler, but this func should remain

here so it's added to rpc_methods list

func (*ChainModule) SubscribeNewHead

func (cm *ChainModule) SubscribeNewHead(r *http.Request, req *EmptyRequest, res *ChainBlockHeaderResponse) error

SubscribeNewHead handled by websocket handler, but this func should remain

here so it's added to rpc_methods list

func (*ChainModule) SubscribeNewHeads

func (cm *ChainModule) SubscribeNewHeads(r *http.Request, req *EmptyRequest, res *ChainBlockHeaderResponse) error

SubscribeNewHeads handled by websocket handler, but this func should remain

here so it's added to rpc_methods list

type CoreAPI

type CoreAPI interface {
	InsertKey(kp crypto.Keypair)
	HasKey(pubKeyStr string, keyType string) (bool, error)
	GetRuntimeVersion() (*runtime.VersionAPI, error)
	IsBlockProducer() bool
	HandleSubmittedExtrinsic(types.Extrinsic) error
	GetMetadata() ([]byte, error)
}

CoreAPI is the interface for the core methods

type DevModule added in v0.2.0

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

DevModule is an RPC module that provides developer endpoints

func NewDevModule added in v0.2.0

func NewDevModule(bp BlockProducerAPI, net NetworkAPI) *DevModule

NewDevModule creates a new Dev module.

func (*DevModule) Control added in v0.2.0

func (m *DevModule) Control(r *http.Request, req *[]string, res *string) error

Control to send start and stop messages to services

func (*DevModule) SetBABEEpochThreshold added in v0.2.0

func (m *DevModule) SetBABEEpochThreshold(r *http.Request, req *string, res *string) error

SetBABEEpochThreshold dev rpc method that sets BABE Epoch Threshold of the BABE Producer

func (*DevModule) SetBABERandomness added in v0.2.0

func (m *DevModule) SetBABERandomness(r *http.Request, req *[]string, res *string) error

SetBABERandomness dev rpc method to set BABE Randomness

func (*DevModule) SetBlockProducerAuthorities added in v0.2.0

func (m *DevModule) SetBlockProducerAuthorities(r *http.Request, req *[]interface{}, res *string) error

SetBlockProducerAuthorities dev rpc method that sets authorities for block producer

type EmptyRequest

type EmptyRequest struct{}

EmptyRequest represents an RPC request with no fields

type Extrinsic

type Extrinsic string

Extrinsic represents a hex-encoded extrinsic

type ExtrinsicHashResponse

type ExtrinsicHashResponse string

ExtrinsicHashResponse is used as Extrinsic hash response

type ExtrinsicOrHash

type ExtrinsicOrHash struct {
	Hash      common.Hash
	Extrinsic []byte
}

ExtrinsicOrHash is a type for Hash and Extrinsic array of bytes

type ExtrinsicOrHashRequest

type ExtrinsicOrHashRequest []ExtrinsicOrHash

ExtrinsicOrHashRequest is a array of ExtrinsicOrHash

type ExtrinsicStatus

type ExtrinsicStatus struct {
	IsFuture    bool
	IsReady     bool
	IsFinalized bool
	AsFinalized common.Hash
	IsUsurped   bool
	AsUsurped   common.Hash
	IsBroadcast bool
	AsBroadcast []string
	IsDropped   bool
	IsInvalid   bool
}

ExtrinsicStatus holds the actual valid statuses

type KeyInsertRequest

type KeyInsertRequest []string

KeyInsertRequest is used as model for the JSON

type KeyInsertResponse

type KeyInsertResponse []byte

KeyInsertResponse []byte

type KeyRotateResponse

type KeyRotateResponse []byte

KeyRotateResponse is a byte array used to rotate

type KeyValueOption

type KeyValueOption struct {
	StorageKey  []byte `json:"storageKey"`
	StorageData []byte `json:"storageData"`
}

KeyValueOption struct holds json fields

type MethodsResponse

type MethodsResponse struct {
	Methods []string `json:"methods"`
}

MethodsResponse struct representing methods

type NetworkAPI

type NetworkAPI interface {
	Health() common.Health
	NetworkState() common.NetworkState
	Peers() []common.PeerInfo
	NodeRoles() byte
	Stop() error
	Start() error
	IsStopped() bool
}

NetworkAPI interface for network state methods

type NetworkStateString added in v0.2.0

type NetworkStateString struct {
	PeerID     string
	Multiaddrs []string
}

NetworkStateString Network State represented as string so JSON encode/decoding works

type PendingExtrinsicsResponse

type PendingExtrinsicsResponse [][]byte

PendingExtrinsicsResponse is a bi-dimensional array of bytes for allocating the pending extrisics

type RPCAPI

type RPCAPI interface {
	Methods() []string
	BuildMethodNames(rcvr interface{}, name string)
}

RPCAPI is the interface for methods related to RPC service

type RPCModule

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

RPCModule is a RPC module providing access to RPC methods

func NewRPCModule

func NewRPCModule(rpcapi RPCAPI) *RPCModule

NewRPCModule creates a new RPC api module

func (*RPCModule) Methods

func (rm *RPCModule) Methods(r *http.Request, req *EmptyRequest, res *MethodsResponse) error

Methods responds with list of methods available via RPC call

type RemoveExtrinsicsResponse

type RemoveExtrinsicsResponse []common.Hash

RemoveExtrinsicsResponse is a array of hash used to Remove extrinsics

type RuntimeAPI

type RuntimeAPI interface {
	ValidateTransaction(e types.Extrinsic) (*transaction.Validity, error)
}

RuntimeAPI is the interface for runtime methods

type StateCallRequest

type StateCallRequest struct {
	Method string      `json:"method"`
	Data   []byte      `json:"data"`
	Block  common.Hash `json:"block"`
}

StateCallRequest holds json fields

type StateCallResponse

type StateCallResponse struct {
	StateCallResponse []byte `json:"stateCallResponse"`
}

StateCallResponse holds json fields

type StateChildStorageRequest

type StateChildStorageRequest struct {
	ChildStorageKey []byte      `json:"childStorageKey"`
	Key             []byte      `json:"key"`
	Block           common.Hash `json:"block"`
}

StateChildStorageRequest holds json fields

type StateKeysResponse

type StateKeysResponse [][]byte

StateKeysResponse field to store the state keys

type StateMetadataResponse

type StateMetadataResponse string

StateMetadataResponse holds the metadata TODO: Determine actual type

type StateModule

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

StateModule is an RPC module providing access to storage API points.

func NewStateModule

func NewStateModule(net NetworkAPI, storage StorageAPI, core CoreAPI) *StateModule

NewStateModule creates a new State module.

func (*StateModule) Call

func (sm *StateModule) Call(r *http.Request, req *StateCallRequest, res *StateCallResponse)

Call isn't implemented properly yet.

func (*StateModule) GetChildKeys

func (sm *StateModule) GetChildKeys(r *http.Request, req *StateChildStorageRequest, res *StateKeysResponse)

GetChildKeys isn't implemented properly yet.

func (*StateModule) GetChildStorage

func (sm *StateModule) GetChildStorage(r *http.Request, req *StateChildStorageRequest, res *StateStorageDataResponse)

GetChildStorage isn't implemented properly yet.

func (*StateModule) GetChildStorageHash

func (sm *StateModule) GetChildStorageHash(r *http.Request, req *StateChildStorageRequest, res *StateStorageHashResponse)

GetChildStorageHash isn't implemented properly yet.

func (*StateModule) GetChildStorageSize

func (sm *StateModule) GetChildStorageSize(r *http.Request, req *StateChildStorageRequest, res *StateStorageSizeResponse)

GetChildStorageSize isn't implemented properly yet.

func (*StateModule) GetKeys

GetKeys isn't implemented properly yet.

func (*StateModule) GetMetadata

func (sm *StateModule) GetMetadata(r *http.Request, req *StateRuntimeMetadataQuery, res *string) error

GetMetadata calls runtime Metadata_metadata function

func (*StateModule) GetPairs

func (sm *StateModule) GetPairs(r *http.Request, req *[]string, res *[]interface{}) error

GetPairs returns the keys with prefix, leave empty to get all the keys.

func (*StateModule) GetRuntimeVersion

func (sm *StateModule) GetRuntimeVersion(r *http.Request, req *string, res *StateRuntimeVersionResponse) error

GetRuntimeVersion Get the runtime version at a given block.

If no block hash is provided, the latest version gets returned.

TODO currently only returns latest version, add functionality to lookup runtime by block hash (see issue #834)

func (*StateModule) GetStorage

func (sm *StateModule) GetStorage(r *http.Request, req *[]string, res *interface{}) error

GetStorage Returns a storage entry at a specific block's state. If not block hash is provided, the latest value is returned.

func (*StateModule) GetStorageHash

func (sm *StateModule) GetStorageHash(r *http.Request, req *[]string, res *interface{}) error

GetStorageHash returns the hash of a storage entry at a block's state.

If no block hash is provided, the latest value is returned.
TODO implement change storage trie so that block hash parameter works (See issue #834)

func (*StateModule) GetStorageSize

func (sm *StateModule) GetStorageSize(r *http.Request, req *[]string, res *interface{}) error

GetStorageSize returns the size of a storage entry at a block's state.

If no block hash is provided, the latest value is used.

TODO implement change storage trie so that block hash parameter works (See issue #834)

func (*StateModule) QueryStorage

QueryStorage isn't implemented properly yet.

func (*StateModule) SubscribeRuntimeVersion

func (sm *StateModule) SubscribeRuntimeVersion(r *http.Request, req *StateStorageQueryRangeRequest, res *StateRuntimeVersionResponse) error

SubscribeRuntimeVersion isn't implemented properly yet. TODO make this actually a subscription that pushes data

func (*StateModule) SubscribeStorage

SubscribeStorage Storage subscription. If storage keys are specified, it creates a message for each block which

changes the specified storage keys. If none are specified, then it creates a message for every block.
This endpoint communicates over the Websocket protocol, but this func should remain here so it's added to rpc_methods list

type StateRuntimeMetadataQuery

type StateRuntimeMetadataQuery common.Hash

StateRuntimeMetadataQuery is a hash value

type StateRuntimeVersionResponse

type StateRuntimeVersionResponse struct {
	SpecName         string        `json:"specName"`
	ImplName         string        `json:"implName"`
	AuthoringVersion int32         `json:"authoringVersion"`
	SpecVersion      int32         `json:"specVersion"`
	ImplVersion      int32         `json:"implVersion"`
	Apis             []interface{} `json:"apis"`
}

StateRuntimeVersionResponse is the runtime version response

type StateStorageDataResponse

type StateStorageDataResponse string

StateStorageDataResponse field to store data response

type StateStorageHashResponse

type StateStorageHashResponse common.Hash

StateStorageHashResponse is a hash value

type StateStorageKeyRequest

type StateStorageKeyRequest struct {
	Key   []byte      `json:"key"`
	Block common.Hash `json:"block"`
}

StateStorageKeyRequest holds json fields

type StateStorageKeysQuery

type StateStorageKeysQuery [][]byte

StateStorageKeysQuery field to store storage keys

type StateStorageKeysResponse

type StateStorageKeysResponse [][]byte

StateStorageKeysResponse field for storage keys

type StateStorageQueryRangeRequest

type StateStorageQueryRangeRequest struct {
	Keys       []byte      `json:"keys"`
	StartBlock common.Hash `json:"startBlock"`
	Block      common.Hash `json:"block"`
}

StateStorageQueryRangeRequest holds json fields

type StateStorageSizeResponse

type StateStorageSizeResponse uint64

StateStorageSizeResponse the default size for response

type StorageAPI

type StorageAPI interface {
	GetStorage(root *common.Hash, key []byte) ([]byte, error)
	GetStorageByBlockHash(bhash common.Hash, key []byte) ([]byte, error)
	Entries(root *common.Hash) (map[string][]byte, error)
	RegisterStorageChangeChannel(ch chan<- *state.KeyValue) (byte, error)
	UnregisterStorageChangeChannel(id byte)
}

StorageAPI is the interface for the storage state

type StorageChangeSetResponse

type StorageChangeSetResponse struct {
	Block   common.Hash
	Changes []KeyValueOption
}

StorageChangeSetResponse is the struct that holds the block and changes

type StorageKey

type StorageKey []byte

StorageKey is the key for the storage

type StringResponse

type StringResponse string

StringResponse holds the string response

type SystemAPI

type SystemAPI interface {
	SystemName() string
	SystemVersion() string
	NodeName() string
	Properties() map[string]interface{}
}

SystemAPI is the interface for handling system methods

type SystemHealthResponse

type SystemHealthResponse struct {
	Health common.Health `json:"health"`
}

SystemHealthResponse struct to marshal json

type SystemModule

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

SystemModule is an RPC module providing access to core API points

func NewSystemModule

func NewSystemModule(net NetworkAPI, sys SystemAPI) *SystemModule

NewSystemModule creates a new API instance

func (*SystemModule) Chain

func (sm *SystemModule) Chain(r *http.Request, req *EmptyRequest, res *string) error

Chain returns the runtime chain

func (*SystemModule) Health

func (sm *SystemModule) Health(r *http.Request, req *EmptyRequest, res *SystemHealthResponse) error

Health returns the information about the health of the network

func (*SystemModule) Name

func (sm *SystemModule) Name(r *http.Request, req *EmptyRequest, res *string) error

Name returns the runtime name

func (*SystemModule) NetworkState

func (sm *SystemModule) NetworkState(r *http.Request, req *EmptyRequest, res *SystemNetworkStateResponse) error

NetworkState returns the network state (basic information about the host)

func (*SystemModule) NodeRoles

func (sm *SystemModule) NodeRoles(r *http.Request, req *EmptyRequest, res *[]interface{}) error

NodeRoles Returns the roles the node is running as.

func (*SystemModule) Peers

func (sm *SystemModule) Peers(r *http.Request, req *EmptyRequest, res *SystemPeersResponse) error

Peers returns peer information for each connected and confirmed peer

func (*SystemModule) Properties

func (sm *SystemModule) Properties(r *http.Request, req *EmptyRequest, res *interface{}) error

Properties returns the runtime properties

func (*SystemModule) Version

func (sm *SystemModule) Version(r *http.Request, req *EmptyRequest, res *string) error

Version returns the runtime version

type SystemNetworkStateResponse

type SystemNetworkStateResponse struct {
	NetworkState NetworkStateString `json:"networkState"`
}

SystemNetworkStateResponse struct to marshal json

type SystemPeersResponse

type SystemPeersResponse struct {
	Peers []common.PeerInfo `json:"peers"`
}

SystemPeersResponse struct to marshal json

type TransactionStateAPI added in v0.2.0

type TransactionStateAPI interface {
	AddToPool(*transaction.ValidTransaction) common.Hash
	Pop() *transaction.ValidTransaction
	Peek() *transaction.ValidTransaction
	Pending() []*transaction.ValidTransaction
}

TransactionStateAPI ...

Jump to

Keyboard shortcuts

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