jsonrpc

package
v0.0.0-...-98adc55 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxRetries               = 10
	DefaultRequestTimeout    = 30 * time.Second
	DefaultMaxRPCConcurrency = 50 // safe default
)

Variables

This section is empty.

Functions

func NewHTTPClient

func NewHTTPClient(log *slog.Logger) *retryablehttp.Client

Types

type ArbitrumNitroClient

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

func (*ArbitrumNitroClient) BlockByNumber

func (c *ArbitrumNitroClient) BlockByNumber(ctx context.Context, blockNumber int64) (models.RPCBlock, error)

BlockByNumber returns the block with the given blockNumber. it uses 3 different methods to get the block:

  1. eth_getBlockByNumber
  2. debug_traceBlockByNumber with tracer "callTracer" TODO: this method should be optional
  3. call to eth_getTransactionReceipt for each Tx present in the Block

We encode the payload in NDJSON

func (*ArbitrumNitroClient) Close

func (c *ArbitrumNitroClient) Close() error

func (*ArbitrumNitroClient) GroupedJSONrpc

func (c *ArbitrumNitroClient) GroupedJSONrpc(
	ctx context.Context,
	group *errgroup.Group,
	method string,
	args []any,
	output *bytes.Buffer,
	debugBlockNumber int64,
)

GroupedJSONrpc is a helper function to spawn multiple calls belonging to the same group. errors are propagated to the errgroup. concurrency is managed by the worker pool.

func (*ArbitrumNitroClient) LatestBlockNumber

func (c *ArbitrumNitroClient) LatestBlockNumber() (int64, error)

type BlockchainClient

type BlockchainClient interface {
	LatestBlockNumber() (int64, error)
	BlockByNumber(ctx context.Context, blockNumber int64) (models.RPCBlock, error)
	Close() error
}

func NewClient

func NewClient(log *slog.Logger, cfg Config) (BlockchainClient, error)

func NewRPCClient

func NewRPCClient(log *slog.Logger, client HTTPClient, cfg Config) (BlockchainClient, error)

type Config

type Config struct {
	URL          string
	PollInterval time.Duration
	HTTPHeaders  map[string]string
	EVMStack     models.EVMStack
	// rpcClient is used in parallel by the ingester to fetch blocks
	// but it also has internal request concurrency on handling each block
	// to avoid spawning too many http requests to the RPC node we set here an upper limit
	TotalRPCConcurrency int
}

type HTTPClient

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

type OpStackClient

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

func (*OpStackClient) BlockByNumber

func (c *OpStackClient) BlockByNumber(ctx context.Context, blockNumber int64) (models.RPCBlock, error)

BlockByNumber returns the block with the given blockNumber. it uses 3 different methods to get the block: 1. eth_getBlockByNumber 2. eth_getBlockReceipts 3. debug_traceBlockByNumber with tracer "callTracer" We encode the payload in NDJSON, in this order. TODO: debug_traceBlockByNumber should be optional

we should handle the case where it is not available

func (*OpStackClient) Close

func (c *OpStackClient) Close() error

func (*OpStackClient) GroupedJSONrpc

func (c *OpStackClient) GroupedJSONrpc(
	ctx context.Context,
	group *errgroup.Group,
	method string,
	args []any,
	output *bytes.Buffer,
	debugBlockNumber int64,
)

GroupedJSONrpc is a helper function to spawn multiple calls belonging to the same group. errors are propagated to the errgroup. concurrency is managed by the worker pool.

func (*OpStackClient) LatestBlockNumber

func (c *OpStackClient) LatestBlockNumber() (int64, error)

Jump to

Keyboard shortcuts

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