api

package
v0.0.0-...-0ff5682 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrMsgBadRequest               = "Bad Request"
	ErrMsgInternalError            = "Internal Server Error"
	ErrMsgBadGateway               = "Bad Gateway"
	ErrMsgUniversalMintingNotReady = "universal minting not supported yet"
)
View Source
const (
	ErrorCodeInvalidRequest = -32600 // Invalid Request
)

Define error codes related to JSON-RPC responses

Variables

This section is empty.

Functions

func CORS

func CORS(next http.Handler) http.Handler

func PostRpcRequestMiddleware

func PostRpcRequestMiddleware(h RPCHandler, stateService state.Service) http.Handler

Types

type GlobalRPCHandler

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

func NewGlobalRPCHandler

func NewGlobalRPCHandler(rpcUrl, evoRpcUrl string, opts ...HandlerOption) *GlobalRPCHandler

func (*GlobalRPCHandler) GetRPCProxyHandler

func (h *GlobalRPCHandler) GetRPCProxyHandler() ProxyHandler

func (*GlobalRPCHandler) GetUniversalMintingRPCHandler

func (h *GlobalRPCHandler) GetUniversalMintingRPCHandler() RPCUniversalHandler

func (*GlobalRPCHandler) HandleProxyRPC

func (h *GlobalRPCHandler) HandleProxyRPC(r *http.Request, req JSONRPCRequest) RPCResponse

func (*GlobalRPCHandler) HandleUniversalMinting

func (h *GlobalRPCHandler) HandleUniversalMinting(r *http.Request, req JSONRPCRequest) RPCResponse

func (*GlobalRPCHandler) PostRPCRequestHandler

func (h *GlobalRPCHandler) PostRPCRequestHandler(w http.ResponseWriter, r *http.Request)

func (*GlobalRPCHandler) SetStateService

func (h *GlobalRPCHandler) SetStateService(stateService state.Service)

type HTTPClientInterface

type HTTPClientInterface interface {
	Do(req *http.Request) (*http.Response, error)
}

Define an interface for HTTP client operations

type HTTPClientWrapper

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

Create a wrapper for the net/http client

func (*HTTPClientWrapper) Do

func (h *HTTPClientWrapper) Do(req *http.Request) (*http.Response, error)

type HandlerOption

type HandlerOption func(*GlobalRPCHandler)

func WithHttpClient

func WithHttpClient(client HTTPClientInterface) HandlerOption

func WithRPCProxyHandler

func WithRPCProxyHandler(handler ProxyHandler) HandlerOption

func WithUniversalMintingRPCHandler

func WithUniversalMintingRPCHandler(handler RPCUniversalHandler) HandlerOption

type JSONRPCRequest

type JSONRPCRequest struct {
	JSONRPC string            `json:"jsonrpc"`
	Method  string            `json:"method"`
	Params  []json.RawMessage `json:"params"`
	ID      *json.RawMessage  `json:"id,omitempty"`
}

JSONRPCRequest represents the expected structure of a JSON-RPC request.

type ProxyHandler

type ProxyHandler interface {
	HandleProxyRPC(r *http.Request, req JSONRPCRequest, stateService state.Service) RPCResponse
	GetRpcUrl() string
	GetHttpClient() HTTPClientInterface
	SetHttpClient(client HTTPClientInterface)
}

func NewProxyHandler

func NewProxyHandler(ops ...ProxyHandlerOption) ProxyHandler

type ProxyHandlerOption

type ProxyHandlerOption func(*RPCProxyHandler)

func WithHttpClientProxyHandler

func WithHttpClientProxyHandler(client HTTPClientInterface) ProxyHandlerOption

func WithProxyRPCMethodManager

func WithProxyRPCMethodManager(proxyRPCMethodManager RPCMethodManager) ProxyHandlerOption

type ProxyRPCMethodManager

type ProxyRPCMethodManager struct{}

func (*ProxyRPCMethodManager) CheckBlockNumberFromResponseFromHashCalls

func (b *ProxyRPCMethodManager) CheckBlockNumberFromResponseFromHashCalls(resp *RPCResponse, method RPCMethod, blockNumberUnode string) error

func (*ProxyRPCMethodManager) HasRPCMethodWithBlockNumber

func (b *ProxyRPCMethodManager) HasRPCMethodWithBlockNumber(methodName string) (RPCMethod, bool)

func (*ProxyRPCMethodManager) HasRPCMethodWithHash

func (b *ProxyRPCMethodManager) HasRPCMethodWithHash(methodName string) (RPCMethod, bool)

func (*ProxyRPCMethodManager) ReplaceBlockTag

func (b *ProxyRPCMethodManager) ReplaceBlockTag(req *JSONRPCRequest, method RPCMethod, blockNumberUnode string) error

type RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type RPCHandler

type RPCHandler interface {
	HandleProxyRPC(r *http.Request, req JSONRPCRequest) RPCResponse
	HandleUniversalMinting(r *http.Request, req JSONRPCRequest) RPCResponse
	PostRPCRequestHandler(w http.ResponseWriter, r *http.Request)
	SetStateService(stateService state.Service)
}

type RPCMethod

type RPCMethod int
const (
	RPCMethodEthCall RPCMethod = iota
	RPCMethodEthGetBalance
	RPCMethodEthGetBlockByNumber
	RPCMethodEthGetBlockTransactionCountByNumber
	RPCMethodEthGetCode
	RPCMethodEthGetLogs
	RPCMethodEthGetStorageAt
	RPCMethodEthGetTransactionByBlockHashAndIndex
	RPCMethodEthGetTransactionByBlockNumberAndIndex
	RPCMethodEthGetTransactionCount
	RPCMethodEthGetUncleCountByBlockNumber
	RPCMethodEthNewFilter
	RPCMethodEthGetBlockByHash
	RPCMethodEthGetTransactionReceipt
	RPCMethodEthGetTransactionByHash
	RPCMethodEthGetUncleCountByBlockHash
	RPCMethodEthGetBlockTransactionCountByHash
)

Constants for each RPC method

type RPCMethodManager

type RPCMethodManager interface {
	HasRPCMethodWithBlockNumber(methodName string) (RPCMethod, bool)
	HasRPCMethodWithHash(methodName string) (RPCMethod, bool)
	CheckBlockNumberFromResponseFromHashCalls(resp *RPCResponse, method RPCMethod, blockNumberUnode string) error
	ReplaceBlockTag(req *JSONRPCRequest, method RPCMethod, blockNumberUnode string) error
}

we don't handle these methods for now but we have to handle this in the future

var rpcMethodsWithCountByHash = map[string]RPCMethod{
	"eth_getUncleCountByBlockHash":       RPCMethodEthGetUncleCountByBlockHash,
	"eth_getBlockTransactionCountByHash": RPCMethodEthGetBlockTransactionCountByHash,
}

func NewProxyRPCMethodManager

func NewProxyRPCMethodManager() RPCMethodManager

type RPCProxyHandler

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

func (*RPCProxyHandler) GetHttpClient

func (h *RPCProxyHandler) GetHttpClient() HTTPClientInterface

func (*RPCProxyHandler) GetRpcUrl

func (h *RPCProxyHandler) GetRpcUrl() string

func (*RPCProxyHandler) HandleProxyRPC

func (h *RPCProxyHandler) HandleProxyRPC(r *http.Request, req JSONRPCRequest, stateService state.Service) RPCResponse

RPCProxyHandler

func (*RPCProxyHandler) SetHttpClient

func (h *RPCProxyHandler) SetHttpClient(client HTTPClientInterface)

type RPCResponse

type RPCResponse struct {
	Jsonrpc string           `json:"jsonrpc"`
	ID      *json.RawMessage `json:"id"`
	Result  *json.RawMessage `json:"result"`
	Error   *RPCError        `json:"error,omitempty"`
}

func (RPCResponse) MarshalJSON

func (r RPCResponse) MarshalJSON() ([]byte, error)

type RPCUniversalHandler

type RPCUniversalHandler interface {
	HandleUniversalMinting(r *http.Request, req JSONRPCRequest, stateService state.Service) RPCResponse
}

type Router

type Router interface {
	HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) *mux.Route
	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

func Routes

func Routes(h RPCHandler, r Router, stateService state.Service) Router

type UniversalMintingRPCHandler

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

func (*UniversalMintingRPCHandler) GetHttpClient

func (*UniversalMintingRPCHandler) GetRpcUrl

func (h *UniversalMintingRPCHandler) GetRpcUrl() string

func (*UniversalMintingRPCHandler) HandleUniversalMinting

func (h *UniversalMintingRPCHandler) HandleUniversalMinting(r *http.Request, jsonRPCRequest JSONRPCRequest, stateService state.Service) RPCResponse

func (*UniversalMintingRPCHandler) SetHttpClient

func (h *UniversalMintingRPCHandler) SetHttpClient(client HTTPClientInterface)

type UniversalMintingRPCHandlerOption

type UniversalMintingRPCHandlerOption func(*UniversalMintingRPCHandler)

func WithRPCMethodManager

func WithRPCMethodManager(rpcMethodManager RPCMethodManager) UniversalMintingRPCHandlerOption

Directories

Path Synopsis
Code generated by MockGen.
Code generated by MockGen.

Jump to

Keyboard shortcuts

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