Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeUint64(input string) (uint64, error)
- func IsTemporaryError(err error) bool
- func UnmarshalFixedText(typname string, input, out []byte) error
- func UnmarshalText(h types.Hash, input []byte) error
- type API
- type BlockNumber
- type BlockNumberOrHash
- type Client
- func ClientFromContext(ctx context.Context) (*Client, bool)
- func Dial(rawurl string) (*Client, error)
- func DialContext(ctx context.Context, rawurl string) (*Client, error)
- func DialHTTP(endpoint string) (*Client, error)
- func DialHTTPWithClient(endpoint string, client *http.Client) (*Client, error)
- func DialIPC(ctx context.Context, endpoint string) (*Client, error)
- func DialInProc(handler *Server) *Client
- func DialWebsocket(ctx context.Context, endpoint, origin string) (*Client, error)
- func DialWebsocketWithDialer(ctx context.Context, endpoint, origin string, dialer websocket.Dialer) (*Client, error)
- func (c *Client) Call(result interface{}, method string, args ...interface{}) error
- func (c *Client) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
- func (c *Client) Close()
- func (c *Client) Notify(ctx context.Context, method string, args ...interface{}) error
- func (c *Client) RegisterName(name string, receiver interface{}) error
- func (c *Client) SetHeader(key, value string)
- func (c *Client) Subscribe(ctx context.Context, namespace string, channel interface{}, ...) (*ClientSubscription, error)
- func (c *Client) SupportedModules() (map[string]string, error)
- type ClientSubscription
- type CodecOption
- type Conn
- type ConnRemoteAddr
- type DataError
- type DecimalOrHex
- type Error
- type HTTPError
- type ID
- type Notifier
- type RPCService
- type Server
- func (s *Server) RegisterName(name string, receiver interface{}) error
- func (s *Server) ServeCodec(codec ServerCodec, options CodecOption)
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) ServeListener(l net.Listener) error
- func (s *Server) Stop()
- func (s *Server) WebsocketHandler(allowedOrigins []string) http.Handler
- type ServerCodec
- type Subscription
Constants ¶
const ( SafeBlockNumber = BlockNumber(-4) FinalizedBlockNumber = BlockNumber(-3) PendingBlockNumber = BlockNumber(-2) LatestBlockNumber = BlockNumber(-1) EarliestBlockNumber = BlockNumber(0) )
const JSONRPCApi = "rpc"
Variables ¶
var ( ErrClientQuit = errors.New("client is closed") ErrNoResult = errors.New("no result in JSON-RPC response") ErrSubscriptionQueueOverflow = errors.New("subscription queue overflow") )
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") )
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 IsTemporaryError ¶
func UnmarshalFixedText ¶
Types ¶
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) 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 DialHTTPWithClient ¶
func DialInProc ¶
func DialWebsocket ¶
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) CallContext ¶
func (*Client) RegisterName ¶
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 ConnRemoteAddr ¶
type ConnRemoteAddr interface {
RemoteAddr() string
}
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 ID ¶
type ID string
ID defines a pseudo random number that is used to identify RPC subscriptions.
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 ¶
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.
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 StartIPCEndpoint ¶
func (*Server) RegisterName ¶
func (*Server) ServeCodec ¶
func (s *Server) ServeCodec(codec ServerCodec, options CodecOption)
func (*Server) WebsocketHandler ¶
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.