Skip to content

Commit 95955bb

Browse files
authored
Merge pull request #2657 from IntersectMBO/fix/2653-too-much-delegation-to-myself-on-my-drep-page
fix(#2653): stake key voting power calculation
2 parents 5726578 + 1a7f68f commit 95955bb

File tree

2 files changed

+7
-43
lines changed

2 files changed

+7
-43
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ changes.
1616

1717
### Fixed
1818

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

2121
### Changed
2222

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,10 @@
1-
WITH RewardRest AS (
2-
SELECT
3-
SUM(amount) AS amount,
4-
addr_id
5-
FROM
6-
reward_rest
7-
GROUP BY
8-
addr_id
9-
),
10-
Reward AS (
11-
SELECT
12-
SUM(amount) AS amount,
13-
addr_id
14-
FROM
15-
reward
16-
GROUP BY
17-
addr_id
18-
),
19-
Balance AS (
20-
SELECT
21-
COALESCE(SUM(uv.value), 0) AS amount,
22-
sa.id AS addr_id,
23-
encode(sa.hash_raw, 'hex') AS addr_raw
24-
FROM
25-
stake_address sa
26-
JOIN utxo_view uv ON uv.stake_address_id = sa.id
27-
GROUP BY
28-
addr_id,
29-
addr_raw
30-
)
311
SELECT
32-
(COALESCE(rr.amount, 0) + COALESCE(r.amount, 0) + COALESCE(b.amount, 0)) AS total_balance,
33-
b.addr_raw
2+
SUM(tx_out.value)
343
FROM
35-
Balance b
4+
stake_address
5+
JOIN
6+
tx_out on tx_out.stake_address_id = stake_address.id
367
LEFT JOIN
37-
RewardRest rr ON rr.addr_id = b.addr_id
38-
LEFT JOIN
39-
Reward r ON r.addr_id = rr.addr_id
8+
tx_in ON tx_in.tx_out_id = tx_out.id AND tx_in.tx_out_index = tx_out.index
409
WHERE
41-
b.addr_id = (SELECT id FROM stake_address WHERE hash_raw = decode(?, 'hex'))
42-
GROUP BY
43-
b.addr_raw,
44-
rr.amount,
45-
r.amount,
46-
b.amount
10+
stake_address.hash_raw = decode(?, 'hex') AND tx_in.id IS NULL;

0 commit comments

Comments
 (0)