protocol

package
v0.0.0-...-6d1d3b9 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BaseError int = iota
	NoAvailableUpstreams
	WrongChain
	CtxErrorCode
	ClientErrorCode         = 400
	AuthErrorCode           = 403
	RequestTimeout          = 408
	InternalServerErrorCode = 500
	RateLimitExceeded       = 429
	NoSupportedMethod       = -32601
	IncorrectResponseBody   = -32001
)
View Source
const MaxChunkSize = 8192
View Source
const MethodSeparator = "#"

Variables

This section is empty.

Functions

func IsRetryable

func IsRetryable(response ResponseHolder) bool

func IsStream

func IsStream(method string) bool

func ResponseCanBeStreamed

func ResponseCanBeStreamed(reader *bufio.Reader, chunkSize int) bool

func ResultAsNumber

func ResultAsNumber(result []byte) uint64

func ResultAsString

func ResultAsString(result []byte) string

func ToHttpCode

func ToHttpCode(response ResponseHolder) int

Types

type AbstractUpstreamStateEvent

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

type ApiConnectorType

type ApiConnectorType int
const (
	JsonRpcConnector ApiConnectorType = iota
	RestConnector
	GrpcConnector
	WsConnector
)

func (ApiConnectorType) String

func (a ApiConnectorType) String() string

type AvailabilityStatus

type AvailabilityStatus int
const (
	Available AvailabilityStatus = iota
	Unavailable

	UnknownStatus = math.MaxInt
)

func (AvailabilityStatus) String

func (a AvailabilityStatus) String() string

type BanMethodUpstreamStateEvent

type BanMethodUpstreamStateEvent struct {
	Method string
}

type BaseUpstreamResponse

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

func NewHttpUpstreamResponse

func NewHttpUpstreamResponse(id string, body []byte, responseCode int, requestType RequestType) *BaseUpstreamResponse

func NewHttpUpstreamResponseStream

func NewHttpUpstreamResponseStream(id string, reader io.Reader, requestType RequestType) *BaseUpstreamResponse

func NewHttpUpstreamResponseWithError

func NewHttpUpstreamResponseWithError(error *ResponseError) *BaseUpstreamResponse

func NewSimpleHttpUpstreamResponse

func NewSimpleHttpUpstreamResponse(id string, body []byte, requestType RequestType) *BaseUpstreamResponse

func (*BaseUpstreamResponse) EncodeResponse

func (h *BaseUpstreamResponse) EncodeResponse(realId []byte) io.Reader

func (*BaseUpstreamResponse) GetError

func (h *BaseUpstreamResponse) GetError() *ResponseError

func (*BaseUpstreamResponse) HasError

func (h *BaseUpstreamResponse) HasError() bool

func (*BaseUpstreamResponse) HasStream

func (h *BaseUpstreamResponse) HasStream() bool

func (*BaseUpstreamResponse) Id

func (h *BaseUpstreamResponse) Id() string

func (*BaseUpstreamResponse) ResponseCode

func (h *BaseUpstreamResponse) ResponseCode() int

func (*BaseUpstreamResponse) ResponseResult

func (h *BaseUpstreamResponse) ResponseResult() []byte

func (*BaseUpstreamResponse) ResponseResultString

func (h *BaseUpstreamResponse) ResponseResultString() (string, error)

type Block

type Block struct {
	BlockData *BlockData
}

func NewBlock

func NewBlock(height, slot uint64, hash string) *Block

type BlockData

type BlockData struct {
	Height uint64
	Slot   uint64
	Hash   string
}

func NewBlockData

func NewBlockData(height, slot uint64, hash string) *BlockData

func NewBlockDataWithHeight

func NewBlockDataWithHeight(height uint64) *BlockData

func (*BlockData) IsEmpty

func (b *BlockData) IsEmpty() bool

type BlockInfo

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

func NewBlockInfo

func NewBlockInfo() *BlockInfo

func (*BlockInfo) AddBlock

func (b *BlockInfo) AddBlock(data *BlockData, blockType BlockType)

func (*BlockInfo) GetBlock

func (b *BlockInfo) GetBlock(blockType BlockType) *BlockData

func (*BlockInfo) GetBlocks

func (b *BlockInfo) GetBlocks() map[BlockType]*BlockData

type BlockType

type BlockType int
const (
	FinalizedBlock BlockType = iota
)

func (BlockType) String

func (b BlockType) String() string

type BlockUpstreamStateEvent

type BlockUpstreamStateEvent struct {
	BlockData *BlockData
	BlockType BlockType
}

type Cap

type Cap int
const (
	WsCap Cap = iota
)

type ClientRetryableError

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

func NewClientRetryableError

func NewClientRetryableError(err error) *ClientRetryableError

func (ClientRetryableError) Error

func (e ClientRetryableError) Error() string

type CloseReader

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

func NewCloseReader

func NewCloseReader(ctx context.Context, mainReader io.Reader, readerToClose io.ReadCloser) *CloseReader

func (*CloseReader) Read

func (c *CloseReader) Read(p []byte) (n int, err error)

type FatalErrorUpstreamStateEvent

type FatalErrorUpstreamStateEvent struct{}

type HeadUpstreamStateEvent

type HeadUpstreamStateEvent struct {
	HeadData *BlockData
}

type HttpMethod

type HttpMethod int
const (
	Get HttpMethod = iota
	Post
)

func (HttpMethod) String

func (h HttpMethod) String() string

type JsonRpcRequestBody

type JsonRpcRequestBody struct {
	Id      json.RawMessage `json:"id"`
	Jsonrpc string          `json:"jsonrpc"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params"`
}

type JsonRpcWsUpstreamResponse

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

func NewJsonRpcWsUpstreamResponse

func NewJsonRpcWsUpstreamResponse(messages chan *WsResponse) *JsonRpcWsUpstreamResponse

func (*JsonRpcWsUpstreamResponse) ResponseChan

func (j *JsonRpcWsUpstreamResponse) ResponseChan() chan *WsResponse

type RemoveUpstreamEvent

type RemoveUpstreamEvent struct{}

type ReplyError

type ReplyError struct {
	ErrorKind ResponseErrorKind
	// contains filtered or unexported fields
}

func NewPartialFailure

func NewPartialFailure(request RequestHolder, responseError *ResponseError) *ReplyError

func NewReplyError

func NewReplyError(id string, responseError *ResponseError, responseType RequestType, errorKind ResponseErrorKind) *ReplyError

func NewTotalFailure

func NewTotalFailure(request RequestHolder, responseError *ResponseError) *ReplyError

func NewTotalFailureFromErr

func NewTotalFailureFromErr(id string, err error, responseType RequestType) *ReplyError

func (*ReplyError) EncodeResponse

func (r *ReplyError) EncodeResponse(realId []byte) io.Reader

func (*ReplyError) GetError

func (r *ReplyError) GetError() *ResponseError

func (*ReplyError) HasError

func (r *ReplyError) HasError() bool

func (*ReplyError) HasStream

func (r *ReplyError) HasStream() bool

func (*ReplyError) Id

func (r *ReplyError) Id() string

func (*ReplyError) ResponseCode

func (r *ReplyError) ResponseCode() int

func (*ReplyError) ResponseResult

func (r *ReplyError) ResponseResult() []byte

func (*ReplyError) ResponseResultString

func (r *ReplyError) ResponseResultString() (string, error)

type RequestHolder

type RequestHolder interface {
	Id() string
	Method() string
	Headers() map[string]string
	Body() ([]byte, error)
	ParseParams(ctx context.Context) specs.MethodParam
	ModifyParams(ctx context.Context, newValue any)
	IsStream() bool
	IsSubscribe() bool
	RequestType() RequestType
	RequestHash() string
	SpecMethod() *specs.Method
}

type RequestType

type RequestType int
const (
	Rest RequestType = iota
	JsonRpc
	Ws
	Grpc
	Unknown
)

func (RequestType) String

func (r RequestType) String() string

type ResponseError

type ResponseError struct {
	Code    int
	Message string
	Data    interface{}
}

func AuthError

func AuthError(cause error) *ResponseError

func ClientError

func ClientError(cause error) *ResponseError

func CtxError

func CtxError(cause error) *ResponseError

func IncorrectResponseBodyError

func IncorrectResponseBodyError(cause error) *ResponseError

func NoAvailableUpstreamsError

func NoAvailableUpstreamsError() *ResponseError

func NotSupportedMethodError

func NotSupportedMethodError(method string) *ResponseError

func ParseError

func ParseError() *ResponseError

func RateLimitError

func RateLimitError() *ResponseError

func RequestTimeoutError

func RequestTimeoutError() *ResponseError

func ResponseErrorWithData

func ResponseErrorWithData(code int, message string, data interface{}) *ResponseError

func ResponseErrorWithMessage

func ResponseErrorWithMessage(message string) *ResponseError

func ServerError

func ServerError() *ResponseError

func ServerErrorWithCause

func ServerErrorWithCause(cause error) *ResponseError

func WrongChainError

func WrongChainError(chain string) *ResponseError

func (*ResponseError) Error

func (b *ResponseError) Error() string

type ResponseErrorKind

type ResponseErrorKind int
const (
	PartialFailure ResponseErrorKind = iota
	TotalFailure
)

type ResponseHolder

type ResponseHolder interface {
	ResponseResult() []byte
	ResponseResultString() (string, error)
	ResponseCode() int
	GetError() *ResponseError
	EncodeResponse(realId []byte) io.Reader
	HasError() bool
	HasStream() bool
	Id() string
}

type ResponseHolderWrapper

type ResponseHolderWrapper struct {
	UpstreamId string
	RequestId  string
	Response   ResponseHolder
}

type ResultType

type ResultType int
const (
	ResultOk ResultType = iota
	ResultOkWithError
	ResultPartialFailure
	ResultTotalFailure
	ResultStop
)

func GetResponseType

func GetResponseType(wrapper *ResponseHolderWrapper, err error) ResultType

type StateUpstreamEvent

type StateUpstreamEvent struct {
	State *UpstreamState
}

type StopRetryErr

type StopRetryErr struct {
}

func (StopRetryErr) Error

func (s StopRetryErr) Error() string

type SubscriptionEventResponse

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

func NewSubscriptionEventResponse

func NewSubscriptionEventResponse(id string, event []byte) *SubscriptionEventResponse

func NewSubscriptionMessageEventResponse

func NewSubscriptionMessageEventResponse(id string, message []byte) *SubscriptionEventResponse

func (*SubscriptionEventResponse) EncodeResponse

func (s *SubscriptionEventResponse) EncodeResponse(realId []byte) io.Reader

func (*SubscriptionEventResponse) GetError

func (*SubscriptionEventResponse) HasError

func (s *SubscriptionEventResponse) HasError() bool

func (*SubscriptionEventResponse) HasStream

func (s *SubscriptionEventResponse) HasStream() bool

func (*SubscriptionEventResponse) Id

func (*SubscriptionEventResponse) ResponseCode

func (s *SubscriptionEventResponse) ResponseCode() int

func (*SubscriptionEventResponse) ResponseResult

func (s *SubscriptionEventResponse) ResponseResult() []byte

func (*SubscriptionEventResponse) ResponseResultString

func (s *SubscriptionEventResponse) ResponseResultString() (string, error)

type UnbanMethodUpstreamStateEvent

type UnbanMethodUpstreamStateEvent struct {
	Method string
}

type UpstreamEvent

type UpstreamEvent struct {
	Id        string
	Chain     chains.Chain
	EventType UpstreamEventType
}

type UpstreamEventType

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

type UpstreamJsonRpcRequest

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

func NewInternalSubUpstreamJsonRpcRequest

func NewInternalSubUpstreamJsonRpcRequest(method string, params any) (*UpstreamJsonRpcRequest, error)

func NewInternalUpstreamJsonRpcRequest

func NewInternalUpstreamJsonRpcRequest(method string, params any) (*UpstreamJsonRpcRequest, error)

func NewStreamUpstreamJsonRpcRequest

func NewStreamUpstreamJsonRpcRequest(id string, realId json.RawMessage, method string, params json.RawMessage, specMethod *specs.Method) *UpstreamJsonRpcRequest

func NewUpstreamJsonRpcRequest

func NewUpstreamJsonRpcRequest(
	id string,
	realId json.RawMessage,
	method string,
	params json.RawMessage,
	isSub bool,
	specMethod *specs.Method,
) *UpstreamJsonRpcRequest

func NewUpstreamJsonRpcRequestWithSpecMethod

func NewUpstreamJsonRpcRequestWithSpecMethod(method string, params any, specMethod *specs.Method) (*UpstreamJsonRpcRequest, error)

func (*UpstreamJsonRpcRequest) Body

func (u *UpstreamJsonRpcRequest) Body() ([]byte, error)

func (*UpstreamJsonRpcRequest) Headers

func (u *UpstreamJsonRpcRequest) Headers() map[string]string

func (*UpstreamJsonRpcRequest) Id

func (*UpstreamJsonRpcRequest) IsStream

func (u *UpstreamJsonRpcRequest) IsStream() bool

func (*UpstreamJsonRpcRequest) IsSubscribe

func (u *UpstreamJsonRpcRequest) IsSubscribe() bool

func (*UpstreamJsonRpcRequest) Method

func (u *UpstreamJsonRpcRequest) Method() string

func (*UpstreamJsonRpcRequest) ModifyParams

func (u *UpstreamJsonRpcRequest) ModifyParams(ctx context.Context, newValue any)

func (*UpstreamJsonRpcRequest) ParseParams

func (*UpstreamJsonRpcRequest) RequestHash

func (u *UpstreamJsonRpcRequest) RequestHash() string

func (*UpstreamJsonRpcRequest) RequestType

func (u *UpstreamJsonRpcRequest) RequestType() RequestType

func (*UpstreamJsonRpcRequest) SpecMethod

func (u *UpstreamJsonRpcRequest) SpecMethod() *specs.Method

type UpstreamRestRequest

type UpstreamRestRequest struct {
}

func NewUpstreamRestRequest

func NewUpstreamRestRequest() *UpstreamRestRequest

func (*UpstreamRestRequest) Body

func (u *UpstreamRestRequest) Body() ([]byte, error)

func (*UpstreamRestRequest) Headers

func (u *UpstreamRestRequest) Headers() map[string]string

func (*UpstreamRestRequest) Id

func (u *UpstreamRestRequest) Id() string

func (*UpstreamRestRequest) IsStream

func (u *UpstreamRestRequest) IsStream() bool

func (*UpstreamRestRequest) IsSubscribe

func (u *UpstreamRestRequest) IsSubscribe() bool

func (*UpstreamRestRequest) Method

func (u *UpstreamRestRequest) Method() string

func (*UpstreamRestRequest) ModifyParams

func (u *UpstreamRestRequest) ModifyParams(ctx context.Context, newValue any)

func (*UpstreamRestRequest) ParseParams

func (u *UpstreamRestRequest) ParseParams(ctx context.Context) specs.MethodParam

func (*UpstreamRestRequest) RequestHash

func (u *UpstreamRestRequest) RequestHash() string

func (*UpstreamRestRequest) RequestType

func (u *UpstreamRestRequest) RequestType() RequestType

func (*UpstreamRestRequest) SpecMethod

func (u *UpstreamRestRequest) SpecMethod() *specs.Method

type UpstreamState

type UpstreamState struct {
	Status              AvailabilityStatus
	HeadData            *BlockData
	UpstreamMethods     methods.Methods
	BlockInfo           *BlockInfo
	Caps                mapset.Set[Cap]
	UpstreamIndex       string
	RateLimiterBudget   *ratelimiter.RateLimitBudget
	AutoTuneRateLimiter *ratelimiter.UpstreamAutoTune
}

func DefaultUpstreamState

func DefaultUpstreamState(upstreamMethods methods.Methods, caps mapset.Set[Cap], upstreamIndex string, rt *ratelimiter.RateLimitBudget, autoTuneRateLimiter *ratelimiter.UpstreamAutoTune) UpstreamState

type UpstreamSubscriptionResponse

type UpstreamSubscriptionResponse interface {
	ResponseChan() chan *WsResponse
}

type ValidUpstreamEvent

type ValidUpstreamEvent struct{}

type ValidUpstreamStateEvent

type ValidUpstreamStateEvent struct{}

type WsJsonRpcResponse

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

func NewWsJsonRpcResponse

func NewWsJsonRpcResponse(id string, result []byte, error *ResponseError) *WsJsonRpcResponse

func (*WsJsonRpcResponse) EncodeResponse

func (w *WsJsonRpcResponse) EncodeResponse(realId []byte) io.Reader

func (*WsJsonRpcResponse) GetError

func (w *WsJsonRpcResponse) GetError() *ResponseError

func (*WsJsonRpcResponse) HasError

func (w *WsJsonRpcResponse) HasError() bool

func (*WsJsonRpcResponse) HasStream

func (w *WsJsonRpcResponse) HasStream() bool

func (*WsJsonRpcResponse) Id

func (w *WsJsonRpcResponse) Id() string

func (*WsJsonRpcResponse) ResponseCode

func (w *WsJsonRpcResponse) ResponseCode() int

func (*WsJsonRpcResponse) ResponseResult

func (w *WsJsonRpcResponse) ResponseResult() []byte

func (*WsJsonRpcResponse) ResponseResultString

func (w *WsJsonRpcResponse) ResponseResultString() (string, error)

type WsResponse

type WsResponse struct {
	Id      string
	SubId   string
	Message []byte
	Type    RequestType
	Error   *ResponseError
	Event   []byte
}

func ParseJsonRpcWsMessage

func ParseJsonRpcWsMessage(body []byte) *WsResponse

Jump to

Keyboard shortcuts

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