From c6c070005bdb00d32a1e64365b586ccd08c5f926 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 15 Apr 2019 11:27:21 -0500 Subject: [PATCH] subscribe method for the rpc client --- pkg/core/rpc_client.go | 1 + pkg/eth/client/rpc_client.go | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/core/rpc_client.go b/pkg/core/rpc_client.go index bd627d48..5b69417f 100644 --- a/pkg/core/rpc_client.go +++ b/pkg/core/rpc_client.go @@ -18,6 +18,7 @@ package core import ( "context" + "github.com/ethereum/go-ethereum/rpc" "github.com/vulcanize/vulcanizedb/pkg/eth/client" diff --git a/pkg/eth/client/rpc_client.go b/pkg/eth/client/rpc_client.go index 3f3d7753..3c8dafa6 100644 --- a/pkg/eth/client/rpc_client.go +++ b/pkg/eth/client/rpc_client.go @@ -24,11 +24,13 @@ import ( "github.com/ethereum/go-ethereum/rpc" ) +// RPCClient is a wrapper around the geth RPC client type RPCClient struct { client *rpc.Client ipcPath string } +// BatchElem is a struct to hold the elements of a BatchCall type BatchElem struct { Method string Args []interface{} @@ -36,6 +38,7 @@ type BatchElem struct { Error error } +// NewRPCClient creates a new RpcClient func NewRPCClient(client *rpc.Client, ipcPath string) RPCClient { return RPCClient{ client: client, @@ -43,6 +46,7 @@ func NewRPCClient(client *rpc.Client, ipcPath string) RPCClient { } } +// CallContext makes an rpc method call with the provided context and arguments func (client RPCClient) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error { //If an empty interface (or other nil object) is passed to CallContext, when the JSONRPC message is created the params will //be interpreted as [null]. This seems to work fine for most of the ethereum clients (which presumably ignore a null parameter. @@ -70,7 +74,6 @@ func (client RPCClient) BatchCall(batch []BatchElem) error { Args: batchElem.Args, Error: batchElem.Error, } - rpcBatch = append(rpcBatch, newBatchElem) } return client.client.BatchCall(rpcBatch) @@ -87,4 +90,4 @@ func (client RPCClient) Subscribe(namespace string, payloadChan interface{}, arg return nil, errors.New("channel given to Subscribe must not be nil") } return client.client.Subscribe(context.Background(), namespace, payloadChan, args...) -} +} \ No newline at end of file