From bbb3ef9886e33aeef7281178c87eda0c6a494a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sza=C5=82owski?= Date: Wed, 31 Jul 2024 14:24:30 +0200 Subject: [PATCH] feat(#1644): provide network name to network metrics endpoint --- CHANGELOG.md | 2 +- govtool/backend/sql/get-network-metrics.sql | 4 +++- govtool/backend/src/VVA/API.hs | 1 + govtool/backend/src/VVA/API/Types.hs | 4 +++- govtool/backend/src/VVA/Network.hs | 2 ++ govtool/backend/src/VVA/Types.hs | 1 + 6 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9d260906..986e19412 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ changes. ### Added -- +- Add network name to GET /network/metrics [Issue 1644](https://github.com/IntersectMBO/govtool/issues/1644) ### Fixed diff --git a/govtool/backend/sql/get-network-metrics.sql b/govtool/backend/sql/get-network-metrics.sql index 0ab89a170..3c5c5a37b 100644 --- a/govtool/backend/sql/get-network-metrics.sql +++ b/govtool/backend/sql/get-network-metrics.sql @@ -71,7 +71,8 @@ SELECT total_drep_votes.count, total_registered_dreps.count, always_abstain_voting_power.amount, - always_no_confidence_voting_power.amount + always_no_confidence_voting_power.amount, + network_name FROM current_epoch CROSS JOIN current_block @@ -82,3 +83,4 @@ FROM CROSS JOIN total_registered_dreps CROSS JOIN always_abstain_voting_power CROSS JOIN always_no_confidence_voting_power + CROSS JOIN meta; diff --git a/govtool/backend/src/VVA/API.hs b/govtool/backend/src/VVA/API.hs index f87c562db..da67e38bf 100644 --- a/govtool/backend/src/VVA/API.hs +++ b/govtool/backend/src/VVA/API.hs @@ -445,6 +445,7 @@ getNetworkMetrics = do , getNetworkMetricsResponseTotalRegisteredDReps = networkMetricsTotalRegisteredDReps , getNetworkMetricsResponseAlwaysAbstainVotingPower = networkMetricsAlwaysAbstainVotingPower , getNetworkMetricsResponseAlwaysNoConfidenceVotingPower = networkMetricsAlwaysNoConfidenceVotingPower + , getNetworkMetricsResponseNetworkName = networkMetricsNetworkName } validateProposalMetadata :: App m => MetadataValidationParams -> m (Types.MetadataValidationResult Types.ProposalMetadata) diff --git a/govtool/backend/src/VVA/API/Types.hs b/govtool/backend/src/VVA/API/Types.hs index a8961556e..79f91fb3f 100644 --- a/govtool/backend/src/VVA/API/Types.hs +++ b/govtool/backend/src/VVA/API/Types.hs @@ -944,6 +944,7 @@ data GetNetworkMetricsResponse , getNetworkMetricsResponseTotalRegisteredDReps :: Integer , getNetworkMetricsResponseAlwaysAbstainVotingPower :: Integer , getNetworkMetricsResponseAlwaysNoConfidenceVotingPower :: Integer + , getNetworkMetricsResponseNetworkName :: Text } deriveJSON (jsonOptions "getNetworkMetricsResponse") ''GetNetworkMetricsResponse @@ -959,7 +960,8 @@ exampleGetNetworkMetricsResponse = <> "\"totalDRepVotes\": 0," <> "\"totalRegisteredDReps\": 0," <> "\"alwaysAbstainVotingPower\": 0," - <> "\"alwaysNoConfidenceVotingPower\": 0}" + <> "\"alwaysNoConfidenceVotingPower\": 0," + <> "\"networkName\": \"Mainnet\"}" instance ToSchema GetNetworkMetricsResponse where declareNamedSchema _ = pure $ NamedSchema (Just "GetNetworkMetricsResponse") $ mempty diff --git a/govtool/backend/src/VVA/Network.hs b/govtool/backend/src/VVA/Network.hs index 2329c689e..692d6359d 100644 --- a/govtool/backend/src/VVA/Network.hs +++ b/govtool/backend/src/VVA/Network.hs @@ -44,6 +44,7 @@ networkMetrics = withPool $ \conn -> do , total_registered_dreps , always_abstain_voting_power , always_no_confidence_voting_power + , network_name )] -> return $ NetworkMetrics current_time epoch_no @@ -55,4 +56,5 @@ networkMetrics = withPool $ \conn -> do total_registered_dreps always_abstain_voting_power always_no_confidence_voting_power + network_name _ -> throwError $ CriticalError "Could not query the network metrics. This should never happen." diff --git a/govtool/backend/src/VVA/Types.hs b/govtool/backend/src/VVA/Types.hs index 85b52d976..c15bbb8c4 100644 --- a/govtool/backend/src/VVA/Types.hs +++ b/govtool/backend/src/VVA/Types.hs @@ -198,6 +198,7 @@ data NetworkMetrics , networkMetricsTotalRegisteredDReps :: Integer , networkMetricsAlwaysAbstainVotingPower :: Integer , networkMetricsAlwaysNoConfidenceVotingPower :: Integer + , networkMetricsNetworkName :: Text } data Delegation