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

This commit is contained in:
Prathamesh Musale 2022-01-18 14:47:16 +05:30
parent 5d86b6e029
commit f190404ab5
2 changed files with 20 additions and 4 deletions

View File

@ -18,9 +18,12 @@ package serve
import ( import (
"context" "context"
"encoding/json"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/statediff"
"github.com/ethereum/go-ethereum/statediff/indexer/shared" "github.com/ethereum/go-ethereum/statediff/indexer/shared"
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/vulcanize/ipld-eth-server/pkg/eth" "github.com/vulcanize/ipld-eth-server/pkg/eth"
@ -35,12 +38,14 @@ const APIVersion = "0.0.1"
// PublicServerAPI is the public api for the watcher // PublicServerAPI is the public api for the watcher
type PublicServerAPI struct { type PublicServerAPI struct {
w Server w Server
rpc *rpc.Client
} }
// NewPublicServerAPI creates a new PublicServerAPI with the provided underlying Server process // 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{ 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 { func (api *PublicServerAPI) Chain() shared.ChainType {
return shared.Ethereum 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
}

View File

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