From 8876afd22312383a12c1a3848fc8760be08ab59b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sza=C5=82owski?= Date: Tue, 15 Oct 2024 10:59:19 +0200 Subject: [PATCH] fix(#2000): fix counting ada holder voting power --- CHANGELOG.md | 1 + govtool/backend/sql/get-stake-key-voting-power.sql | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c05300ca2..fba49167e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ changes. - Fix counting epoch boundaries for Governance Actions [Issue 2125](https://github.com/IntersectMBO/govtool/issues/2125) - Fix displaying the SPO Votes [Issue 2085](https://github.com/IntersectMBO/govtool/issues/2085) +- Fix counting ada holder voting power [Issue 2000](https://github.com/IntersectMBO/govtool/issues/2000) ### Changed diff --git a/govtool/backend/sql/get-stake-key-voting-power.sql b/govtool/backend/sql/get-stake-key-voting-power.sql index 59aa5049b..3c8f44020 100644 --- a/govtool/backend/sql/get-stake-key-voting-power.sql +++ b/govtool/backend/sql/get-stake-key-voting-power.sql @@ -1,6 +1,8 @@ -select coalesce(sum(utxo_view.value), 0), encode(stake_address.hash_raw, 'hex') -from stake_address -join utxo_view -on utxo_view.stake_address_id = stake_address.id -where stake_address.hash_raw = decode(?, 'hex') -group by stake_address.hash_raw +SELECT COALESCE(SUM(utxo_view.value::numeric), 0) + COALESCE(SUM(reward_rest.amount), 0) AS total_value, + encode(stake_address.hash_raw, 'hex') +FROM stake_address +JOIN utxo_view ON utxo_view.stake_address_id = stake_address.id +LEFT JOIN reward_rest ON reward_rest.addr_id = stake_address.id +WHERE reward_rest.earned_epoch IS NULL +WHERE stake_address.hash_raw = decode(?, 'hex') +GROUP BY stake_address.hash_raw; \ No newline at end of file