Documentation ¶
Index ¶
- Constants
- Variables
- func ForwardCall(request jsonrpc.RPCRequest) ([]byte, error)
- func InitResponseCache(c ResponseCache)
- func MarshalResponse(r *jsonrpc.RPCResponse) ([]byte, error)
- func MethodRequiresAccountID(method string) bool
- func NewErrorResponse(message string, code int) *jsonrpc.RPCResponse
- func NewRequest(method string, params ...interface{}) jsonrpc.RPCRequest
- func Proxy(r *jsonrpc.RPCRequest, accountID string) ([]byte, error)
- func RawCall(request jsonrpc.RPCRequest) (*jsonrpc.RPCResponse, error)
- func UnmarshalRequest(r []byte) (*jsonrpc.RPCRequest, error)
- type AuthFailed
- type CallError
- type Caller
- type GenericError
- type Preprocessor
- type Query
- type RequestHandler
- type ResponseCache
- type Service
Constants ¶
const ErrAuthFailed int = -32085
ErrAuthFailed is when supplied auth_token / account_id is not present in the database.
const ErrInternal int = -32603
ErrInternal is a general server error code
const ErrInvalidParams int = -32602
ErrInvalidParams signifies a client-supplied params error
const ErrInvalidRequest int = -32600
ErrInvalidRequest signifies a general client error
const ErrJSONParse int = -32700
ErrJSONParse means invalid JSON was received by the server.
ErrMethodUnavailable means the client-requested method cannot be found
const ErrProxy int = -32080
ErrProxy is for general errors that originate inside the proxy module
const MethodAccountBalance = "account_balance"
const MethodAccountList = "account_list"
const MethodClaimSearch = "claim_search"
const MethodCommentList = "comment_list"
const MethodFileList = "file_list"
const MethodGet = "get"
const MethodResolve = "resolve"
const MethodStatus = "status"
Variables ¶
var ResolveTime float64
Functions ¶
func ForwardCall ¶
func ForwardCall(request jsonrpc.RPCRequest) ([]byte, error)
ForwardCall passes a prepared jsonrpc request to the SDK and calls post-processors on the response.
func InitResponseCache ¶
func InitResponseCache(c ResponseCache)
InitResponseCache initializes module-level responseCache variable
func MarshalResponse ¶
func MarshalResponse(r *jsonrpc.RPCResponse) ([]byte, error)
MarshalResponse takes a raw json request body and serializes it into RPCRequest struct for further processing.
func MethodRequiresAccountID ¶
func NewErrorResponse ¶
func NewErrorResponse(message string, code int) *jsonrpc.RPCResponse
NewErrorResponse is a shorthand for creating an RPCResponse instance with specified error message and code
func NewRequest ¶
func NewRequest(method string, params ...interface{}) jsonrpc.RPCRequest
func Proxy ¶
func Proxy(r *jsonrpc.RPCRequest, accountID string) ([]byte, error)
Proxy takes a parsed jsonrpc request, calls processors on it and passes it over to the daemon. If accountID is supplied, it's injected as a request param.
func RawCall ¶
func RawCall(request jsonrpc.RPCRequest) (*jsonrpc.RPCResponse, error)
RawCall makes an arbitrary jsonrpc request to the SDK
func UnmarshalRequest ¶
func UnmarshalRequest(r []byte) (*jsonrpc.RPCRequest, error)
UnmarshalRequest takes a raw json request body and serializes it into RPCRequest struct for further processing.
Types ¶
type AuthFailed ¶ added in v0.7.0
type AuthFailed struct {
CallError
}
AuthFailed is for authentication failures when jsonrpc client has provided a token
func (AuthFailed) Code ¶ added in v0.7.0
func (e AuthFailed) Code() int
Code returns JSRON-RPC error code
func (AuthFailed) Error ¶ added in v0.7.0
func (e AuthFailed) Error() string
type CallError ¶ added in v0.7.0
type CallError interface { AsRPCResponse() *jsonrpc.RPCResponse Code() int Error() string }
CallError is for whatever errors might occur when processing or forwarding client JSON-RPC request
type Caller ¶ added in v0.7.0
type Caller struct {
// contains filtered or unexported fields
}
Caller patches through JSON-RPC requests from clients, doing pre/post-processing, account processing and validation.
func (*Caller) AccountID ¶ added in v0.7.0
AccountID is an SDK account ID for the client this caller instance is serving.
func (*Caller) Call ¶ added in v0.7.0
Call method processes a raw query received from JSON-RPC client and forwards it to SDK. It returns a response that is ready to be sent back to the JSON-RPC client as is.
func (*Caller) SetAccountID ¶ added in v0.7.0
SetAccountID sets accountID for the current instance of Caller.
func (*Caller) SetPreprocessor ¶ added in v0.8.0
func (c *Caller) SetPreprocessor(p Preprocessor)
SetPreprocessor applies provided function to query before it's sent to the SDK.
type GenericError ¶ added in v0.7.0
type GenericError struct {
// contains filtered or unexported fields
}
func NewError ¶ added in v0.7.0
func NewError(e error) GenericError
NewError is for general internal errors
func NewInternalError ¶ added in v0.7.0
func NewInternalError(e error) GenericError
NewInternalError is for SDK-related errors (connection problems etc)
func NewMethodError ¶ added in v0.7.0
func NewMethodError(e error) GenericError
NewMethodError creates a call method error
func NewParamsError ¶ added in v0.7.0
func NewParamsError(e error) GenericError
NewParamsError creates a call method error
func NewParseError ¶ added in v0.7.0
func NewParseError(e error) GenericError
NewParseError is for json parsing errors
func (GenericError) AsRPCResponse ¶ added in v0.7.0
func (e GenericError) AsRPCResponse() *jsonrpc.RPCResponse
AsRPCResponse returns error as jsonrpc.RPCResponse
func (GenericError) Code ¶ added in v0.7.0
func (e GenericError) Code() int
Code returns JSRON-RPC error code
func (GenericError) Error ¶ added in v0.7.0
func (e GenericError) Error() string
type Preprocessor ¶ added in v0.8.0
type Preprocessor func(q *Query)
type Query ¶ added in v0.7.0
type Query struct { Request *jsonrpc.RPCRequest // contains filtered or unexported fields }
Query is a wrapper around client JSON-RPC query for easier (un)marshaling and processing.
func NewQuery ¶ added in v0.7.0
NewQuery initializes Query object with JSON-RPC request supplied as bytes. The object is immediately usable and returns an error in case request parsing fails.
func (*Query) Params ¶ added in v0.7.0
func (q *Query) Params() interface{}
Params is a shortcut for query params.
func (*Query) ParamsAsMap ¶ added in v0.7.0
ParamsAsMap returns query params converted to plain map.
func (*Query) ParamsToStruct ¶ added in v0.8.0
ParamsToStruct returns query params parsed into a supplied structure.
type RequestHandler ¶ added in v0.7.0
type RequestHandler struct {
*Service
}
RequestHandler is a wrapper for passing proxy.Service instance to proxy HTTP handler.
func NewRequestHandler ¶ added in v0.8.2
func NewRequestHandler(svc *Service) *RequestHandler
func (*RequestHandler) Handle ¶ added in v0.7.0
func (rh *RequestHandler) Handle(w http.ResponseWriter, r *http.Request)
Handle forwards client JSON-RPC request to proxy.
func (*RequestHandler) HandleOptions ¶ added in v0.8.2
func (rh *RequestHandler) HandleOptions(w http.ResponseWriter, r *http.Request)
type ResponseCache ¶
type ResponseCache interface { Save(method string, params interface{}, r interface{}) Retrieve(method string, params interface{}) interface{} Count() int // contains filtered or unexported methods }
ResponseCache interface describes methods for SDK response cache saving and retrieval
type Service ¶ added in v0.7.0
type Service struct { *metrics.Collector TargetEndpoint string // contains filtered or unexported fields }
Service generates Caller objects and keeps execution time metrics for all calls proxied through those objects.
func NewService ¶ added in v0.7.0
NewService is the entry point to proxy module. Normally only one instance of Service should be created per running server.