rpc

package
v1.7.1-testnet-hotfix-3 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolHttp = "HTTP"
	ProtocolWS   = "WS"
)

Variables

View Source
var (
	// DefaultShutdownTimeout is default timeout to shutdown RPC server.
	DefaultShutdownTimeout = 3 * time.Second
)

Functions

func ContextWithPubSubSession

func ContextWithPubSubSession(ctx context.Context, session *PubSubSession) context.Context

ContextWithPubSubSession stores the current PubSub session in a request context.

func DefaultCfxClientConfig

func DefaultCfxClientConfig() clientConfig

func HookMiddlewares

func HookMiddlewares(provider *providers.MiddlewarableProvider, url, space string, flags ...MiddlewareHookFlag)

func HookRedirectHttpHeader

func HookRedirectHttpHeader()

HookRedirectHttpHeader registers an event handler before sending client HTTP request, which will forward HTTP headers to the requested RPC service.

func MustInit

func MustInit()

func MustNewCfxClient

func MustNewCfxClient(url string, options ...ClientOption) *sdk.Client

func MustNewCfxClientsFromViper

func MustNewCfxClientsFromViper(options ...ClientOption) (clients []*sdk.Client)

func MustNewEthClient

func MustNewEthClient(url string, options ...ClientOption) *web3go.Client

func MustNewEthClientsFromViper

func MustNewEthClientsFromViper(options ...ClientOption) (clients []*web3go.Client)

func MustNewEthDataCacheClientFromViper

func MustNewEthDataCacheClientFromViper() cacheRpc.Interface

func NewCfxClient

func NewCfxClient(url string, options ...ClientOption) (*sdk.Client, error)

func NewEthClient

func NewEthClient(url string, options ...ClientOption) (*web3go.Client, error)

func Url2NodeName

func Url2NodeName(url string) string

Types

type CfxCoreClient

type CfxCoreClient struct {
	sdk.ClientOperator
	// contains filtered or unexported fields
}

func NewCfxCoreClient

func NewCfxCoreClient(client sdk.ClientOperator) *CfxCoreClient

func (CfxCoreClient) GetBestBlockHash

func (c CfxCoreClient) GetBestBlockHash() (types.Hash, error)

func (CfxCoreClient) GetClientVersion

func (c CfxCoreClient) GetClientVersion() (string, error)

func (CfxCoreClient) GetEpochNumber

func (c CfxCoreClient) GetEpochNumber(epochs ...*types.Epoch) (*hexutil.Big, error)

func (CfxCoreClient) GetGasPrice

func (c CfxCoreClient) GetGasPrice() (*hexutil.Big, error)

func (CfxCoreClient) GetStatus

func (c CfxCoreClient) GetStatus() (types.Status, error)

type ClientOption

type ClientOption func(opt ClientOptioner)

func WithCircuitBreaker

func WithCircuitBreaker(maxFail int, failTimeWindow, openColdTime time.Duration) ClientOption

func WithClientHookMetrics

func WithClientHookMetrics(hook bool) ClientOption

func WithClientMaxConnsPerHost

func WithClientMaxConnsPerHost(maxConns int) ClientOption

func WithClientRequestTimeout

func WithClientRequestTimeout(reqTimeout time.Duration) ClientOption

func WithClientRetryCount

func WithClientRetryCount(retry int) ClientOption

func WithClientRetryInterval

func WithClientRetryInterval(retryInterval time.Duration) ClientOption

type ClientOptioner

type ClientOptioner interface {
	SetRetryCount(retry int)
	SetRetryInterval(retryInterval time.Duration)
	SetRequestTimeout(reqTimeout time.Duration)
	SetMaxConnsPerHost(maxConns int)
	SetHookMetrics(hook bool)
	SetCircuitBreaker(maxFail int, failTimeWindow, openColdTime time.Duration)
}

type EthNearHeadCache

type EthNearHeadCache struct {
	*nearhead.EthCache
	// contains filtered or unexported fields
}

func NewEthNearHeadCacheFromViper

func NewEthNearHeadCacheFromViper(url string) (*EthNearHeadCache, error)

func (*EthNearHeadCache) Close

func (c *EthNearHeadCache) Close()

type MiddlewareHookFlag

type MiddlewareHookFlag int

MiddlewareHookFlag represents the type for middleware hook flags.

const (
	// MiddlewareHookNone represents no middleware hooks enabled.
	MiddlewareHookNone MiddlewareHookFlag = 0

	// MiddlewareHookAll enables all middleware hooks.
	MiddlewareHookAll MiddlewareHookFlag = ^MiddlewareHookFlag(0)

	// MiddlewareHookLog enables logging middleware hook.
	MiddlewareHookLog MiddlewareHookFlag = 1 << iota

	// MiddlewareHookLogMetrics enables metrics logging middleware hook.
	MiddlewareHookLogMetrics
)

type Protocol

type Protocol string

type PubSubLimitConfig

type PubSubLimitConfig struct {
	MaxConnections                int `default:"10000"`
	MaxConnectionsPerIP           int `default:"20"`
	MaxSubscriptions              int `default:"50000"`
	MaxSubscriptionsPerIP         int `default:"100"`
	MaxSubscriptionsPerConnection int `default:"20"`
}

PubSubLimitConfig controls resource bounds for WebSocket PubSub traffic. A zero value for any field disables that specific bound.

type PubSubLimitError

type PubSubLimitError struct {
	Resource string
	Scope    string
	Limit    int
}

PubSubLimitError describes which PubSub resource bound was exceeded.

func (*PubSubLimitError) Error

func (e *PubSubLimitError) Error() string

type PubSubLimiter

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

PubSubLimiter tracks WebSocket PubSub connection and subscription quotas.

func NewPubSubLimiter

func NewPubSubLimiter(config PubSubLimitConfig) *PubSubLimiter

NewPubSubLimiter builds a PubSubLimiter with the supplied bounds.

func NewPubSubLimiterFromViper

func NewPubSubLimiterFromViper() *PubSubLimiter

NewPubSubLimiterFromViper builds a PubSubLimiter from requestControl.pubsub.

func (*PubSubLimiter) AcquireConnection

func (l *PubSubLimiter) AcquireConnection(ip string) (*PubSubSession, error)

AcquireConnection reserves quota for one WebSocket connection.

func (*PubSubLimiter) Stats

func (l *PubSubLimiter) Stats() PubSubLimiterStats

Stats returns a consistent copy of current PubSub resource counters.

type PubSubLimiterStats

type PubSubLimiterStats struct {
	Connections       int
	ConnectionsByIP   map[string]int
	Subscriptions     int
	SubscriptionsByIP map[string]int
}

PubSubLimiterStats is a snapshot of active PubSub resource usage.

type PubSubSession

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

PubSubSession represents one accepted WebSocket connection.

func PubSubSessionFromContext

func PubSubSessionFromContext(ctx context.Context) (*PubSubSession, bool)

PubSubSessionFromContext returns the current PubSub session from a request context.

func (*PubSubSession) AcquireSubscription

func (s *PubSubSession) AcquireSubscription() (*PubSubSubscriptionPermit, error)

AcquireSubscription reserves quota for one subscription on this WebSocket connection.

func (*PubSubSession) Close

func (s *PubSubSession) Close()

Close releases this WebSocket connection and any remaining subscription quota.

type PubSubSubscriptionPermit

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

PubSubSubscriptionPermit is the quota permit for one active PubSub subscription.

func (*PubSubSubscriptionPermit) Release

func (permit *PubSubSubscriptionPermit) Release()

Release releases this subscription quota once.

type Server

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

Server serves JSON RPC services.

func MustNewServer

func MustNewServer(
	name string,
	rpcs map[string]interface{},
	pubSubLimiter *PubSubLimiter,
	middlewares ...handlers.Middleware,
) *Server

MustNewServer creates an instance of Server with specified RPC services.

func (*Server) MustServe

func (s *Server) MustServe(endpoint string, protocol Protocol)

MustServe serves RPC server in blocking way or panics if failed.

func (*Server) MustServeGraceful

func (s *Server) MustServeGraceful(
	ctx context.Context, wg *sync.WaitGroup, endpoint string, protocol Protocol,
)

MustServeGraceful serves RPC server in a goroutine until graceful shutdown.

func (*Server) String

func (s *Server) String() string

type Web3goClient

type Web3goClient struct {
	*web3go.Client
	util.EthBlockNumberResolver

	URL   string
	Eth   ethCacheClient
	Trace traceCacheClient
	// contains filtered or unexported fields
}

Web3goClient wraps web3go.Client with additional caching and resolution capabilities.

func NewWeb3goClient

func NewWeb3goClient(
	url string,
	client *web3go.Client,
	dataCache cacheRpc.Interface,
	nearHeadCache *EthNearHeadCache,
) (*Web3goClient, error)

func (Web3goClient) Close

func (w3c Web3goClient) Close()

func (Web3goClient) NodeName

func (w3c Web3goClient) NodeName() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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