rpcinterface

package
v0.20.6 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SlogDebug added in v0.7.0

func SlogDebug() slog.Handler

SlogDebug returns a text handler preconfigured to DEBUG log level

func SlogError added in v0.7.0

func SlogError() slog.Handler

SlogError returns a text handler preconfigured to ERROR log level

func SlogInfo added in v0.7.0

func SlogInfo() slog.Handler

SlogInfo returns a text handler preconfigured to INFO log level

func SlogWarn added in v0.7.0

func SlogWarn() slog.Handler

SlogWarn returns a text handler preconfigured to WARN log level

Types

type ChiaRPCError added in v0.20.0

type ChiaRPCError struct {
	Message string
}

ChiaRPCError is the specific error returned when the RPC request succeeds, but returns success: false and an error

func (*ChiaRPCError) Error added in v0.20.0

func (e *ChiaRPCError) Error() string

Error satisfies the error interface

type Client

type Client interface {
	NewRequest(service ServiceType, rpcEndpoint Endpoint, opt interface{}) (*Request, error)
	Do(req *Request, v IResponse) (*http.Response, error)
	Close() error
	SetBaseURL(url *url.URL) error

	// SetLogHandler sets a slog compatible log handler
	SetLogHandler(handler slog.Handler)

	// SubscribeSelf subscribes to responses to requests from this service
	SubscribeSelf() error
	// Subscribe adds a subscription to events from a particular service
	Subscribe(service string) error

	// AddHandler adds a handler function that will be called when a message is received over the websocket
	// Does not apply to HTTP client
	AddHandler(handler WebsocketResponseHandler) (uuid.UUID, error)

	// RemoveHandler removes the handler from the active websocket handlers
	RemoveHandler(handlerID uuid.UUID)

	// AddDisconnectHandler adds a function to call if the connection is disconnected
	// Applies to websocket connections
	AddDisconnectHandler(onDisconnect DisconnectHandler)

	// AddReconnectHandler adds a function to call if the connection is reconnected
	// Applies to websocket connections
	AddReconnectHandler(onReconnect ReconnectHandler)

	// SetSyncMode enforces synchronous request/response behavior
	// This is default for HTTP client, but websocket default is async, so this forces a different mode
	// Note that anything received by the websocket in sync mode that is not the current expected response
	// will be ignored
	SetSyncMode()

	// SetAsyncMode sets the client to async mode
	// This is not supported for the HTTP client, but will set the websocket client back to async mode
	// if it was set to sync mode temporarily
	SetAsyncMode()
}

Client defines the interface for a client HTTP (standard RPC) and websockets are the two supported now

type ClientOptionFunc

type ClientOptionFunc func(client Client) error

ClientOptionFunc can be used to customize a new RPC client.

type ConfigOptionFunc added in v0.2.0

type ConfigOptionFunc func() (*config.ChiaConfig, error)

ConfigOptionFunc used to specify how to load configuration for the RPC client

type DisconnectHandler

type DisconnectHandler func()

DisconnectHandler the function to call when the client is disconnected

type Endpoint

type Endpoint string

Endpoint represents and RPC Method

type IResponse added in v0.20.0

type IResponse interface {
	IsSuccessful() bool
	GetRPCError() string
}

IResponse is the interface that must be satisfied by return types so we can properly wrap RPC errors

type ReconnectHandler added in v0.0.12

type ReconnectHandler func()

ReconnectHandler the function to call when the client is reconnected

type Request

type Request struct {
	Service  ServiceType
	Endpoint Endpoint
	Data     interface{}
	Request  *http.Request
}

Request is a wrapped http.Request that indicates the service we're making the RPC call to

type Response added in v0.20.0

type Response struct {
	Success bool              `json:"success"`
	Error   mo.Option[string] `json:"error,omitempty"`
}

Response is the base response elements that may be in any response from an RPC server in Chia

func (*Response) GetRPCError added in v0.20.0

func (r *Response) GetRPCError() string

GetRPCError returns the error if present or an empty string

func (*Response) IsSuccessful added in v0.20.0

func (r *Response) IsSuccessful() bool

IsSuccessful returns whether the RPC request has success: true

type Service added in v0.20.0

type Service interface {
	NewRequest(rpcEndpoint Endpoint, opt interface{}) (*Request, error)
	GetClient() Client
}

Service defines the interface for a service

type ServiceType

type ServiceType uint8

ServiceType is a type that refers to a particular service

const (
	// ServiceDaemon the daemon
	ServiceDaemon ServiceType = iota

	// ServiceFullNode the full node service
	ServiceFullNode

	// ServiceFarmer the farmer service
	ServiceFarmer

	// ServiceHarvester the harvester service
	ServiceHarvester

	// ServiceWallet the wallet service
	ServiceWallet

	// ServiceTimelord is the timelord service
	ServiceTimelord

	// ServicePeer full node service, but for communicating with full nodes using the public protocol
	ServicePeer

	// ServiceCrawler crawler service
	ServiceCrawler

	// ServiceDataLayer datalayer service
	ServiceDataLayer
)

type WebsocketResponseHandler

type WebsocketResponseHandler func(*types.WebsocketResponse, error)

WebsocketResponseHandler is a function that is called to process a received websocket response

Jump to

Keyboard shortcuts

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