Skip to content

Commit 86a9e56

Browse files
committed
hotfix: 500 on ada-holder/stake key voting power
1 parent 9b0f347 commit 86a9e56

File tree

1 file changed

+41
-8
lines changed

1 file changed

+41
-8
lines changed
Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,46 @@
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+
)
131
SELECT
2-
COALESCE(SUM(tx_out.value), 0) AS voting_power,
3-
stake_address.id as addr_id
32+
(COALESCE(rr.amount, 0) + COALESCE(r.amount, 0) + COALESCE(b.amount, 0)) AS total_balance,
33+
b.addr_raw
434
FROM
5-
stake_address
6-
JOIN
7-
tx_out on tx_out.stake_address_id = stake_address.id
35+
Balance b
836
LEFT JOIN
9-
tx_in ON tx_in.tx_out_id = tx_out.id AND tx_in.tx_out_index = tx_out.index
37+
RewardRest rr ON rr.addr_id = b.addr_id
38+
LEFT JOIN
39+
Reward r ON r.addr_id = rr.addr_id
1040
WHERE
11-
stake_address.hash_raw = decode(?, 'hex') AND tx_in.id IS NULL
41+
b.addr_id = (SELECT id FROM stake_address WHERE hash_raw = decode(?, 'hex'))
1242
GROUP BY
13-
stake_address.id;
43+
b.addr_raw,
44+
rr.amount,
45+
r.amount,
46+
b.amount

0 commit comments

Comments
 (0)