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.
Index ¶
- Variables
- func DisableLog()
- func EstimateLockInChain(genesisBits, bits, k uint32, amount int64) (int64, error)
- func UseLogger(logger zerolog.Logger)
- func WebSocketHandlers(core *MultiChainRPC) *wsHandler
- func WebSocketManager(server *MultiChainRPC) *wsManager
- type BeaconRPC
- type CommandHandler
- type CommonChainRPC
- func (server *CommonChainRPC) BlockGenerator(useCoinbaseValue bool, burnReward int) (mining.BlockTemplate, error)
- func (server *CommonChainRPC) ComposeHandlers()
- func (server *CommonChainRPC) Handlers() map[jaxjson.MethodName]CommandHandler
- func (server *CommonChainRPC) IsBeacon() bool
- func (server *CommonChainRPC) NotifyNewTransactions(txns []*mempool.TxDesc)
- func (server *CommonChainRPC) OwnHandlers() map[jaxjson.MethodName]CommandHandler
- type Config
- type IWebsocketManager
- type MultiChainRPC
- func (server *MultiChainRPC) AddShard(shardID uint32, rpc *ShardRPC)
- func (server *MultiChainRPC) Run(ctx context.Context)
- func (server *MultiChainRPC) WSHandleFunc() func(w http.ResponseWriter, r *http.Request)
- func (server *MultiChainRPC) WebsocketHandler(conn *websocket.Conn, remoteAddr string, authenticated bool, isAdmin bool)
- type Mux
- type NodeRPC
- type ParsedRPCCmd
- type ServerCore
- func (server *ServerCore) ActiveClients() int32
- func (server *ServerCore) HandleFunc(handler commandMux) func(w http.ResponseWriter, r *http.Request)
- func (server *ServerCore) ReadJsonRPC(w http.ResponseWriter, r *http.Request, isAdmin bool, handler commandMux)
- func (server *ServerCore) RequestedProcessShutdown() <-chan struct{}
- func (server *ServerCore) StartRPC(ctx context.Context, rpcServeMux *http.ServeMux)
- func (server *ServerCore) Stop() error
- func (server *ServerCore) WSHandleFunc() func(w http.ResponseWriter, r *http.Request)
- type ShardManager
- type ShardRPC
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRPCUnimplemented is an error returned to RPC clients when the // provided command is recognized, but not implemented. ErrRPCUnimplemented = &jaxjson.RPCError{ Code: jaxjson.ErrRPCUnimplemented, Message: "Command unimplemented", } // ErrRPCNoWallet is an error returned to RPC clients when the provided // command is recognized as a wallet command. ErrRPCNoWallet = &jaxjson.RPCError{ Code: jaxjson.ErrRPCNoWallet, Message: "This implementation does not implement wallet commands", } )
Errors
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.
var ErrRescanReorg = jaxjson.RPCError{ Code: jaxjson.ErrRPCDatabase, Message: "Reorganize", }
ErrRescanReorg defines the error that is returned when an unrecoverable reorganize is detected during a rescan.
Functions ¶
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.
func EstimateLockInChain ¶ added in v0.3.8
EstimateLockInChain estimates desired period in block for locking funds in shard during the CrossShard Swap Tx.
func UseLogger ¶
UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.
func WebSocketHandlers ¶
func WebSocketHandlers(core *MultiChainRPC) *wsHandler
func WebSocketManager ¶
func WebSocketManager(server *MultiChainRPC) *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[jaxjson.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, burnReward int) (mining.BlockTemplate, error)
func (*CommonChainRPC) ComposeHandlers ¶
func (server *CommonChainRPC) ComposeHandlers()
func (*CommonChainRPC) Handlers ¶
func (server *CommonChainRPC) Handlers() map[jaxjson.MethodName]CommandHandler
func (*CommonChainRPC) IsBeacon ¶
func (server *CommonChainRPC) IsBeacon() bool
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[jaxjson.MethodName]CommandHandler
type Config ¶
type Config struct { ListenerAddresses []string `yaml:"listeners" toml:"listeners"` MaxClients int `yaml:"maxclients" toml:"maxclients"` User string `yaml:"user" toml:"user"` Password string `yaml:"password" toml:"password"` Disable bool `` /* 195-byte string literal not displayed */ RPCCert string `yaml:"rpc_cert" toml:"rpc_cert" long:"rpccert" description:"File containing the certificate file"` RPCKey string `yaml:"rpc_key" toml:"rpc_key" long:"rpckey" description:"File containing the certificate key"` LimitPass string `yaml:"limit_pass" toml:"limit_pass"` LimitUser string `yaml:"limit_user" toml:"limit_user"` MaxConcurrentReqs int `` /* 176-byte string literal not displayed */ MaxWebsockets int `` /* 129-byte string literal not displayed */ WSEnable bool `yaml:"ws_enable" toml:"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 `toml:"-" yaml:"-"` }
Config is a descriptor containing the RPC Server configuration.
type IWebsocketManager ¶
type MultiChainRPC ¶
type MultiChainRPC struct { *ServerCore // contains filtered or unexported fields }
func NewMultiChainRPC ¶
func (*MultiChainRPC) AddShard ¶
func (server *MultiChainRPC) AddShard(shardID uint32, rpc *ShardRPC)
func (*MultiChainRPC) Run ¶
func (server *MultiChainRPC) Run(ctx context.Context)
func (*MultiChainRPC) WSHandleFunc ¶
func (server *MultiChainRPC) WSHandleFunc() func(w http.ResponseWriter, r *http.Request)
func (*MultiChainRPC) WebsocketHandler ¶
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 ¶
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 ¶
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[jaxjson.MethodName]CommandHandler)
type NodeRPC ¶
type NodeRPC struct { Mux StartupTime int64 MiningAddrs []jaxutil.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[jaxjson.MethodName]CommandHandler
type ParsedRPCCmd ¶ added in v0.3.14
type ParsedRPCCmd struct { ID interface{} Scope string Method string ShardID uint32 Cmd interface{} Err *jaxjson.RPCError }
ParsedRPCCmd represents a JSON-RPC request object that has been parsed into a known concrete command along with any error that might have happened while parsing it.
func ParseCmd ¶ added in v0.3.14
func ParseCmd(request *jaxjson.Request) *ParsedRPCCmd
ParseCmd parses a JSON-RPC request object into known concrete command. The err field of the returned ParsedRPCCmd struct will contain an RPC error that is suitable for use in replies if the command is invalid in some way such as an unregistered command or invalid parameters.
type ServerCore ¶
type ServerCore struct {
// contains filtered or unexported fields
}
func NewRPCCore ¶
func NewRPCCore(config *Config) *ServerCore
func (*ServerCore) ActiveClients ¶
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() jaxjson.ShardListResult ShardCtl(id uint32) (*cprovider.ChainProvider, bool) 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[jaxjson.MethodName]CommandHandler