urpc

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: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JSON_RPC_VERSION_1_0 = "1.0"
	JSON_RPC_VERSION_2_0 = "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"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(options ...ClientOption) *Client

func (*Client) Call

func (c *Client) Call(request *Request) (response *Response, err error)

func (*Client) Get

func (c *Client) Get(method string, params map[string]interface{}, response interface{}) (err error)

func (*Client) Post

func (c *Client) Post(method string, params interface{}, response interface{}) (err error)

type ClientOption

type ClientOption func(client *Client)

func WithHTTPRest

func WithHTTPRest(url string, headers map[string]string) ClientOption

WithHTTPRest sets the URL of the REST server for http network requests This is used for RESTful like API requests for TRON and similar networks

func WithHTTPRpc

func WithHTTPRpc(url string, headers map[string]string) ClientOption

WithHTTPRpc sets the URL of the RPC server for http network requests

func WithRpcIPCSocket

func WithRpcIPCSocket(socketPath string) ClientOption

WithRpcIPCSocket sets the RPC client for use unix socket interactions Please note, may not work on Windows (differences between Unix sockets and Windows named pipes)

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type Request

type Request struct {
	Id           RequestId              `json:"id"`
	JsonRpc      string                 `json:"jsonrpc"`
	Method       string                 `json:"method"`
	ParamsNamed  map[string]interface{} `json:"paramsN,omitempty"`
	ParamsArray  []interface{}          `json:"paramsA,omitempty"`
	Params       json.RawMessage        `json:"params,omitempty"`
	ParamsObject interface{}            `json:"paramsO,omitempty"`
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(method string, params ...interface{}) (req *Request)

func NewRequestWithNamedParams

func NewRequestWithNamedParams(method string, params map[string]interface{}) (req *Request)

func NewRequestWithObject

func NewRequestWithObject(method string, params interface{}) (req *Request)

func NewRequestWithRawParams

func NewRequestWithRawParams(method string, params json.RawMessage) (req *Request)

func (*Request) AddParams

func (r *Request) AddParams(values ...interface{})

func (*Request) MarshalJSON

func (r *Request) MarshalJSON() ([]byte, error)

func (*Request) SetId

func (r *Request) SetId(id RequestId)

func (*Request) SetNamedParam

func (r *Request) SetNamedParam(key string, value interface{})

func (*Request) SetParams

func (r *Request) SetParams(values ...interface{})

func (*Request) String

func (r *Request) String() string

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 Response

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

func NewResponse

func NewResponse() *Response

func (*Response) IsSuccess

func (r *Response) IsSuccess() bool

func (*Response) ParseError

func (r *Response) ParseError() error

func (*Response) ParseResult

func (r *Response) ParseResult(target interface{}) (err error)

func (*Response) String

func (r *Response) String() string

type WarpedError

type WarpedError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func (*WarpedError) Error

func (err *WarpedError) Error() string

Jump to

Keyboard shortcuts

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