conn

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: Apache-2.0, GPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 DefaultChannelTimeouts = ChannelTimeouts{
	ReadTimeout:  30 * time.Second,
	WriteTimeout: 30 * time.Second,
	IdleTimeout:  120 * time.Second,
}

DefaultChannelTimeouts represents the default timeout values used if further configuration is not provided.

View Source
var DefaultHTTPTimeouts = HTTPTimeouts{
	ReadTimeout:  30 * time.Second,
	WriteTimeout: 30 * time.Second,
	IdleTimeout:  120 * time.Second,
}

DefaultHTTPTimeouts represents the default timeout values used if further configuration is not provided.

Functions

This section is empty.

Types

type API

type API struct {
	Namespace string      // namespace under which the rpc methods of Service are exposed
	Version   string      // api version for DApp's
	Service   interface{} // receiver instance which holds the methods
	Public    bool        // indication if the methods must be considered safe for public use
}

API describes the set of methods offered over the RPC interface

type BatchElem

type BatchElem struct {
	Method string
	Args   []interface{}
	// The result is unmarshaled into this field. Result must be set to a
	// non-nil pointer value of the desired type, otherwise the response will be
	// discarded.
	Result interface{}
	// Error is set if the server returns an error for this request, or if
	// unmarshaling into Result fails. It is not set for I/O errors.
	Error error
}

BatchElem is an element in a batch request.

type ChannelTimeouts

type ChannelTimeouts struct {
	// ReadTimeout is the maximum duration for reading the entire
	// request, including the body.
	//
	// Because ReadTimeout does not let Handlers make per-request
	// decisions on each request body's acceptable deadline or
	// upload rate, most users will prefer to use
	// ReadHeaderTimeout. It is valid to use them both.
	ReadTimeout time.Duration

	// WriteTimeout is the maximum duration before timing out
	// writes of the response. It is reset whenever a new
	// request's header is read. Like ReadTimeout, it does not
	// let Handlers make decisions on a per-request basis.
	WriteTimeout time.Duration

	// IdleTimeout is the maximum amount of time to wait for the
	// next request when keep-alives are enabled. If IdleTimeout
	// is zero, the value of ReadTimeout is used. If both are
	// zero, ReadHeaderTimeout is used.
	IdleTimeout time.Duration
}

ChannelTimeouts represents the configuration params for the Channel RPC server.

type Conn

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

Conn is a subset of the methods of net.Conn which are sufficient for ServerCodec.

type ConnRemoteAddr

type ConnRemoteAddr interface {
	RemoteAddr() string
}

ConnRemoteAddr wraps the RemoteAddr operation, which returns a description of the peer address of a connection. If a Conn also implements ConnRemoteAddr, this description is used in log messages.

type Connection

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

Connection represents a connection to an RPC server.

func ClientFromContext

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

ClientFromContext Connection retrieves the client from the context, if any. This can be used to perform 'reverse calls' in a handler method.

func DialChannelWithClient

func DialChannelWithClient(endpoint string, config *tls.Config, groupID int) (*Connection, error)

DialChannelWithClient creates a new RPC client that connects to an RPC server over Channel using the provided Channel Client.

func DialContextChannel

func DialContextChannel(rawurl string, caRoot, certContext, keyContext []byte, groupID int) (*Connection, error)

DialContextChannel creates a new Channel client, just like Dial.

func DialContextHTTP

func DialContextHTTP(rawurl string) (*Connection, error)

DialContextHTTP creates a new RPC client, just like Dial.

The context is used to cancel or time out the initial connection establishment. It does not affect subsequent interactions with the client.

func DialHTTP

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

DialHTTP creates a new RPC client that connects to an RPC server over HTTP.

func DialHTTPWithClient

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

DialHTTPWithClient creates a new RPC client that connects to an RPC server over HTTP using the provided HTTP Client.

func (*Connection) AsyncSendTransaction added in v0.10.0

func (c *Connection) AsyncSendTransaction(ctx context.Context, handler func(*types.Receipt, error), method string, args ...interface{}) error

func (*Connection) BroadcastAMOPMsg added in v0.10.0

func (c *Connection) BroadcastAMOPMsg(topic string, data []byte) error

func (*Connection) BroadcastAMOPPrivateMsg added in v0.10.0

func (c *Connection) BroadcastAMOPPrivateMsg(topic string, data []byte) error

func (*Connection) Call

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

Call performs a JSON-RPC call with the given arguments and unmarshals into result if no error occurred.

The result must be a pointer so that package json can unmarshal into it. You can also pass nil, in which case the result is ignored.

func (*Connection) CallContext

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

CallContext performs a JSON-RPC call with the given arguments. If the context is canceled before the call has successfully returned, CallContext returns immediately.

The result must be a pointer so that package json can unmarshal into it. You can also pass nil, in which case the result is ignored.

func (*Connection) Close

func (c *Connection) Close()

Close closes the client, aborting any in-flight requests.

func (*Connection) GetBlockNumber added in v0.10.0

func (c *Connection) GetBlockNumber() int64

GetBlockNumber returns BlockLimit

func (*Connection) IsHTTP added in v0.10.0

func (c *Connection) IsHTTP() bool

IsHTTP returns whether is HTTP

func (*Connection) PublishPrivateTopic added in v0.10.0

func (c *Connection) PublishPrivateTopic(topic string, publicKey []*ecdsa.PublicKey) error

func (*Connection) ReConn added in v1.1.0

func (c *Connection) ReConn()

Close closes the client, aborting any in-flight requests.

func (*Connection) SendAMOPMsg added in v0.10.0

func (c *Connection) SendAMOPMsg(topic string, data []byte) ([]byte, error)

func (*Connection) SendAMOPPrivateMsg added in v0.10.0

func (c *Connection) SendAMOPPrivateMsg(topic string, data []byte) ([]byte, error)

func (*Connection) SubscribeBlockNumberNotify added in v0.10.0

func (c *Connection) SubscribeBlockNumberNotify(groupID uint64, handler func(int64)) error

func (*Connection) SubscribeEventLogs added in v1.0.0

func (c *Connection) SubscribeEventLogs(eventLogParams types.EventLogParams, handler func(int, []types.Log)) (string, error)

func (*Connection) SubscribePrivateTopic added in v0.10.0

func (c *Connection) SubscribePrivateTopic(topic string, privateKey *ecdsa.PrivateKey, handler func([]byte, *[]byte)) error

func (*Connection) SubscribeTopic added in v0.10.0

func (c *Connection) SubscribeTopic(topic string, handler func([]byte, *[]byte)) error

func (*Connection) UnSubscribeEventLogs added in v1.1.0

func (c *Connection) UnSubscribeEventLogs(filterID string) error

func (*Connection) UnsubscribeBlockNumberNotify added in v0.10.0

func (c *Connection) UnsubscribeBlockNumberNotify(groupID uint64) error

func (*Connection) UnsubscribePrivateTopic added in v0.10.0

func (c *Connection) UnsubscribePrivateTopic(topic string) error

func (*Connection) UnsubscribeTopic added in v0.10.0

func (c *Connection) UnsubscribeTopic(topic string) error

type Error

type Error interface {
	Error() string  // returns the message
	ErrorCode() int // returns the code
}

Error wraps RPC errors, which contain an error code in addition to the message.

type EventLog added in v1.0.0

type EventLog struct {
	LogIndex         string   `json:"logIndex"`
	TransactionIndex string   `json:"transactionIndex"`
	TransactionHash  string   `json:"transactionHash"`
	BlockHash        string   `json:"blockHash"`
	BlockNumber      string   `json:"blockNumber"`
	Address          string   `json:"address"`
	Data             string   `json:"data"`
	Topics           []string `json:"topics"`
}

type HTTPTimeouts

type HTTPTimeouts struct {
	// ReadTimeout is the maximum duration for reading the entire
	// request, including the body.
	//
	// Because ReadTimeout does not let Handlers make per-request
	// decisions on each request body's acceptable deadline or
	// upload rate, most users will prefer to use
	// ReadHeaderTimeout. It is valid to use them both.
	ReadTimeout time.Duration

	// WriteTimeout is the maximum duration before timing out
	// writes of the response. It is reset whenever a new
	// request's header is read. Like ReadTimeout, it does not
	// let Handlers make decisions on a per-request basis.
	WriteTimeout time.Duration

	// IdleTimeout is the maximum amount of time to wait for the
	// next request when keep-alives are enabled. If IdleTimeout
	// is zero, the value of ReadTimeout is used. If both are
	// zero, ReadHeaderTimeout is used.
	IdleTimeout time.Duration
}

HTTPTimeouts represents the configuration params for the HTTP RPC server.

type ServerCodec

type ServerCodec interface {
	Read() (msgs []*jsonrpcMessage, isBatch bool, err error)
	Close()
	// contains filtered or unexported methods
}

ServerCodec implements reading, parsing and writing RPC messages for the server side of a RPC session. Implementations must be go-routine safe since the codec can be called in multiple go-routines concurrently.

func NewCodec

func NewCodec(conn Conn, encode, decode func(v interface{}) error) ServerCodec

NewCodec creates a new RPC server codec with support for JSON-RPC 2.0 based on explicitly given encoding and decoding methods.

func NewJSONCodec

func NewJSONCodec(conn Conn) ServerCodec

NewJSONCodec creates a new RPC server codec with support for JSON-RPC 2.0.

Jump to

Keyboard shortcuts

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