Skip to content

Commit

Permalink
chore: import genesis data from JSON file and update balances table
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed May 3, 2024
1 parent 80b8891 commit acaf2a7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
13 changes: 13 additions & 0 deletions genesis-local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"balances": [
{
"address": "agoric1estsewt6jqsx77pwcxkn5ah0jqgu8rhgflwfdl",
"coins": [
{
"denom": "ubld",
"amount": "999999995000000000"
}
]
}
]
}
13 changes: 13 additions & 0 deletions genesis-main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"balances": [
{
"address": "agoric1estsewt6jqsx77pwcxkn5ah0jqgu8rhgflwfdl",
"coins": [
{
"denom": "ubld",
"amount": "999999995000000000"
}
]
}
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"pub": "subql publish",
"codegen": "subql codegen",
"start:docker": "docker-compose pull && docker-compose up --remove-orphans",
"dev": "subql codegen && subql build && docker-compose pull && docker-compose up --remove-orphans",
"dev": "network=local && subql codegen && subql build && docker-compose pull && docker-compose up --remove-orphans",
"prepack": "rm -rf dist && npm run build",
"test": "jest",
"subql": "subql codegen --help",
Expand Down
30 changes: 20 additions & 10 deletions src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ import { priceFeedEventKit } from "./events/priceFeed";
import { vaultsEventKit } from "./events/vaults";
import { reservesEventKit } from "./events/reserves";
import { DecodedEvent, Operation, balancesEventKit } from "./events/balances";

import localGenesisData from "../../genesis-local.json";
import mainnetGenesisData from "../../genesis-main.json";
// @ts-ignore
BigInt.prototype.toJSON = function () {
return this.toString();
Expand Down Expand Up @@ -210,7 +211,7 @@ export async function handleBalanceEvent(
);

if (!address) {
logger.error('Address is missing or invalid.');
logger.error(`Address ${address} is missing or invalid.`);
return;
}

Expand All @@ -233,14 +234,23 @@ export async function handleBalanceEvent(
}

export async function initiateBalancesTable(block: CosmosBlock): Promise<void> {
const newBalance = new Balances(
'agoric1estsewt6jqsx77pwcxkn5ah0jqgu8rhgflwfdl'
);
newBalance.address = 'agoric1estsewt6jqsx77pwcxkn5ah0jqgu8rhgflwfdl';
newBalance.balance = BigInt(999999995000000000);
newBalance.denom = 'ubld';
try {
const data =
process.env.network === 'main' ? mainnetGenesisData : localGenesisData;

for (let element of data.balances) {
const newBalance = new Balances(element.address);
newBalance.address = element.address;
for (const coin of element.coins) {
newBalance.balance = BigInt(coin.amount);
newBalance.denom = coin.denom;
}

await newBalance.save();
await newBalance.save();
}

logger.info(`Balances Table Initiated`);
logger.info(`Balances Table Initiated`);
} catch (error) {
logger.error(`Error initiating balances table: ${error}`);
}
}

0 comments on commit acaf2a7

Please sign in to comment.