Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#2653): stake key voting power calculation #2657

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ changes.

### Fixed

-
- Fix calculating stake key balance [Issue 2653](https://github.com/IntersectMBO/govtool/issues/2653)

### Changed

Expand Down
48 changes: 6 additions & 42 deletions govtool/backend/sql/get-stake-key-voting-power.sql
Original file line number Diff line number Diff line change
@@ -1,46 +1,10 @@
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(rr.amount, 0) + COALESCE(r.amount, 0) + COALESCE(b.amount, 0)) AS total_balance,
b.addr_raw
SUM(tx_out.value)
FROM
Balance b
stake_address
JOIN
tx_out on tx_out.stake_address_id = stake_address.id
LEFT JOIN
RewardRest rr ON rr.addr_id = b.addr_id
LEFT JOIN
Reward r ON r.addr_id = rr.addr_id
tx_in ON tx_in.tx_out_id = tx_out.id AND tx_in.tx_out_index = tx_out.index
WHERE
b.addr_id = (SELECT id FROM stake_address WHERE hash_raw = decode(?, 'hex'))
GROUP BY
b.addr_raw,
rr.amount,
r.amount,
b.amount
stake_address.hash_raw = decode(?, 'hex') AND tx_in.id IS NULL;
Loading