From c1b2d2ce0c0e781d4ef38bd7fb026b0604517090 Mon Sep 17 00:00:00 2001 From: Edgar Aroutiounian Date: Tue, 17 Sep 2019 15:47:39 -0700 Subject: [PATCH] [RPC] Expose node metadata --- internal/hmyapi/README.md | 3 ++- internal/hmyapi/harmony.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/internal/hmyapi/README.md b/internal/hmyapi/README.md index acd84eecc..6baabdb31 100644 --- a/internal/hmyapi/README.md +++ b/internal/hmyapi/README.md @@ -10,6 +10,7 @@ * [x] hmy_protocolVersion - check protocol version * [ ] net_version - get network id * [ ] net_peerCount - peer count +* [x] hmy_getNodeMetadata - get node's version, bls key ### BlockChain info related * [ ] hmy_gasPrice - return min-gas-price @@ -87,4 +88,4 @@ The ``shh`` is for the whisper protocol to communicate p2p and broadcast * [ ] shh_newFilter * [ ] shh_uninstallFilter * [ ] shh_getFilterChanges -* [ ] shh_getMessages \ No newline at end of file +* [ ] shh_getMessages diff --git a/internal/hmyapi/harmony.go b/internal/hmyapi/harmony.go index eb9e988a5..1951a8e71 100644 --- a/internal/hmyapi/harmony.go +++ b/internal/hmyapi/harmony.go @@ -6,6 +6,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/harmony-one/harmony/api/proto" + nodeconfig "github.com/harmony-one/harmony/internal/configs/node" ) // PublicHarmonyAPI provides an API to access Harmony related information. @@ -41,3 +42,18 @@ func (s *PublicHarmonyAPI) GasPrice(ctx context.Context) (*hexutil.Big, error) { // TODO(ricl): add SuggestPrice API return (*hexutil.Big)(big.NewInt(1)), nil } + +type NodeMetadata struct { + BLSPublicKey string `json:"blskey"` + Version string `json:"version"` + NetworkType string `json:"network"` +} + +func (s *PublicHarmonyAPI) GetNodeMetadata() NodeMetadata { + cfg := nodeconfig.GetDefaultConfig() + return NodeMetadata{ + cfg.ConsensusPubKey.SerializeToHexStr(), + nodeconfig.GetVersion(), + string(cfg.GetNetworkType()), + } +}