Add an API to change addresses being watched by geth for direct indexing

This commit is contained in:
nabarun 2022-03-16 17:09:32 +05:30 committed by prathamesh0
parent f57b816530
commit 1a6ff273ba
2 changed files with 17 additions and 4 deletions

View File

@ -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
}

View File

@ -129,7 +129,7 @@ func (sap *Service) APIs() []rpc.API {
{
Namespace: APIName,
Version: APIVersion,
Service: NewPublicServerAPI(sap),
Service: NewPublicServerAPI(sap, sap.client),
Public: true,
},
{