add: batch rpc calls
This commit is contained in:
@@ -19,12 +19,24 @@ func NewRpcClient(endpoint string) RpcClient {
|
||||
func (r *RpcClient) EthRpcCall(method string) (*jsonrpc.RPCResponse, error) {
|
||||
response, err := r.ethClient.Call(method)
|
||||
if err != nil {
|
||||
return response, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if response.Error != nil {
|
||||
return response, fmt.Errorf("rpc client error: (code %d) %s", response.Error.Code, response.Error.Message)
|
||||
return nil, fmt.Errorf("rpc client error: (code %d) %s", response.Error.Code, response.Error.Message)
|
||||
}
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (r *RpcClient) EthBatchRpcCall(batchedMethods jsonrpc.RPCRequests) (map[int]*jsonrpc.RPCResponse, error) {
|
||||
response, _ := r.ethClient.CallBatch(batchedMethods)
|
||||
|
||||
if response.HasError() {
|
||||
return nil, fmt.Errorf("batch rpc request failed")
|
||||
}
|
||||
|
||||
results := response.AsMap()
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user