Documentation ¶
Index ¶
- Constants
- Variables
- func GenCertPair(certFile, keyFile string) error
- func GetTxsHexFromBlock(block *types.SerializedBlock, duplicate bool) ([]string, error)
- func RPCClientInInitialDownloadError(err, context string) error
- func RpcAddressKeyError(fmtStr string, args ...interface{}) error
- func RpcDecodeHexError(gotHex string) error
- func RpcDeserializationError(fmtStr string, args ...interface{}) error
- func RpcDuplicateTxError(fmtStr string, args ...interface{}) error
- func RpcInternalError(err, context string) error
- func RpcInvalidError(fmtStr string, args ...interface{}) error
- func RpcNoTxInfoError(txHash *hash.Hash) error
- func RpcRuleError(fmtStr string, args ...interface{}) error
- func RpcSubmitError(fmtStr string, args ...interface{}) error
- func UseLogger(logger l.Logger)
- type CodecOption
- type Error
- type ID
- type Notifier
- type RequestStatus
- type RpcServer
- func (s *RpcServer) AddRequstStatus(sReq *serverRequest)
- func (s *RpcServer) NotifyBlockTemplate(bt *json.RemoteGBTResult)
- func (s *RpcServer) NotifyNewTransactions(txns []*types.TxDesc)
- func (s *RpcServer) RegisterService(namespace string, regSvc interface{}) error
- func (s *RpcServer) RemoveRequstStatus(sReq *serverRequest)
- func (s *RpcServer) RequestedProcessShutdown() chan struct{}
- func (s *RpcServer) ServeSingleRequest(ctx context.Context, codec ServerCodec, options CodecOption)
- func (s *RpcServer) Start() error
- func (s *RpcServer) Stop() error
- func (s *RpcServer) WebsocketHandler(conn *websocket.Conn, remoteAddr string, isAdmin bool)
- type ServerCodec
- type SessionResult
- type Subscription
- type TxConfirm
- type WSCodec
- func (c *WSCodec) Close()
- func (c *WSCodec) Closed() <-chan interface{}
- func (c *WSCodec) CreateErrorResponse(id interface{}, err Error) interface{}
- func (c *WSCodec) CreateErrorResponseWithInfo(id interface{}, err Error, info interface{}) interface{}
- func (c *WSCodec) CreateNotification(subid, namespace string, event interface{}) interface{}
- func (c *WSCodec) CreateResponse(id interface{}, reply interface{}) interface{}
- func (c *WSCodec) ParseRequestArguments(argTypes []reflect.Type, params interface{}) ([]reflect.Value, Error)
- func (c *WSCodec) ReadRequestHeaders() ([]rpcRequest, bool, Error)
- func (c *WSCodec) Write(res interface{}) error
- type WatchTxConfirmServer
- func (w *WatchTxConfirmServer) AddTxConfirms(confirm TxConfirm)
- func (w *WatchTxConfirmServer) Handle(wsc *wsClient, currentHeight uint64)
- func (w *WatchTxConfirmServer) RemoveTxConfirms(confirm TxConfirm)
- func (w *WatchTxConfirmServer) SendTxNotification(tx string, confirms uint64, wsc *wsClient, isBlue, isValid bool)
Constants ¶
const MaxInvPerMsg = 50000
MaxInvPerMsg is the maximum number of inventory vectors that can be in a single inv message.
Variables ¶
var ( // ErrNotificationsUnsupported is returned when the connection doesn't support notifications ErrNotificationsUnsupported = errors.New("notifications not supported") // ErrNotificationNotFound is returned when the notification for the given id is not found ErrSubscriptionNotFound = errors.New("subscription not found") )
var ErrClientQuit = errors.New("client quit")
var ErrRescanReorg = cmds.ErrRPCDatabase
ErrRescanReorg defines the error that is returned when an unrecoverable reorganize is detected during a rescan.
Functions ¶
func GenCertPair ¶
genCertPair generates a key/cert pair to the paths provided.
func GetTxsHexFromBlock ¶
func GetTxsHexFromBlock(block *types.SerializedBlock, duplicate bool) ([]string, error)
func RPCClientInInitialDownloadError ¶
LL(getblocktemplate RPC) 2018-10-28 client errors.
func RpcAddressKeyError ¶
RpcAddressKeyError is a convenience function to convert an address/key error to an RPC error.
func RpcDecodeHexError ¶
RpcDecodeHexError is a convenience function for returning a nicely formatted RPC error which indicates the provided hex string failed to decode.
func RpcDeserializationError ¶
RpcDeserializetionError is a convenience function to convert a deserialization error to an RPC error
func RpcDuplicateTxError ¶
RpcDuplicateTxError is a convenience function to convert a rejected duplicate tx error to an RPC error
func RpcInternalError ¶
func RpcInvalidError ¶
RpcInvalidError is a convenience function to convert an invalid parameter error to an RPC error with the appropriate code set.
func RpcNoTxInfoError ¶
RpcNoTxInfoError is a convenience function for returning a nicely formatted RPC error which indicates there is no information available for the provided transaction hash.
func RpcRuleError ¶
RpcRuleError is a convenience function to convert a rule error to an RPC error
func RpcSubmitError ¶
Types ¶
type CodecOption ¶
type CodecOption int
CodecOption specifies which type of messages this codec supports
const ( // OptionMethodInvocation is an indication that the codec supports RPC method calls OptionMethodInvocation CodecOption = 1 << iota // OptionSubscriptions is an indication that the codec suports RPC notifications OptionSubscriptions = 1 << iota // support pub sub )
type ID ¶
type ID string
ID defines a pseudo random number that is used to identify RPC subscriptions.
type Notifier ¶
type Notifier struct {
// contains filtered or unexported fields
}
Notifier is tight to a RPC connection that supports subscriptions. Server callbacks use the notifier to send notifications.
func NotifierFromContext ¶
NotifierFromContext returns the Notifier value stored in ctx, if any.
func (*Notifier) Closed ¶
func (n *Notifier) Closed() <-chan interface{}
Closed returns a channel that is closed when the RPC connection is closed.
func (*Notifier) CreateSubscription ¶
func (n *Notifier) CreateSubscription() *Subscription
CreateSubscription returns a new subscription that is coupled to the RPC connection. By default subscriptions are inactive and notifications are dropped until the subscription is marked as active. This is done by the RPC server after the subscription ID is send to the client.
type RequestStatus ¶
type RequestStatus struct { Service string Method string TotalCalls uint TotalTime time.Duration MaxTime time.Duration MinTime time.Duration MaxTimeReqID string MinTimeReqID string Requests []*serverRequest }
func NewRequestStatus ¶
func NewRequestStatus(sReq *serverRequest) (*RequestStatus, error)
func (*RequestStatus) AddRequst ¶
func (rs *RequestStatus) AddRequst(sReq *serverRequest)
func (*RequestStatus) GetName ¶
func (rs *RequestStatus) GetName() string
func (*RequestStatus) RemoveRequst ¶
func (rs *RequestStatus) RemoveRequst(sReq *serverRequest)
func (*RequestStatus) ToJson ¶
func (rs *RequestStatus) ToJson() *cmds.JsonRequestStatus
type RpcServer ¶
type RpcServer struct { ser.Service ReqStatus map[string]*RequestStatus BC *blockchain.BlockChain ChainParams *params.Params // contains filtered or unexported fields }
RpcServer provides a concurrent safe RPC server to a chain server.
func NewRPCServer ¶
newRPCServer returns a new instance of the rpcServer struct.
func (*RpcServer) AddRequstStatus ¶
func (s *RpcServer) AddRequstStatus(sReq *serverRequest)
func (*RpcServer) NotifyBlockTemplate ¶
func (s *RpcServer) NotifyBlockTemplate(bt *json.RemoteGBTResult)
func (*RpcServer) NotifyNewTransactions ¶
func (*RpcServer) RegisterService ¶
RegisterService will create a service for the given type under the given namespace. When no methods on the given type match the criteria to be either a RPC method or a subscription an error is returned. Otherwise a new service is created and added to the service registry.
func (*RpcServer) RemoveRequstStatus ¶
func (s *RpcServer) RemoveRequstStatus(sReq *serverRequest)
func (*RpcServer) RequestedProcessShutdown ¶
func (s *RpcServer) RequestedProcessShutdown() chan struct{}
func (*RpcServer) ServeSingleRequest ¶
func (s *RpcServer) ServeSingleRequest(ctx context.Context, codec ServerCodec, options CodecOption)
ServeSingleRequest reads and processes a single RPC request from the given codec. It will not close the codec unless a non-recoverable error has occurred. Note, this method will return after a single request has been processed!
type ServerCodec ¶
type ServerCodec interface { // Read next request ReadRequestHeaders() ([]rpcRequest, bool, Error) // Parse request argument to the given types ParseRequestArguments(argTypes []reflect.Type, params interface{}) ([]reflect.Value, Error) // Assemble success response, expects response id and payload CreateResponse(id interface{}, reply interface{}) interface{} // Assemble error response, expects response id and error CreateErrorResponse(id interface{}, err Error) interface{} // Assemble error response with extra information about the error through info CreateErrorResponseWithInfo(id interface{}, err Error, info interface{}) interface{} // Create notification response CreateNotification(id, namespace string, event interface{}) interface{} // Write msg to client. Write(msg interface{}) error // Close underlying data stream Close() // Closed when underlying connection is closed Closed() <-chan interface{} }
ServerCodec implements reading, parsing and writing RPC messages for the server side of a RPC session. Implementations must be go-routine safe since the codec can be called in multiple go-routines concurrently.
func NewCodec ¶
func NewCodec(rwc io.ReadWriteCloser, encode, decode func(v interface{}) error) ServerCodec
NewCodec creates a new RPC server codec with support for JSON-RPC 2.0 based on explicitly given encoding and decoding methods.
func NewJSONCodec ¶
func NewJSONCodec(rwc io.ReadWriteCloser) ServerCodec
NewJSONCodec creates a new RPC server codec with support for JSON-RPC 2.0.
type SessionResult ¶
type SessionResult struct {
SessionID uint64 `json:"sessionid"`
}
type Subscription ¶
type Subscription struct { ID ID // contains filtered or unexported fields }
a Subscription is created by a notifier and tight to that notifier. The client can use this subscription to wait for an unsubscribe request for the client, see Err().
func (*Subscription) Err ¶
func (s *Subscription) Err() <-chan error
Err returns a channel that is closed when the client send an unsubscribe request.
type WSCodec ¶
type WSCodec struct {
// contains filtered or unexported fields
}
func NewWSCodec ¶
func (*WSCodec) Closed ¶
func (c *WSCodec) Closed() <-chan interface{}
Closed returns a channel which will be closed when Close is called
func (*WSCodec) CreateErrorResponse ¶
CreateErrorResponse will create a JSON-RPC error response with the given id and error.
func (*WSCodec) CreateErrorResponseWithInfo ¶
func (c *WSCodec) CreateErrorResponseWithInfo(id interface{}, err Error, info interface{}) interface{}
CreateErrorResponseWithInfo will create a JSON-RPC error response with the given id and error. info is optional and contains additional information about the error. When an empty string is passed it is ignored.
func (*WSCodec) CreateNotification ¶
CreateNotification will create a JSON-RPC notification with the given subscription id and event as params.
func (*WSCodec) CreateResponse ¶
func (c *WSCodec) CreateResponse(id interface{}, reply interface{}) interface{}
CreateResponse will create a JSON-RPC success response with the given id and reply as result.
func (*WSCodec) ParseRequestArguments ¶
func (*WSCodec) ReadRequestHeaders ¶
type WatchTxConfirmServer ¶
func (*WatchTxConfirmServer) AddTxConfirms ¶
func (w *WatchTxConfirmServer) AddTxConfirms(confirm TxConfirm)
func (*WatchTxConfirmServer) Handle ¶
func (w *WatchTxConfirmServer) Handle(wsc *wsClient, currentHeight uint64)
func (*WatchTxConfirmServer) RemoveTxConfirms ¶
func (w *WatchTxConfirmServer) RemoveTxConfirms(confirm TxConfirm)
func (*WatchTxConfirmServer) SendTxNotification ¶
func (w *WatchTxConfirmServer) SendTxNotification(tx string, confirms uint64, wsc *wsClient, isBlue, isValid bool)