Skip to content

Commit

Permalink
Merge pull request #6 from gear-foundation/do-fix-circ-supply
Browse files Browse the repository at this point in the history
fix: get total staking
  • Loading branch information
EugenWay authored Dec 1, 2023
2 parents f4cfbe9 + 5815bb4 commit 66213a2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/calculators/circulation-supply.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import { totalSupply } from './total-supply.js';

const STAKING_HEX = '0x7374616b696e6720';

async function getKeys(prefix) {
const result = await api.rpc.state.getKeysPaged(prefix, 1000, prefix);
async function getKeys(prefix, startKey = null) {
const result = await api.rpc.state.getKeysPaged(prefix, 1000, startKey);
if (result.length === 1000) {
const moreKeys = await getKeys(prefix);
const moreKeys = await getKeys(prefix, result[result.length - 1]);
result.push(...moreKeys);
}
return result;
Expand Down
1 change: 1 addition & 0 deletions src/calculators/total-supply.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export async function totalSupply() {
const total = await api.query.balances.totalIssuance();

const bigint = total.toBigInt() / BigInt(10 ** DECIMALS);

return Number(bigint);
}
4 changes: 3 additions & 1 deletion src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export async function getBalance(addr) {

export async function getBalances(addresses) {
const accounts = await api.queryMulti(addresses.map((addr) => [api.query.system.account, addr]));
return accounts.map(({ data: { free } }) => Number(free.toBigInt() / BigInt(10 ** 12)));
const result = accounts.map(({ data: { free } }) => Number(free.toBigInt() / BigInt(10 ** 12)));

return result;
}

export const deriveAddr = (addr) => {
Expand Down

0 comments on commit 66213a2

Please sign in to comment.