Skip to content

Commit 959a43b

Browse files
committed
fix: update drep active delegator query
1 parent 6cd7ed3 commit 959a43b

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/repository/drep.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -796,12 +796,12 @@ export const fetchDRepActiveDelegators = async (
796796
WHERE dv.addr_id IN (SELECT id FROM stakes)
797797
GROUP BY dv.addr_id
798798
)
799-
SELECT
800-
sa.view AS stakeAddress,
801-
ENCODE(tx.hash, 'hex') AS txId,
802-
e.no AS epoch,
803-
b.time AS time,
804-
COALESCE(SUM(uv.value), 0) +
799+
SELECT json_build_object (
800+
'stakeAddress', sa.view,
801+
'txId', ENCODE(tx.hash, 'hex'),
802+
'epoch', e.no,
803+
'time', b.time,
804+
'amount', COALESCE(SUM(uv.value), 0) +
805805
COALESCE((
806806
SELECT SUM(amount)
807807
FROM reward r
@@ -825,7 +825,9 @@ export const fetchDRepActiveDelegators = async (
825825
JOIN block blka ON blka.id = txa.block_id
826826
WHERE w.addr_id = lt.addr_id
827827
), 0)
828-
), 0) AS amount
828+
), 0)
829+
) AS result,
830+
COUNT(*) OVER () AS total_count
829831
FROM latest_tx lt
830832
JOIN stake_address sa ON sa.id = lt.addr_id
831833
JOIN tx ON tx.id = lt.latest_tx_id
@@ -842,7 +844,8 @@ export const fetchDRepActiveDelegators = async (
842844
string,
843845
any
844846
>[]
845-
} else {
847+
}
848+
else {
846849
result = (await prisma.$queryRaw`
847850
WITH stakes AS (
848851
SELECT DISTINCT dv.addr_id AS id

0 commit comments

Comments
 (0)