Skip to content

Commit

Permalink
Merge pull request #236 from cardanoapi/fix/ada-holder-voting-power
Browse files Browse the repository at this point in the history
Update ada-holder-voting-power query
  • Loading branch information
Sital999 authored Oct 21, 2024
2 parents a03e2f5 + 2072608 commit e5b959e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions dbsync-api/src/repository/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { prisma } from "../config/db";

export const fetchFaucetBalance= async (address:string)=>{
const result = await prisma.$queryRaw`
select coalesce(sum(utxo_view.value), 0) as balance
from stake_address
join utxo_view
on utxo_view.stake_address_id = stake_address.id
where stake_address.hash_raw = decode(${address}, 'hex')
group by stake_address.hash_raw;
SELECT COALESCE(SUM(utxo_view.value::numeric), 0) + COALESCE(SUM(reward_rest.amount), 0) AS total_value
FROM stake_address
JOIN utxo_view ON utxo_view.stake_address_id = stake_address.id
LEFT JOIN reward_rest ON reward_rest.addr_id = stake_address.id
WHERE reward_rest.earned_epoch IS NULL AND
stake_address.hash_raw = decode(${address}, 'hex')
GROUP BY stake_address.hash_raw
` as Array<Record<string, number>>
return result.length?+result[0].balance:0
return result.length?+result[0].total_value:0
}

0 comments on commit e5b959e

Please sign in to comment.