Skip to content

Commit

Permalink
Merge pull request #2707 from IntersectMBO/main
Browse files Browse the repository at this point in the history
hotfix: 500 on ada-holder/stake key voting power
  • Loading branch information
MSzalowski authored Jan 23, 2025
2 parents c9d05d7 + 52988d2 commit 9858f85
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions govtool/backend/sql/get-stake-key-voting-power.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,46 @@
WITH RewardRest AS (
SELECT
SUM(amount) AS amount,
addr_id
FROM
reward_rest
GROUP BY
addr_id
),
Reward AS (
SELECT
SUM(amount) AS amount,
addr_id
FROM
reward
GROUP BY
addr_id
),
Balance AS (
SELECT
COALESCE(SUM(uv.value), 0) AS amount,
sa.id AS addr_id,
encode(sa.hash_raw, 'hex') AS addr_raw
FROM
stake_address sa
JOIN utxo_view uv ON uv.stake_address_id = sa.id
GROUP BY
addr_id,
addr_raw
)
SELECT
COALESCE(SUM(tx_out.value), 0) AS voting_power,
stake_address.id as addr_id
(COALESCE(rr.amount, 0) + COALESCE(r.amount, 0) + COALESCE(b.amount, 0)) AS total_balance,
b.addr_raw
FROM
stake_address
JOIN
tx_out on tx_out.stake_address_id = stake_address.id
Balance b
LEFT JOIN
tx_in ON tx_in.tx_out_id = tx_out.id AND tx_in.tx_out_index = tx_out.index
RewardRest rr ON rr.addr_id = b.addr_id
LEFT JOIN
Reward r ON r.addr_id = rr.addr_id
WHERE
stake_address.hash_raw = decode(?, 'hex') AND tx_in.id IS NULL
b.addr_id = (SELECT id FROM stake_address WHERE hash_raw = decode(?, 'hex'))
GROUP BY
stake_address.id;
b.addr_raw,
rr.amount,
r.amount,
b.amount

0 comments on commit 9858f85

Please sign in to comment.