rpc

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: 18 Imported by: 0

Documentation

Overview

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

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

View Source
const (
	SUB_NEW_HEAD = iota
	SUB_FINALIZED_HEAD
	SUB_STORAGE
)

consts to represent subscription type

Variables

This section is empty.

Functions

This section is empty.

Types

type DotUpCodec

type DotUpCodec struct{}

DotUpCodec for overridding default jsonCodec

func NewDotUpCodec

func NewDotUpCodec() *DotUpCodec

NewDotUpCodec for creating instance of DocUpCodec

func (*DotUpCodec) NewRequest

func (c *DotUpCodec) NewRequest(r *http.Request) rpc.CodecRequest

NewRequest is overridden to inject our codec handler

type DotUpCodecRequest

type DotUpCodecRequest struct {
	*json2.CodecRequest
}

DotUpCodecRequest decodes and encodes a single request. UpCodecRequest implements gorilla/rpc.CodecRequest interface primarily by embedding the CodecRequest from gorilla/rpc/json. By selectively adding CodecRequest methods to UpCodecRequest, we can modify that behavior while maintaining all the other remaining CodecRequest methods from gorilla's rpc/json implementation

func (*DotUpCodecRequest) Method

func (c *DotUpCodecRequest) Method() (string, error)

Method returns the decoded method as a string of the form "Service.Method" after checking for, and correcting a underscore and lowercase method name By being of lower depth in the struct , Method will replace the implementation of Method() on the embedded CodecRequest. Because the request data is part of the embedded json.CodecRequest, and unexported, we have to get the requested method name via the embedded CR's own method Method(). Essentially, this just intercepts the return value from the embedded gorilla/rpc/json.CodecRequest.Method(), checks/modifies it, and passes it on to the calling rpc server.

type ErrorMessageJSON

type ErrorMessageJSON struct {
	Code    *big.Int `json:"code"`
	Message string   `json:"message"`
}

ErrorMessageJSON json for error messages

type ErrorResponseJSON

type ErrorResponseJSON struct {
	Jsonrpc string            `json:"jsonrpc"`
	Error   *ErrorMessageJSON `json:"error"`
	ID      *big.Int          `json:"id"`
}

ErrorResponseJSON json for error responses

type HTTPServer

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

HTTPServer gateway for RPC server

func NewHTTPServer

func NewHTTPServer(cfg *HTTPServerConfig) *HTTPServer

NewHTTPServer creates a new http server and registers an associated rpc server

func (*HTTPServer) RegisterModules

func (h *HTTPServer) RegisterModules(mods []string)

RegisterModules registers the RPC services associated with the given API modules

func (*HTTPServer) ServeHTTP

func (h *HTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implemented to handle WebSocket connections

func (*HTTPServer) Start

func (h *HTTPServer) Start() error

Start registers the rpc handler function and starts the rpc http and websocket server

func (*HTTPServer) Stop

func (h *HTTPServer) Stop() error

Stop stops the server

type HTTPServerConfig

type HTTPServerConfig struct {
	BlockAPI               modules.BlockAPI
	StorageAPI             modules.StorageAPI
	NetworkAPI             modules.NetworkAPI
	CoreAPI                modules.CoreAPI
	RuntimeAPI             modules.RuntimeAPI
	TransactionQueueAPI    modules.TransactionQueueAPI
	RPCAPI                 modules.RPCAPI
	SystemAPI              modules.SystemAPI
	Host                   string
	RPCPort                uint32
	WSEnabled              bool
	WSPort                 uint32
	Modules                []string
	WSSubscriptions        map[uint32]*WebSocketSubscription
	BlockAddedReceiver     chan *types.Block
	BlockAddedReceiverDone chan struct{}
}

HTTPServerConfig configures the HTTPServer

type Service

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

Service struct to hold rpc service data

func NewService

func NewService() *Service

NewService create a new instance of Service

func (*Service) BuildMethodNames

func (s *Service) BuildMethodNames(rcvr interface{}, name string)

BuildMethodNames takes receiver interface and populates rpcMethods array with available

method names

func (*Service) Methods

func (s *Service) Methods() []string

Methods returns list of methods available via RPC call

type SubscriptionBaseResponseJSON

type SubscriptionBaseResponseJSON struct {
	Jsonrpc      string      `json:"jsonrpc"`
	Method       string      `json:"method"`
	Params       interface{} `json:"params"`
	Subscription uint32      `json:"subscription"`
}

SubscriptionBaseResponseJSON for base json response

type SubscriptionResponseJSON

type SubscriptionResponseJSON struct {
	Jsonrpc string  `json:"jsonrpc"`
	Result  uint32  `json:"result"`
	ID      float64 `json:"id"`
}

SubscriptionResponseJSON for json subscription responses

type WebSocketSubscription

type WebSocketSubscription struct {
	WSConnection     *websocket.Conn
	SubscriptionType int
}

WebSocketSubscription holds subscription details

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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