diff --git a/generic-operator-proxy/proxy.go b/generic-operator-proxy/proxy.go index 1d59ec9..3498292 100644 --- a/generic-operator-proxy/proxy.go +++ b/generic-operator-proxy/proxy.go @@ -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" @@ -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 @@ -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 @@ -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) @@ -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) } @@ -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 +}