Documentation
¶
Index ¶
- Variables
- func ReadAs[T any](v json.RawMessage, e error) (T, error)
- func ReadBigInt(v json.RawMessage, e error) (*big.Int, error)
- func ReadString(v json.RawMessage, e error) (string, error)
- func ReadTo(target any) func(v json.RawMessage, e error) error
- func ReadUint64(v json.RawMessage, e error) (uint64, error)
- type Api
- func (a *Api) BlockNumber(ctx context.Context) (uint64, error)
- func (a *Api) ChainId(ctx context.Context) (uint64, error)
- func (a *Api) Do(method string, args ...any) (json.RawMessage, error)
- func (a *Api) To(target any, method string, args ...any) error
- func (a *Api) ToCtx(ctx context.Context, target any, method string, args ...any) error
- type ErrorObject
- type ForwardOptions
- type Handler
- type RPC
- func (r *RPC) Do(method string, args ...any) (json.RawMessage, error)
- func (r *RPC) DoCtx(ctx context.Context, method string, args ...any) (json.RawMessage, error)
- func (r *RPC) DoNamed(method string, args map[string]any) (json.RawMessage, error)
- func (r *RPC) DoNamedCtx(ctx context.Context, method string, args map[string]any) (json.RawMessage, error)
- func (r *RPC) Forward(ctx context.Context, rw http.ResponseWriter, req *Request, ...)
- func (r *RPC) Override(method string, fnc any)
- func (r *RPC) Send(req *Request) (json.RawMessage, error)
- func (r *RPC) SendCtx(ctx context.Context, req *Request) (json.RawMessage, error)
- func (r *RPC) SetBasicAuth(username, password string)
- func (r *RPC) To(target any, method string, args ...any) error
- type RPCList
- type Request
- type Response
- type ResponseIntf
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoAvailableServer = errors.New("no available server")
)
Functions ¶
func ReadBigInt ¶ added in v0.1.1
ReadBigInt can decode a json-encoded bigint in various ways, including if it is a number literal or a string.
func ReadString ¶
func ReadString(v json.RawMessage, e error) (string, error)
ReadString decodes the return value as a string and returns it
func ReadTo ¶
func ReadTo(target any) func(v json.RawMessage, e error) error
ReadTo returns a setter function that will return an error if an error happens. This is a bit convoluted because of limitation in Go's syntax, but this could be used as:
err = ReadTo(&block)(target.Do("eth_getBlockByNumber", "0x1b4", true))
func ReadUint64 ¶
func ReadUint64(v json.RawMessage, e error) (uint64, error)
ReadUint64 decodes the return value and passes it as a uint64.
This can be used as: res, err := ReadUint64(target.Do("eth_blockNumber"))
Types ¶
type Api ¶ added in v0.1.4
type Api struct {
Handler
}
func (*Api) BlockNumber ¶ added in v0.1.4
type ErrorObject ¶ added in v0.1.6
type ErrorObject struct { Code int `json:"code"` Message string `json:"message"` Data any `json:"data,omitempty"` }
func (*ErrorObject) Error ¶ added in v0.1.6
func (e *ErrorObject) Error() string
type ForwardOptions ¶ added in v0.1.7
type Handler ¶ added in v0.1.4
type RPC ¶
TODO support ws protocol
func (*RPC) DoCtx ¶
DoCtx performs a RPC request, taking an optional context that can be cancelled to stop the request
func (*RPC) DoNamedCtx ¶ added in v0.2.6
func (r *RPC) DoNamedCtx(ctx context.Context, method string, args map[string]any) (json.RawMessage, error)
DoNamedCtx performs a RPC request using named arguments, taking an optional context that can be cancelled to stop the request
func (*RPC) Forward ¶ added in v0.1.7
func (r *RPC) Forward(ctx context.Context, rw http.ResponseWriter, req *Request, opts *ForwardOptions)
Forward will write the RPC response to the given http.ResponseWriter.
func (*RPC) Override ¶ added in v0.2.0
Override allows redirecting calls to a RPC method to a standard go function
func (*RPC) Send ¶ added in v0.1.6
func (r *RPC) Send(req *Request) (json.RawMessage, error)
Send sends a raw request for processing
func (*RPC) SetBasicAuth ¶ added in v0.1.9
SetBasicAuth sets basic auth params for all subsequent RPC requests
type Request ¶ added in v0.1.6
type Request struct { JsonRpc string `json:"jsonrpc"` // 2.0 Method string `json:"method"` Params any `json:"params"` Id any `json:"id"` }
func NewRequest ¶ added in v0.1.6
NewRequest makes a new Request fit to use with methods like Send.
func (*Request) HTTPRequest ¶ added in v0.1.6
HTTPRequest returns a http.Request for the given json-rpc request.
type Response ¶ added in v0.1.6
type Response struct { JsonRpc string `json:"jsonrpc"` // 2.0 Result json.RawMessage `json:"result"` Error *ErrorObject `json:"error,omitempty"` Id any `json:"id"` }
type ResponseIntf ¶ added in v0.1.6
type ResponseIntf struct { JsonRpc string `json:"jsonrpc"` // 2.0 Result any `json:"result"` Error *ErrorObject `json:"error,omitempty"` Id any `json:"id"` }
RPCResponseIntf is same as rpcResponse except Result is a any