ipld-eth-server/pkg/serve/api.go

54 lines
1.7 KiB
Go
Raw Permalink Normal View History

2019-05-17 06:27:02 +00:00
// VulcanizeDB
// Copyright © 2019 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2020-08-31 15:58:16 +00:00
package serve
2019-05-17 06:27:02 +00:00
import (
"github.com/cerc-io/plugeth-statediff/types"
2019-05-17 06:27:02 +00:00
"github.com/ethereum/go-ethereum/rpc"
)
// APIName is the namespace used for the state diffing service API
const APIName = "vdb"
2019-05-17 06:27:02 +00:00
// APIVersion is the version of the state diffing service API
const APIVersion = "0.0.1"
2020-08-31 15:58:16 +00:00
// PublicServerAPI is the public api for the watcher
type PublicServerAPI struct {
w Server
rpc *rpc.Client
2019-05-17 06:27:02 +00:00
}
2020-08-31 15:58:16 +00:00
// NewPublicServerAPI creates a new PublicServerAPI with the provided underlying Server process
func NewPublicServerAPI(w Server, client *rpc.Client) *PublicServerAPI {
2020-08-31 15:58:16 +00:00
return &PublicServerAPI{
w: w,
rpc: client,
2019-05-17 06:27:02 +00:00
}
}
// 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 the error directly to match the native Geth API
return err
}
return nil
}