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. nolint: forcetypeassert
nolint: forcetypeassert
nolint: forcetypeassert
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. nolint: forcetypeassert
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. nolint: forcetypeassert
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. nolint: forcetypeassert
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. nolint: forcetypeassert
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. nolint: forcetypeassert
Copyright (c) 2013-2017 The btcsuite developers Copyright (c) 2015-2017 The Decred developers 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. nolint: forcetypeassert
nolint: forcetypeassert
nolint: forcetypeassert
nolint: forcetypeassert
Index ¶
- Variables
- func DisableLog()
- func EstimateLockInChain(bits, k uint32, amount int64) (int64, error)
- func UseLogger(logger zerolog.Logger)
- func WebSocketHandlers(core *MultiChainRPC) *wsHandler
- type BeaconRPC
- type CmdCtx
- type CommandHandler
- type CommonChainRPC
- func (server *CommonChainRPC) BlockGenerator(useCoinbaseValue bool, burnReward int) (chaindata.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 MetricsManager
- 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, authCtx interface{}, ...)
- 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
- type WsManager
- func (m *WsManager) AddClient(wsc *wsClient)
- func (m *WsManager) NumClients() (n int)
- func (m *WsManager) RegisterBlockUpdates(wsc *wsClient, shardID uint32)
- func (m *WsManager) RegisterNewMempoolTxsUpdates(wsc *wsClient)
- func (m *WsManager) RegisterSpentRequests(chain *cprovider.ChainProvider, wsc *wsClient, ops []*wire.OutPoint)
- func (m *WsManager) RegisterTxOutAddressRequests(chain *cprovider.ChainProvider, wsc *wsClient, addrs []string)
- func (m *WsManager) RemoveClient(wsc *wsClient)
- func (m *WsManager) Start(ctx context.Context)
- func (m *WsManager) UnregisterBlockUpdates(wsc *wsClient, shardID uint32)
- func (m *WsManager) UnregisterNewMempoolTxsUpdates(wsc *wsClient)
- func (m *WsManager) UnregisterSpentRequest(chain *cprovider.ChainProvider, wsc *wsClient, op *wire.OutPoint)
- func (m *WsManager) UnregisterTxOutAddressRequest(chain *cprovider.ChainProvider, wsc *wsClient, addr string)
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. nolint: gomnd
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
nolint: golint, revive
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 CmdCtx ¶ added in v0.4.3
type CmdCtx struct { ID interface{} Cmd interface{} CloseChan <-chan struct{} AuthCtx interface{} }
type CommandHandler ¶
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) (chaindata.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 `` /* 182-byte string literal not displayed */ RPCCert string `yaml:"rpc_cert" toml:"rpc_cert" description:"File containing the certificate file"` RPCKey string `yaml:"rpc_key" toml:"rpc_key" description:"File containing the certificate key"` LimitPass string `yaml:"limit_pass" toml:"limit_pass"` LimitUser string `yaml:"limit_user" toml:"limit_user"` MaxConcurrentReqs int `` /* 148-byte string literal not displayed */ MaxWebsockets int `yaml:"rpc_max_websockets" toml:"rpc_max_websockets" description:"Max number of RPC websocket connections"` DisableTLS bool `` /* 152-byte string literal not displayed */ WSEnable bool `yaml:"ws_enable" toml:"ws_enable"` // custom handler for auth, instead of standard login and password. First return value indicates if user is authorized or not. // Second return value indicated is it is a limited user // All standard password checks are ignored if this function is provided when creating RPC server AuthProvider func(r *http.Request) (interface{}, bool, bool) ResponseHook func(request *jaxjson.Request, headers http.Header, response interface{}, marshalledResponse []byte) // 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 MetricsManager ¶ added in v0.4.2
type MetricsManager interface { GetNodeMetrics() jaxjson.GetNodeMetricsResult GetChainMetrics() jaxjson.GetChainMetricsResult }
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(beaconChain *cprovider.ChainProvider, shardsMgr ShardManager, logger zerolog.Logger, metricsMgr MetricsManager, cpuMiner *cpuminer.CPUMiner) *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 AuthCtx interface{} }
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 ¶ added in v0.4.3
func (server *ServerCore) ReadJSONRPC(w http.ResponseWriter, r *http.Request, isAdmin bool, authCtx interface{}, 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)
nolint: errcheck
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
}
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
type WsManager ¶ added in v0.4.0
WsManager is a connection and notification manager used for websockets. It allows websocket clients to register for notifications they are interested in. When an event happens elsewhere in the code such as transactions being added to the memory pool or block connects/disconnects, the notification manager is provided with the relevant details needed to figure out which websocket clients need to be notified based on what they have registered for and notifies them accordingly. It is also used to keep track of all connected websocket clients.
func WebSocketManager ¶
func WebSocketManager(server *MultiChainRPC) *WsManager
WebSocketManager returns a new notification manager ready for use. See wsNotificationManager for more details.
func (*WsManager) AddClient ¶ added in v0.4.0
func (m *WsManager) AddClient(wsc *wsClient)
AddClient adds the passed websocket client to the notification manager.
func (*WsManager) NumClients ¶ added in v0.4.0
NumClients returns the number of clients actively being served.
func (*WsManager) RegisterBlockUpdates ¶ added in v0.4.0
RegisterBlockUpdates requests block update notifications to the passed websocket client.
func (*WsManager) RegisterNewMempoolTxsUpdates ¶ added in v0.4.0
func (m *WsManager) RegisterNewMempoolTxsUpdates(wsc *wsClient)
RegisterNewMempoolTxsUpdates requests notifications to the passed websocket client when new transactions are added to the memory pool.
func (*WsManager) RegisterSpentRequests ¶ added in v0.4.0
func (m *WsManager) RegisterSpentRequests(chain *cprovider.ChainProvider, wsc *wsClient, ops []*wire.OutPoint)
RegisterSpentRequests requests a notification when each of the passed outpoints is confirmed spent (contained in a block connected to the main BlockChain) for the passed websocket client. The request is automatically removed once the notification has been sent.
func (*WsManager) RegisterTxOutAddressRequests ¶ added in v0.4.0
func (m *WsManager) RegisterTxOutAddressRequests(chain *cprovider.ChainProvider, wsc *wsClient, addrs []string)
RegisterTxOutAddressRequests requests notifications to the passed websocket client when a transaction output spends to the passed address.
func (*WsManager) RemoveClient ¶ added in v0.4.0
func (m *WsManager) RemoveClient(wsc *wsClient)
RemoveClient removes the passed websocket client and all notifications registered for it.
func (*WsManager) UnregisterBlockUpdates ¶ added in v0.4.0
UnregisterBlockUpdates removes block update notifications for the passed websocket client.
func (*WsManager) UnregisterNewMempoolTxsUpdates ¶ added in v0.4.0
func (m *WsManager) UnregisterNewMempoolTxsUpdates(wsc *wsClient)
UnregisterNewMempoolTxsUpdates removes notifications to the passed websocket client when new transaction are added to the memory pool.
func (*WsManager) UnregisterSpentRequest ¶ added in v0.4.0
func (m *WsManager) UnregisterSpentRequest(chain *cprovider.ChainProvider, wsc *wsClient, op *wire.OutPoint)
UnregisterSpentRequest removes a request from the passed websocket client to be notified when the passed outpoint is confirmed spent (contained in a block connected to the main BlockChain).
func (*WsManager) UnregisterTxOutAddressRequest ¶ added in v0.4.0
func (m *WsManager) UnregisterTxOutAddressRequest(chain *cprovider.ChainProvider, wsc *wsClient, addr string)
UnregisterTxOutAddressRequest removes a request from the passed websocket client to be notified when a transaction spends to the passed address.