rpc

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2021 License: ISC Imports: 50 Imported by: 0

Documentation

Overview

Copyright (c) 2020 The JaxNetwork developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2020 The JaxNetwork developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2020 The JaxNetwork developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2020 The JaxNetwork developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2020 The JaxNetwork developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2020 The JaxNetwork developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2020 The JaxNetwork developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2020 The JaxNetwork developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2020 The JaxNetwork developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRPCUnimplemented is an error returned to RPC clients when the
	// provided command is recognized, but not implemented.
	ErrRPCUnimplemented = &btcjson.RPCError{
		Code:    btcjson.ErrRPCUnimplemented,
		Message: "Command unimplemented",
	}

	// ErrRPCNoWallet is an error returned to RPC clients when the provided
	// command is recognized as a wallet command.
	ErrRPCNoWallet = &btcjson.RPCError{
		Code:    btcjson.ErrRPCNoWallet,
		Message: "This implementation does not implement wallet commands",
	}
)

Errors

View Source
var ErrClientQuit = errors.New("client quit")

ErrClientQuit describes the error where a client send is not processed due to the client having already been disconnected or dropped.

View Source
var ErrRescanReorg = btcjson.RPCError{
	Code:    btcjson.ErrRPCDatabase,
	Message: "Reorganize",
}

ErrRescanReorg defines the error that is returned when an unrecoverable reorganize is detected during a rescan.

Functions

func WebSocketHandlers added in v0.1.6

func WebSocketHandlers(core *MultiChainRPC) *wsHandler

func WebSocketManager added in v0.1.6

func WebSocketManager(server *MultiChainRPC, logger zerolog.Logger) *wsManager

newWsNotificationManager returns a new notification manager ready for use. See wsNotificationManager for more details.

Types

type BeaconRPC

type BeaconRPC struct {
	*CommonChainRPC
}

func NewBeaconRPC

func NewBeaconRPC(chainProvider *cprovider.ChainProvider,
	connMgr netsync.P2PConnManager, logger zerolog.Logger) *BeaconRPC

func (*BeaconRPC) ComposeHandlers

func (server *BeaconRPC) ComposeHandlers()

func (*BeaconRPC) Handlers

func (server *BeaconRPC) Handlers() map[btcjson.MethodName]CommandHandler

type CommandHandler

type CommandHandler func(interface{}, <-chan struct{}) (interface{}, error)

type CommonChainRPC

type CommonChainRPC struct {
	Mux
	// contains filtered or unexported fields
}

func NewCommonChainRPC

func NewCommonChainRPC(chainProvider *cprovider.ChainProvider, connMgr netsync.P2PConnManager,
	logger zerolog.Logger) *CommonChainRPC

func (*CommonChainRPC) BlockGenerator

func (server *CommonChainRPC) BlockGenerator(useCoinbaseValue bool) (mining.BlockTemplate, error)

func (*CommonChainRPC) ComposeHandlers

func (server *CommonChainRPC) ComposeHandlers()

func (*CommonChainRPC) Handlers

func (server *CommonChainRPC) Handlers() map[btcjson.MethodName]CommandHandler

func (*CommonChainRPC) NotifyNewTransactions

func (server *CommonChainRPC) NotifyNewTransactions(txns []*mempool.TxDesc)

NotifyNewTransactions notifies both websocket and getblocktemplate long poll clients of the passed transactions. This function should be called whenever new transactions are added to the mempool.

func (*CommonChainRPC) OwnHandlers

func (server *CommonChainRPC) OwnHandlers() map[btcjson.MethodName]CommandHandler

type Config

type Config struct {
	ListenerAddresses []string `yaml:"listeners"`
	MaxClients        int      `yaml:"maxclients"`
	User              string   `yaml:"user"`
	Password          string   `yaml:"password"`
	Disable           bool     `` /* 180-byte string literal not displayed */
	RPCCert           string   `yaml:"rpc_cert" long:"rpccert" description:"File containing the certificate file"`
	RPCKey            string   `yaml:"rpc_key" long:"rpckey" description:"File containing the certificate key"`
	LimitPass         string   `yaml:"limit_pass"`
	LimitUser         string   `yaml:"limit_user"`
	MaxConcurrentReqs int      `` /* 145-byte string literal not displayed */
	MaxWebsockets     int      `yaml:"max_websockets" long:"rpcmaxwebsockets" description:"Max number of RPC websocket connections"`
	WSEnable          bool     `yaml:"ws_enable"`

	// Listeners defines a slice of listeners for which the RPC Server will
	// take ownership of and accept connections.  Since the RPC Server takes
	// ownership of these listeners, they will be closed when the RPC Server
	// is stopped.
	Listeners []net.Listener `yaml:"-"`
}

Config is a descriptor containing the RPC Server configuration.

func (*Config) SetupRPCListeners

func (cfg *Config) SetupRPCListeners() ([]net.Listener, error)

SetupRPCListeners returns a slice of listeners that are configured for use with the RPC server depending on the configuration settings for listen addresses and TLS.

type IWebsocketManager added in v0.1.6

type IWebsocketManager interface {
	Start(ctx context.Context)
}

type MultiChainRPC

type MultiChainRPC struct {
	*ServerCore
	// contains filtered or unexported fields
}

func NewMultiChainRPC

func NewMultiChainRPC(config *Config, logger zerolog.Logger,
	nodeRPC *NodeRPC, beaconRPC *BeaconRPC, shardRPCs map[uint32]*ShardRPC) *MultiChainRPC

func (*MultiChainRPC) AddShard

func (server *MultiChainRPC) AddShard(shardID uint32, rpc *ShardRPC)

func (*MultiChainRPC) Run

func (server *MultiChainRPC) Run(ctx context.Context)

func (*MultiChainRPC) WSHandleFunc added in v0.1.6

func (server *MultiChainRPC) WSHandleFunc() func(w http.ResponseWriter, r *http.Request)

func (*MultiChainRPC) WebsocketHandler added in v0.1.6

func (server *MultiChainRPC) WebsocketHandler(conn *websocket.Conn, remoteAddr string,
	authenticated bool, isAdmin bool)

WebsocketHandler handles a new websocket client by creating a new wsClient, starting it, and blocking until the connection closes. Since it blocks, it must be run in a separate goroutine. It should be invoked from the websocket server handler which runs each new connection in a new goroutine thereby satisfying the requirement.

type Mux

type Mux struct {
	rpcutli.ToolsXt
	Log zerolog.Logger
	// contains filtered or unexported fields
}

func NewRPCMux

func NewRPCMux(logger zerolog.Logger) Mux

func (*Mux) HandleCommand

func (server *Mux) HandleCommand(cmd *parsedRPCCmd, closeChan <-chan struct{}) (interface{}, error)

HandleCommand checks that a parsed command is a standard Bitcoin JSON-RPC command and runs the appropriate handler to reply to the command. Any commands which are not recognized or not implemented will return an error suitable for use in replies.

func (*Mux) InternalRPCError

func (server *Mux) InternalRPCError(errStr, context string) *btcjson.RPCError

InternalRPCError is a convenience function to convert an internal error to an RPC error with the appropriate code set. It also logs the error to the RPC server subsystem since internal errors really should not occur. The context parameter is only used in the log message and may be empty if it's not needed.

func (*Mux) SetCommands

func (server *Mux) SetCommands(commands map[btcjson.MethodName]CommandHandler)

type NodeRPC

type NodeRPC struct {
	Mux

	StartupTime int64
	MiningAddrs []btcutil.Address
	CPUMiner    cpuminer.CPUMiner
	// contains filtered or unexported fields
}

func NewNodeRPC

func NewNodeRPC(provider *cprovider.ChainProvider, shardsMgr ShardManager, logger zerolog.Logger) *NodeRPC

func (*NodeRPC) ComposeHandlers

func (server *NodeRPC) ComposeHandlers()

func (*NodeRPC) OwnHandlers

func (server *NodeRPC) OwnHandlers() map[btcjson.MethodName]CommandHandler

type ServerCore

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

func NewRPCCore

func NewRPCCore(config *Config, logger zerolog.Logger) *ServerCore

func (*ServerCore) ActiveClients added in v0.1.6

func (server *ServerCore) ActiveClients() int32

func (*ServerCore) HandleFunc

func (server *ServerCore) HandleFunc(handler commandMux) func(w http.ResponseWriter, r *http.Request)

func (*ServerCore) ReadJsonRPC

func (server *ServerCore) ReadJsonRPC(w http.ResponseWriter, r *http.Request, isAdmin bool, handler commandMux)

ReadJsonRPC handles reading and responding to RPC messages.

func (*ServerCore) RequestedProcessShutdown

func (server *ServerCore) RequestedProcessShutdown() <-chan struct{}

RequestedProcessShutdown returns a channel that is sent to when an authorized RPC client requests the process to shutdown. If the request can not be read immediately, it is dropped.

func (*ServerCore) StartRPC

func (server *ServerCore) StartRPC(ctx context.Context, rpcServeMux *http.ServeMux)

func (*ServerCore) Stop

func (server *ServerCore) Stop() error

Stop is used by rpc.go to stop the rpc listener.

func (*ServerCore) WSHandleFunc

func (server *ServerCore) WSHandleFunc() func(w http.ResponseWriter, r *http.Request)

type ShardManager

type ShardManager interface {
	ListShards() btcjson.ShardListResult

	EnableShard(shardID uint32) error

	DisableShard(shardID uint32) error
}

type ShardRPC

type ShardRPC struct {
	*CommonChainRPC
	// contains filtered or unexported fields
}

func NewShardRPC

func NewShardRPC(chainProvider *cprovider.ChainProvider,
	connMgr netsync.P2PConnManager,
	logger zerolog.Logger) *ShardRPC

func (*ShardRPC) ComposeHandlers

func (server *ShardRPC) ComposeHandlers()

func (*ShardRPC) HandleCommand

func (server *ShardRPC) HandleCommand(cmd *parsedRPCCmd, closeChan <-chan struct{}) (interface{}, error)

func (*ShardRPC) OwnHandlers

func (server *ShardRPC) OwnHandlers() map[btcjson.MethodName]CommandHandler

Jump to

Keyboard shortcuts

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