jsonrpc

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: GPL-3.0 Imports: 34 Imported by: 1

Documentation

Index

Constants

View Source
const (
	SafeBlockNumber      = BlockNumber(-4)
	FinalizedBlockNumber = BlockNumber(-3)
	PendingBlockNumber   = BlockNumber(-2)
	LatestBlockNumber    = BlockNumber(-1)
	EarliestBlockNumber  = BlockNumber(0)
)
View Source
const JSONRPCApi = "rpc"

Variables

View Source
var (
	ErrClientQuit                = errors.New("client is closed")
	ErrNoResult                  = errors.New("no result in JSON-RPC response")
	ErrSubscriptionQueueOverflow = errors.New("subscription queue overflow")
)
View Source
var (
	// ErrNotificationsUnsupported is returned when the connection doesn't support notifications
	ErrNotificationsUnsupported = errors.New("notifications not supported")
	// ErrSubscriptionNotFound is returned when the notification for the given id is not found
	ErrSubscriptionNotFound = errors.New("subscription not found")
)
View Source
var (
	ErrEmptyString   = &decError{"empty hex string"}
	ErrSyntax        = &decError{"invalid hex string"}
	ErrMissingPrefix = &decError{"hex string without 0x prefix"}
	ErrOddLength     = &decError{"hex string of odd length"}
	ErrEmptyNumber   = &decError{"hex string \"0x\""}
	ErrLeadingZero   = &decError{"hex number with leading zero digits"}
	ErrUint64Range   = &decError{"hex number > 64 bits"}
	ErrUintRange     = &decError{fmt.Sprintf("hex number > %d bits", uintBits)}
	ErrBig256Range   = &decError{"hex number > 256 bits"}
)

Functions

func DecodeUint64

func DecodeUint64(input string) (uint64, error)

func IsTemporaryError

func IsTemporaryError(err error) bool

func UnmarshalFixedText

func UnmarshalFixedText(typname string, input, out []byte) error

func UnmarshalText

func UnmarshalText(h types.Hash, input []byte) error

Types

type API

type API struct {
	Namespace     string
	Service       interface{}
	Authenticated bool // whether the api should only be available behind authentication.
}

type BlockNumber

type BlockNumber int64

func (BlockNumber) Int64

func (bn BlockNumber) Int64() int64

func (*BlockNumber) UnmarshalJSON

func (bn *BlockNumber) UnmarshalJSON(data []byte) error

type BlockNumberOrHash

type BlockNumberOrHash struct {
	BlockNumber      *BlockNumber `json:"blockNumber,omitempty"`
	BlockHash        *types.Hash  `json:"blockHash,omitempty"`
	RequireCanonical bool         `json:"requireCanonical,omitempty"`
}

func BlockNumberOrHashWithHash

func BlockNumberOrHashWithHash(hash types.Hash, canonical bool) BlockNumberOrHash

func BlockNumberOrHashWithNumber

func BlockNumberOrHashWithNumber(blockNr BlockNumber) BlockNumberOrHash

func (*BlockNumberOrHash) Hash

func (bnh *BlockNumberOrHash) Hash() (types.Hash, bool)

func (*BlockNumberOrHash) Number

func (bnh *BlockNumberOrHash) Number() (BlockNumber, bool)

func (*BlockNumberOrHash) String

func (bnh *BlockNumberOrHash) String() string

func (*BlockNumberOrHash) UnmarshalJSON

func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error

type Client

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

func ClientFromContext

func ClientFromContext(ctx context.Context) (*Client, bool)

func Dial

func Dial(rawurl string) (*Client, error)

func DialContext

func DialContext(ctx context.Context, rawurl string) (*Client, error)

func DialHTTP

func DialHTTP(endpoint string) (*Client, error)

func DialHTTPWithClient

func DialHTTPWithClient(endpoint string, client *http.Client) (*Client, error)

func DialIPC

func DialIPC(ctx context.Context, endpoint string) (*Client, error)

func DialInProc

func DialInProc(handler *Server) *Client

func DialWebsocket

func DialWebsocket(ctx context.Context, endpoint, origin string) (*Client, error)

DialWebsocket creates a new RPC client that communicates with a JSON-RPC server that is listening on the given endpoint.

The context is used for the initial connection establishment. It does not affect subsequent interactions with the client.

func DialWebsocketWithDialer

func DialWebsocketWithDialer(ctx context.Context, endpoint, origin string, dialer websocket.Dialer) (*Client, error)

DialWebsocketWithDialer creates a new RPC client that communicates with a JSON-RPC server that is listening on the given endpoint using the provided dialer.

func (*Client) Call

func (c *Client) Call(result interface{}, method string, args ...interface{}) error

func (*Client) CallContext

func (c *Client) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error

func (*Client) Close

func (c *Client) Close()

func (*Client) Notify

func (c *Client) Notify(ctx context.Context, method string, args ...interface{}) error

func (*Client) RegisterName

func (c *Client) RegisterName(name string, receiver interface{}) error

func (*Client) SetHeader

func (c *Client) SetHeader(key, value string)

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context, namespace string, channel interface{}, args ...interface{}) (*ClientSubscription, error)

func (*Client) SupportedModules

func (c *Client) SupportedModules() (map[string]string, error)

type ClientSubscription

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

ClientSubscription is a subscription established through the Client's Subscribe or EthSubscribe methods.

func (*ClientSubscription) Err

func (sub *ClientSubscription) Err() <-chan error

Err returns the subscription error channel. The intended use of Err is to schedule resubscription when the client connection is closed unexpectedly.

The error channel receives a value when the subscription has ended due to an error. The received error is nil if Close has been called on the underlying client and no other error has occurred.

The error channel is closed when Unsubscribe is called on the subscription.

func (*ClientSubscription) Unsubscribe

func (sub *ClientSubscription) Unsubscribe()

Unsubscribe unsubscribes the notification and closes the error channel. It can safely be called more than once.

type CodecOption

type CodecOption int

type Conn

type Conn interface {
	io.ReadWriteCloser
	SetWriteDeadline(time.Time) error
}

type ConnRemoteAddr

type ConnRemoteAddr interface {
	RemoteAddr() string
}

type DataError

type DataError interface {
	Error() string
	ErrorData() interface{}
}

type DecimalOrHex

type DecimalOrHex uint64

DecimalOrHex unmarshals a non-negative decimal or hex parameter into a uint64.

func (*DecimalOrHex) UnmarshalJSON

func (dh *DecimalOrHex) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Error

type Error interface {
	Error() string
	ErrorCode() int
}

type HTTPError

type HTTPError struct {
	StatusCode int
	Status     string
	Body       []byte
}

func (HTTPError) Error

func (err HTTPError) Error() string

type ID

type ID string

ID defines a pseudo random number that is used to identify RPC subscriptions.

func NewID

func NewID() ID

NewID returns a new, random ID.

type Notifier

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

Notifier is tied to a RPC connection that supports subscriptions. Server callbacks use the notifier to send notifications.

func NotifierFromContext

func NotifierFromContext(ctx context.Context) (*Notifier, bool)

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. Deprecated: use subscription error channel

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.

func (*Notifier) Notify

func (n *Notifier) Notify(id ID, data interface{}) error

Notify sends a notification to the client with the given data as payload. If an error occurs the RPC connection is closed and the error is returned.

type RPCService

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

func (*RPCService) Modules

func (s *RPCService) Modules() map[string]string

type Server

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

func NewServer

func NewServer() *Server

func StartIPCEndpoint

func StartIPCEndpoint(ipcEndpoint string, apis []API) (net.Listener, *Server, error)

func (*Server) RegisterName

func (s *Server) RegisterName(name string, receiver interface{}) error

func (*Server) ServeCodec

func (s *Server) ServeCodec(codec ServerCodec, options CodecOption)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) ServeListener

func (s *Server) ServeListener(l net.Listener) error

func (*Server) Stop

func (s *Server) Stop()

func (*Server) WebsocketHandler

func (s *Server) WebsocketHandler(allowedOrigins []string) http.Handler

WebsocketHandler returns a handler that serves JSON-RPC to WebSocket connections.

allowedOrigins should be a comma-separated list of allowed origin URLs. To allow connections with any origin, pass "*".

type ServerCodec

type ServerCodec interface {
	// contains filtered or unexported methods
}

func NewCodec

func NewCodec(conn Conn) ServerCodec

func NewFuncCodec

func NewFuncCodec(conn deadlineCloser, encode, decode func(v interface{}) error) ServerCodec

type Subscription

type Subscription struct {
	ID ID
	// contains filtered or unexported fields
}

A Subscription is created by a notifier and tied 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.

func (*Subscription) MarshalJSON

func (s *Subscription) MarshalJSON() ([]byte, error)

MarshalJSON marshals a subscription as its ID.

Jump to

Keyboard shortcuts

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