diff --git a/docker-compose.yml b/docker-compose.yml index 8fdb74de..32dfbe5c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -37,6 +37,7 @@ services: - --db-schema=app - --workers=4 - --batch-size=30 + - --unsafe # - --log-level=debug # - --unfinalized-blocks=true healthcheck: diff --git a/src/mappings/mappingHandlers.ts b/src/mappings/mappingHandlers.ts index 6a0380e6..b3557699 100644 --- a/src/mappings/mappingHandlers.ts +++ b/src/mappings/mappingHandlers.ts @@ -332,17 +332,32 @@ const fetchAccounts = async ( return [[], '']; } }; + +const findAddress = (obj: any) => { + let stack = [obj]; + + while (stack.length > 0) { + let current = stack.pop(); + + if (typeof current !== 'object' || current === null) { + continue; + } + + for (let key in current) { + if (key === 'address') { + return current[key]; + } else if (typeof current[key] === 'object') { + stack.push(current[key]); + } + } + } + + return null; +}; const extractAddresses = (accounts: (BaseAccount | ModuleAccount | VestingAccount)[]): Array => { return accounts .map((account) => { - if (isBaseAccount(account)) { - return account.address; - } else if (isModuleAccount(account)) { - return account.base_account.address; - } else if (isVestingAccount(account)) { - return account.base_vesting_account.address; - } - return ''; + return findAddress(account); }) .filter((address) => address !== null); }; @@ -365,7 +380,6 @@ const saveAccountBalances = async (address: string, balances: Balance[]) => { newBalance.denom = denom; await newBalance.save(); - logger.info(`Save Operation Successful`); } }; @@ -395,6 +409,7 @@ export const initiateBalancesTable = async (block: CosmosBlock): Promise = if (accounts) { logger.info('Storing Balances'); const accountAddresses = extractAddresses(accounts).filter(Boolean); + logger.info(`Accounts Extracted: ${accountAddresses.length}`); await fetchAndSaveBalances(accountAddresses); logger.info('Balances Stored Successfully'); offset += accounts.length;