forked from cerc-io/ipld-eth-server
subscribe method for the rpc client
This commit is contained in:
parent
bc59aa4ed6
commit
c6c070005b
@ -18,6 +18,7 @@ package core
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/eth/client"
|
"github.com/vulcanize/vulcanizedb/pkg/eth/client"
|
||||||
|
@ -24,11 +24,13 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// RPCClient is a wrapper around the geth RPC client
|
||||||
type RPCClient struct {
|
type RPCClient struct {
|
||||||
client *rpc.Client
|
client *rpc.Client
|
||||||
ipcPath string
|
ipcPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BatchElem is a struct to hold the elements of a BatchCall
|
||||||
type BatchElem struct {
|
type BatchElem struct {
|
||||||
Method string
|
Method string
|
||||||
Args []interface{}
|
Args []interface{}
|
||||||
@ -36,6 +38,7 @@ type BatchElem struct {
|
|||||||
Error error
|
Error error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewRPCClient creates a new RpcClient
|
||||||
func NewRPCClient(client *rpc.Client, ipcPath string) RPCClient {
|
func NewRPCClient(client *rpc.Client, ipcPath string) RPCClient {
|
||||||
return RPCClient{
|
return RPCClient{
|
||||||
client: client,
|
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 {
|
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
|
//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.
|
//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,
|
Args: batchElem.Args,
|
||||||
Error: batchElem.Error,
|
Error: batchElem.Error,
|
||||||
}
|
}
|
||||||
|
|
||||||
rpcBatch = append(rpcBatch, newBatchElem)
|
rpcBatch = append(rpcBatch, newBatchElem)
|
||||||
}
|
}
|
||||||
return client.client.BatchCall(rpcBatch)
|
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 nil, errors.New("channel given to Subscribe must not be nil")
|
||||||
}
|
}
|
||||||
return client.client.Subscribe(context.Background(), namespace, payloadChan, args...)
|
return client.client.Subscribe(context.Background(), namespace, payloadChan, args...)
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user