-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: erc20 total holder * feat: erc20 total holder
- Loading branch information
1 parent
b61bddb
commit 9e6012b
Showing
5 changed files
with
965 additions
and
157 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
migrations/evm/20240920024049_erc20_contract_add_total_holder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Knex } from 'knex'; | ||
import { AccountBalance } from '../../src/models'; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
await knex.schema.alterTable('erc20_contract', (table) => { | ||
table.integer('total_holder').defaultTo(0).index(); | ||
}); | ||
await knex.raw(`set statement_timeout to 0`); | ||
const totalHolders = await AccountBalance.query(knex) | ||
.select('account_balance.denom') | ||
.where('account_balance.type', AccountBalance.TYPE.ERC20_TOKEN) | ||
.andWhere('account_balance.amount', '>', 0) | ||
.count() | ||
.groupBy('account_balance.denom'); | ||
if (totalHolders.length > 0) { | ||
const stringListUpdates = totalHolders | ||
.map((totalHolder) => `('${totalHolder.denom}', ${totalHolder.count})`) | ||
.join(','); | ||
await knex.raw( | ||
`UPDATE erc20_contract SET total_holder = temp.total_holder from (VALUES ${stringListUpdates}) as temp(address, total_holder) where temp.address = erc20_contract.address` | ||
); | ||
} | ||
} | ||
|
||
export async function down(knex: Knex): Promise<void> { | ||
await knex.schema.alterTable('erc20_contract', (table) => { | ||
table.dropColumn('total_holder'); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.