httprpc

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Inspired by https://github.com/vektah/dataloaden with some tweaks

Index

Constants

View Source
const (
	// DefaultHTTPTimeout is the default timeout interval for http requests
	DefaultHTTPTimeout = 3 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchLoader

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

BatchLoader loads RPC request as batches

func NewBatchLoader

func NewBatchLoader(maxBatch int, wait time.Duration) (*BatchLoader, error)

NewBatchLoader creates a new batchLoader given a fetch, wait, and maxBatch

func (*BatchLoader) Init

func (l *BatchLoader) Init(p *HTTPProvider)

Init initializes the BatchLoader

func (*BatchLoader) Load

func (l *BatchLoader) Load(req *jsonrpc2.JSONRPCRequest) ([]byte, error)

Load a request, batching will be applied automatically

func (*BatchLoader) LoadAll

func (l *BatchLoader) LoadAll(reqs []*jsonrpc2.JSONRPCRequest) ([][]byte, []error)

LoadAll fetches many keys at once. It will be broken into appropriate sized sub batches depending on how the loader is configured

func (*BatchLoader) LoadAllThunk

func (l *BatchLoader) LoadAllThunk(keys []*jsonrpc2.JSONRPCRequest) func() ([][]byte, []error)

LoadAllThunk returns a function that when called will block waiting for a bytes. This method should be used if you want one goroutine to make requests to many different data loaders without blocking until the thunk is called.

func (*BatchLoader) LoadThunk

func (l *BatchLoader) LoadThunk(req *jsonrpc2.JSONRPCRequest) func() ([]byte, error)

LoadThunk returns a function that when called will block waiting for a byte. This method should be used if you want one goroutine to make requests to many different data loaders without blocking until the thunk is called.

type HTTPProvider

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

HTTPProvider implements ethereum RPC calls over HTTP

func New

func New(url string) (*HTTPProvider, error)

New initializes a Client and returns it

func NewWithLoader

func NewWithLoader(url string, loader RPCLoader) (*HTTPProvider, error)

NewWithLoader initializes a Client with a specified loader and returns it

func (*HTTPProvider) Call

func (p *HTTPProvider) Call(result interface{}, method string, params ...interface{}) error

Call calls a RPC method and returns coresponding object

func (*HTTPProvider) CallRaw

func (p *HTTPProvider) CallRaw(method string, params ...interface{}) ([]byte, error)

CallRaw calls a RPC method and returns the raw result

func (*HTTPProvider) SetHTTPClient

func (p *HTTPProvider) SetHTTPClient(httpClient *http.Client)

SetHTTPClient allows setting the http client from outside

func (*HTTPProvider) SetHTTPTimeout

func (p *HTTPProvider) SetHTTPTimeout(httpTimeout time.Duration)

SetHTTPTimeout allows setting the http timeout from outside

func (*HTTPProvider) Start

func (p *HTTPProvider) Start() error

Start does nothing on the http provider

func (*HTTPProvider) Stop

func (p *HTTPProvider) Stop()

Stop does nothing on the http provider

func (*HTTPProvider) Subscribe

func (p *HTTPProvider) Subscribe(receiver chan *json.RawMessage, method string, event string, params ...interface{}) error

Subscribe creates a subscription to event using method. not available on http

type RPCLoader

type RPCLoader interface {
	Load(*jsonrpc2.JSONRPCRequest) ([]byte, error)
	Init(p *HTTPProvider)
}

type SyncLoader

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

SyncLoader is a synchronous loader that makes one http request per RPC

func NewSyncLoader

func NewSyncLoader() (*SyncLoader, error)

NewSyncLoader creates a new syncLoader given a fetch, wait, and maxBatch

func (*SyncLoader) Init

func (l *SyncLoader) Init(p *HTTPProvider)

Init initializes the SyncLoader

func (*SyncLoader) Load

func (l *SyncLoader) Load(req *jsonrpc2.JSONRPCRequest) ([]byte, error)

Load turns a RPCRequest into a byte array response

Jump to

Keyboard shortcuts

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