From 1a6ff273baaf8324dbb20faad6bdf8dae6373a46 Mon Sep 17 00:00:00 2001 From: nabarun Date: Wed, 16 Mar 2022 17:09:32 +0530 Subject: [PATCH] Add an API to change addresses being watched by geth for direct indexing --- pkg/serve/api.go | 19 ++++++++++++++++--- pkg/serve/service.go | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pkg/serve/api.go b/pkg/serve/api.go index 8cf3d43f..8d1177bc 100644 --- a/pkg/serve/api.go +++ b/pkg/serve/api.go @@ -20,6 +20,7 @@ import ( "context" "github.com/ethereum/go-ethereum/rpc" + "github.com/ethereum/go-ethereum/statediff/types" log "github.com/sirupsen/logrus" "github.com/vulcanize/ipld-eth-server/pkg/eth" @@ -33,13 +34,15 @@ const APIVersion = "0.0.1" // PublicServerAPI is the public api for the watcher type PublicServerAPI struct { - w Server + w Server + rpc *rpc.Client } // NewPublicServerAPI creates a new PublicServerAPI with the provided underlying Server process -func NewPublicServerAPI(w Server) *PublicServerAPI { +func NewPublicServerAPI(w Server, client *rpc.Client) *PublicServerAPI { return &PublicServerAPI{ - w: w, + w: w, + rpc: client, } } @@ -81,3 +84,13 @@ func (api *PublicServerAPI) Stream(ctx context.Context, params eth.SubscriptionS return rpcSub, nil } + +// WatchAddress makes a geth WatchAddress API call with the given operation and args +func (api *PublicServerAPI) WatchAddress(operation types.OperationType, args []types.WatchAddressArg) error { + err := api.rpc.Call(nil, "statediff_watchAddress", operation, args) + if err != nil { + return err + } + + return nil +} diff --git a/pkg/serve/service.go b/pkg/serve/service.go index 1704ea64..91606073 100644 --- a/pkg/serve/service.go +++ b/pkg/serve/service.go @@ -129,7 +129,7 @@ func (sap *Service) APIs() []rpc.API { { Namespace: APIName, Version: APIVersion, - Service: NewPublicServerAPI(sap), + Service: NewPublicServerAPI(sap, sap.client), Public: true, }, {