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, }, {