Documentation ¶
Overview ¶
Inspired by https://github.com/vektah/dataloaden with some tweaks
Index ¶
- Constants
- type BatchLoader
- func (l *BatchLoader) Init(p *HTTPProvider)
- func (l *BatchLoader) Load(req *jsonrpc2.JSONRPCRequest) ([]byte, error)
- func (l *BatchLoader) LoadAll(reqs []*jsonrpc2.JSONRPCRequest) ([][]byte, []error)
- func (l *BatchLoader) LoadAllThunk(keys []*jsonrpc2.JSONRPCRequest) func() ([][]byte, []error)
- func (l *BatchLoader) LoadThunk(req *jsonrpc2.JSONRPCRequest) func() ([]byte, error)
- type HTTPProvider
- func (p *HTTPProvider) Call(result interface{}, method string, params ...interface{}) error
- func (p *HTTPProvider) CallRaw(method string, params ...interface{}) ([]byte, error)
- func (p *HTTPProvider) SetHTTPTimeout(httpTimeout time.Duration)
- func (p *HTTPProvider) Start() error
- func (p *HTTPProvider) Stop()
- func (p *HTTPProvider) Subscribe(receiver chan *json.RawMessage, method string, event string, ...) error
- type RPCLoader
- type SyncLoader
Constants ¶
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 ¶ added in v0.0.4
type BatchLoader struct {
// contains filtered or unexported fields
}
BatchLoader loads RPC request as batches
func NewBatchLoader ¶ added in v0.0.4
func NewBatchLoader(maxBatch int, wait time.Duration) (*BatchLoader, error)
NewBatchLoader creates a new batchLoader given a fetch, wait, and maxBatch
func (*BatchLoader) Init ¶ added in v0.0.4
func (l *BatchLoader) Init(p *HTTPProvider)
Init initializes the BatchLoader
func (*BatchLoader) Load ¶ added in v0.0.4
func (l *BatchLoader) Load(req *jsonrpc2.JSONRPCRequest) ([]byte, error)
Load a request, batching will be applied automatically
func (*BatchLoader) LoadAll ¶ added in v0.0.4
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 ¶ added in v0.0.4
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 ¶ added in v0.0.4
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 NewWithLoader ¶ added in v0.0.4
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) SetHTTPTimeout ¶ added in v0.0.4
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) 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 ¶ added in v0.0.4
type RPCLoader interface { Load(*jsonrpc2.JSONRPCRequest) ([]byte, error) Init(p *HTTPProvider) }
type SyncLoader ¶ added in v0.0.4
type SyncLoader struct {
// contains filtered or unexported fields
}
SyncLoader is a synchronous loader that makes one http request per RPC
func NewSyncLoader ¶ added in v0.0.4
func NewSyncLoader() (*SyncLoader, error)
NewSyncLoader creates a new syncLoader given a fetch, wait, and maxBatch
func (*SyncLoader) Init ¶ added in v0.0.4
func (l *SyncLoader) Init(p *HTTPProvider)
Init initializes the SyncLoader
func (*SyncLoader) Load ¶ added in v0.0.4
func (l *SyncLoader) Load(req *jsonrpc2.JSONRPCRequest) ([]byte, error)
Load turns a RPCRequest into a byte array response