From f190404ab5cbeb0518c0f2fb3933dea0fe5ed83d Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Tue, 18 Jan 2022 14:47:16 +0530 Subject: [PATCH] Add an API to change addresses being watched by geth for direct indexing --- pkg/serve/api.go | 22 +++++++++++++++++++--- pkg/serve/service.go | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pkg/serve/api.go b/pkg/serve/api.go index e00877c4..ad80bec1 100644 --- a/pkg/serve/api.go +++ b/pkg/serve/api.go @@ -18,9 +18,12 @@ package serve import ( "context" + "encoding/json" "github.com/ethereum/go-ethereum/rpc" + "github.com/ethereum/go-ethereum/statediff" "github.com/ethereum/go-ethereum/statediff/indexer/shared" + sdtypes "github.com/ethereum/go-ethereum/statediff/types" log "github.com/sirupsen/logrus" "github.com/vulcanize/ipld-eth-server/pkg/eth" @@ -34,13 +37,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, } } @@ -87,3 +92,14 @@ func (api *PublicServerAPI) Stream(ctx context.Context, params eth.SubscriptionS func (api *PublicServerAPI) Chain() shared.ChainType { return shared.Ethereum } + +// WatchAddress makes a geth WatchAddress API call with the given operation and args +func (api *PublicServerAPI) WatchAddress(operation statediff.OperationType, args []sdtypes.WatchAddressArg) error { + var data json.RawMessage + err := api.rpc.Call(&data, "statediff_watchAddress", operation, args) + if err != nil { + return err + } + + return nil +} diff --git a/pkg/serve/service.go b/pkg/serve/service.go index b1c295f2..97cf4ec4 100644 --- a/pkg/serve/service.go +++ b/pkg/serve/service.go @@ -126,7 +126,7 @@ func (sap *Service) APIs() []rpc.API { { Namespace: APIName, Version: APIVersion, - Service: NewPublicServerAPI(sap), + Service: NewPublicServerAPI(sap, sap.client), Public: true, }, {