Skip to content

Commit

Permalink
feat: add query operator status rpc api for proxy (#174)
Browse files Browse the repository at this point in the history
* add status api for proxy

* add proxy api

* add params
  • Loading branch information
fyInALT authored Aug 29, 2024
1 parent e4601d0 commit c4082a8
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions generic-operator-proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
"github.com/Layr-Labs/eigensdk-go/logging"
sdktypes "github.com/Layr-Labs/eigensdk-go/types"
gethrpc "github.com/ethereum/go-ethereum/rpc"

"github.com/alt-research/avs-generic-aggregator/core/config"
"github.com/alt-research/avs-generic-aggregator/core/types"
Expand All @@ -28,6 +29,7 @@ type ProxyHashRpcServer struct {
chainIds map[string]uint32
workProofsBlockNumMod map[string]uint32
defaultAVSName string
genericOperatorAddr string
logger logging.Logger
// We use this rpc server as the handler for jsonrpc
// to make sure same as legacy operator 's api
Expand Down Expand Up @@ -79,6 +81,7 @@ func NewAlertProxyRpcServer(
avsCfgs: avsCfgsMap,
chainIds: chainIds,
workProofsBlockNumMod: workProofsBlockNumMod,
genericOperatorAddr: genericOperatorAddr,
}

// not need do this because we not need use this server impl
Expand Down Expand Up @@ -130,6 +133,31 @@ func (s *ProxyHashRpcServer) handerConfigReq(
operator.WriteJSON(s.logger, w, rpcRequest.ID, json.RawMessage(cfg))
}

func (s *ProxyHashRpcServer) handerOperatorStatusReq(
ctx context.Context,
w http.ResponseWriter,
rpcRequest jsonrpc2.Request) {

resp, err := s.OperatorStatus(ctx)

if err != nil {
operator.WriteErrorJSON(
s.logger, w, rpcRequest.ID, http.StatusBadRequest, 3,
err)
return
}

raw, err := json.Marshal(resp)
if err != nil {
operator.WriteErrorJSON(
s.logger, w, rpcRequest.ID, http.StatusBadRequest, 3,
err)
return
}

operator.WriteJSON(s.logger, w, rpcRequest.ID, json.RawMessage(raw))
}

func (s *ProxyHashRpcServer) HttpRPCHandler(w http.ResponseWriter, r *http.Request) {
rpcRequest := jsonrpc2.Request{}
err := json.NewDecoder(r.Body).Decode(&rpcRequest)
Expand All @@ -148,6 +176,8 @@ func (s *ProxyHashRpcServer) HttpRPCHandler(w http.ResponseWriter, r *http.Reque

if rpcRequest.Method == "operator_getConfig" {
s.handerConfigReq(w, rpcRequest)
} else if rpcRequest.Method == "operator_operatorStatus" {
s.handerOperatorStatusReq(r.Context(), w, rpcRequest)
} else {
s.rpcServer.HttpRPCHandlerRequest(w, rpcRequest)
}
Expand Down Expand Up @@ -344,3 +374,35 @@ func (s *ProxyHashRpcServer) commitWorkProof(ctx context.Context, avsName string

return nil
}

type OperatorStatusAVSStatus struct {
AVSName string `json:"avs_name"`
AVSContractAddress string `json:"avs_contract_address"`
OperatorId string `json:"operator_id"`
OperatorAddress string `json:"operator_address"`
}

type OperatorStatusResponse struct {
NodeName string `json:"node_name"`
Version string `json:"version"`
Avs []OperatorStatusAVSStatus `json:"avs"`
}

func (s *ProxyHashRpcServer) OperatorStatus(ctx context.Context) (OperatorStatusResponse, error) {
s.logger.Debug("OperatorStatus")

res := OperatorStatusResponse{}

client, err := gethrpc.DialContext(ctx, s.genericOperatorAddr)
if err != nil {
return res, errors.Wrapf(err, "dial OperatorStatus connection failed")
}

err = client.CallContext(
ctx, &res, "operator_operatorStatus", []interface{}{})
if err != nil {
return res, errors.Wrapf(err, "call OperatorStatus failed")
}

return res, nil
}

0 comments on commit c4082a8

Please sign in to comment.