endpoint

package
v0.0.0-...-4fc266b Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MIME_TYPE_JSON           = "application/json"
	ERROR_METHOD_NOT_ALLOWED = `{"error": {"code": -32601, "message": "method not found"}}`
)
View Source
const (
	JSON_RPC_VERSION = "2.0"

	ERROR_CODE_PARSE_ERROR         = -32700
	ERROR_MESSAGE_PARSE_ERROR      = "Parse error"
	ERROR_CODE_INVALID_REQUEST     = -32600
	ERROR_MESSAGE_INVALID_REQUEST  = "invalid request"
	ERROR_CODE_METHOD_NOT_FOUND    = -32601
	ERROR_MESSAGE_METHOD_NOT_FOUND = "method not found"
	ERROR_CODE_SERVER_ERROR        = -32000
	ERROR_MESSAGE_SERVER_ERROR     = "server error"
	ERROR_CODE_UNAUTHORIZED        = -32001
	ERROR_MESSAGE_UNAUTHORIZED     = "unauthorized access"
)
View Source
const (
	MIME_TYPE_TEXT_HTML = "text/html"
)

Variables

View Source
var (
	ErrParamNotFound    = errors.New("param not found")
	ErrInvalidParamType = errors.New("invalid param type")

	ErrInvalidAmount = errors.New("invalid amount")
)

Functions

func NewServer

func NewServer(options ...ServerOption) (server *endpointServer, err error)

Types

type BackRpc

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

func NewBackRpc

func NewBackRpc(addressPool *address.Manager, chainClient types.ChainClient, subscriptions *subscriptions.Manager, watchdog *watchdog.Service, txCache types.TxCache, options ...BackRpcOption) *BackRpc

func (*BackRpc) AddRpcProcessor

func (r *BackRpc) AddRpcProcessor(method RpcMethod, processor RpcProcessor)

func (*BackRpc) Handle

func (r *BackRpc) Handle(ctx *fasthttp.RequestCtx)

func (*BackRpc) InitProcessors

func (r *BackRpc) InitProcessors()

func (*BackRpc) RegisterProcessor

func (r *BackRpc) RegisterProcessor(method RpcMethod, processor RpcProcessor)

func (*BackRpc) RegisterSecuredProcessor

func (r *BackRpc) RegisterSecuredProcessor(method RpcMethod, processor RpcProcessor)

func (*BackRpc) RouteRpcRequest

func (r *BackRpc) RouteRpcRequest(ctx *fasthttp.RequestCtx) (err error)

type BackRpcOption

type BackRpcOption func(r *BackRpc)

func WithDebugMode

func WithDebugMode(debugMode bool) BackRpcOption

func WithFallbackResponse

func WithFallbackResponse(response HttpResponse) BackRpcOption

func WithRpcProcessor

func WithRpcProcessor(method RpcMethod, processor RpcProcessor) BackRpcOption

func WithSecurityManager

func WithSecurityManager(securityManager *security.Manager) BackRpcOption

type DevForm

type DevForm struct {
	FormPath string
}

func (DevForm) Body

func (d DevForm) Body() string

func (DevForm) ContentType

func (d DevForm) ContentType() string

func (DevForm) StatusCode

func (d DevForm) StatusCode() int

type HttpResponse

type HttpResponse interface {
	ContentType() string
	StatusCode() int
	Body() string
}

type JsonRpcError

type JsonRpcError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    string `json:"data"`
}

type JsonRpcRequest

type JsonRpcRequest struct {
	Id      RequestId       `json:"id"`
	JsonRpc string          `json:"jsonrpc"`
	Method  RpcMethod       `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
	// contains filtered or unexported fields
}

func (*JsonRpcRequest) GetMethod

func (r *JsonRpcRequest) GetMethod() (method RpcMethod)

func (*JsonRpcRequest) GetParamBool

func (r *JsonRpcRequest) GetParamBool(key string) (value bool, err error)

func (*JsonRpcRequest) GetParamFloat64

func (r *JsonRpcRequest) GetParamFloat64(key string) (param float64, err error)

func (*JsonRpcRequest) GetParamInt

func (r *JsonRpcRequest) GetParamInt(key string) (param int64, err error)

func (*JsonRpcRequest) GetParamRaw

func (r *JsonRpcRequest) GetParamRaw(key string) (param interface{}, found bool)

func (*JsonRpcRequest) GetParamString

func (r *JsonRpcRequest) GetParamString(key string) (param string, err error)

func (*JsonRpcRequest) ParseParams

func (r *JsonRpcRequest) ParseParams(params interface{}) (err error)

type JsonRpcResponse

type JsonRpcResponse struct {
	Id      RequestId       `json:"id"`
	JsonRpc string          `json:"jsonrpc"`
	Error   *JsonRpcError   `json:"error,omitempty"`
	Result  json.RawMessage `json:"result,omitempty"`
}

func NewResponse

func NewResponse() *JsonRpcResponse

func (*JsonRpcResponse) SetError

func (r *JsonRpcResponse) SetError(code int, message string)

func (*JsonRpcResponse) SetErrorWithData

func (r *JsonRpcResponse) SetErrorWithData(code int, message, data string)

func (*JsonRpcResponse) SetResult

func (r *JsonRpcResponse) SetResult(result interface{})

func (*JsonRpcResponse) SetResultBytes

func (r *JsonRpcResponse) SetResultBytes(result []byte)

type Number

type Number string

type Processor

type Processor interface {
	Process(ctx RequestContext, request RpcRequest, result RpcResponse) (err error)
}

type RequestContext

type RequestContext interface {
	GetString(key string) (value string, err error)
	GetInt(key string) (value int64, err error)
	GetBool(key string) (value bool, err error)
	GetApiToken() (token string, err error)
	SetBool(key string, value bool)
	SetString(key string, value string)
	SetInt(key string, value int64)
	Authorized(bool)
}

type RequestId

type RequestId string

func (RequestId) MarshalJSON

func (id RequestId) MarshalJSON() ([]byte, error)

func (RequestId) String

func (id RequestId) String() string

func (*RequestId) UnmarshalJSON

func (id *RequestId) UnmarshalJSON(data []byte) error

type Router

type Router interface {
	Handle(method string, processor Processor)
}

type RpcMethod

type RpcMethod string

type RpcProcessor

type RpcProcessor func(ctx RequestContext, request RpcRequest, response RpcResponse)

type RpcRequest

type RpcRequest interface {
	GetMethod() (method RpcMethod)
	ParseParams(params interface{}) (err error)
	GetParamString(key string) (value string, err error)
	GetParamInt(key string) (value int64, err error)
	GetParamBool(key string) (value bool, err error)
}

type RpcRequestContext

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

func NewRpcRequestContext

func NewRpcRequestContext() *RpcRequestContext

func (*RpcRequestContext) Authorized

func (r *RpcRequestContext) Authorized(v bool)

func (*RpcRequestContext) GetApiToken

func (r *RpcRequestContext) GetApiToken() (token string, err error)

func (*RpcRequestContext) GetBool

func (r *RpcRequestContext) GetBool(key string) (value bool, err error)

func (*RpcRequestContext) GetInt

func (r *RpcRequestContext) GetInt(key string) (value int64, err error)

func (*RpcRequestContext) GetString

func (r *RpcRequestContext) GetString(key string) (value string, err error)

func (*RpcRequestContext) SetBool

func (r *RpcRequestContext) SetBool(key string, value bool)

func (*RpcRequestContext) SetInt

func (r *RpcRequestContext) SetInt(key string, value int64)

func (*RpcRequestContext) SetString

func (r *RpcRequestContext) SetString(key, value string)

type RpcResponse

type RpcResponse interface {
	SetResult(result interface{})
	SetError(code int, message string)
	SetErrorWithData(code int, message, data string)
}

type ServerOption

type ServerOption func(s *endpointServer) error

func WithHandler

func WithHandler(handler fasthttp.RequestHandler) ServerOption

func WithHttpListener

func WithHttpListener(listenAddress string) ServerOption

func WithSocketListener

func WithSocketListener(socketFile string) ServerOption

func WithSshListener

func WithSshListener(listenPort int, knownKeys []string) ServerOption

type TransferInfoResponse

type TransferInfoResponse struct {
	TxID              string `json:"tx_id"`
	Timestamp         int64  `json:"timestamp"`
	BlockNum          int    `json:"blockNum"`
	Success           bool   `json:"success"`
	Transfer          bool   `json:"transfer"`
	NativeCoin        bool   `json:"nativeCoin,omitempty"`
	Symbol            string `json:"symbol,omitempty"`
	Decimals          int    `json:"decimals"`
	SmartContract     bool   `json:"smartContract,omitempty"`
	From              string `json:"from"`
	To                string `json:"to"`
	Amount            amount `json:"amount"`
	Token             string `json:"token,omitempty"`
	TokenSymbol       string `json:"tokenSymbol,omitempty"`
	Fee               amount `json:"fee"`
	InPool            bool   `json:"inPool"`
	Confirmed         bool   `json:"confirmed"`
	Confirmations     int    `json:"confirmations,omitempty"`
	ChainSpecificData []byte `json:"chainSpecificData,omitempty"`
}

Jump to

Keyboard shortcuts

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