Skip to content

Commit

Permalink
added dump contracts script
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Jul 15, 2024
1 parent 84467ff commit c8546eb
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"serve:prod": "npm install && npm run build && pm2 reload ecosystem.config.js --only server && pm2 save",
"serve:prod:accounts": "npm run build && pm2 reload ecosystem.config.js --only server_accounts",
"search:update": "node dist/scripts/searchUpdate.js",
"console": "node dist/scripts/console.js"
"console": "node dist/scripts/console.js",
"dumpContracts": "node dist/scripts/dumpContracts.js"
},
"author": "Noah Saso <[email protected]>",
"devDependencies": {
Expand Down
66 changes: 66 additions & 0 deletions src/scripts/dumpContracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Dump all contract addresses from DB for matching code IDs keys.
*/

import { Command } from 'commander'
import { Op } from 'sequelize'

import { loadConfig } from '@/config'
import { Contract, loadDb } from '@/db'
import { WasmCodeService } from '@/services'
import { DbType } from '@/types'

// Parse arguments.
const program = new Command()
program.option(
'-c, --config <path>',
'path to config file, falling back to config.json'
)
program.requiredOption(
'-k, --code-ids-keys <keys>',
'comma separated list of code IDs keys from the config to revalidate'
)
program.parse()
const { config: _config, codeIdsKeys } = program.opts()

const main = async () => {
console.log(`\n[${new Date().toISOString()}] Dumping contracts...`)

// Load config with config option.
loadConfig(_config)

// Load DB on start.
const sequelize = await loadDb({
type: DbType.Data,
})

// Set up wasm code service.
await WasmCodeService.setUpInstance()

const extractedCodeIdsKeys = WasmCodeService.extractWasmCodeKeys(codeIdsKeys)
const codeIds = WasmCodeService.getInstance().findWasmCodeIdsByKeys(
...extractedCodeIdsKeys
)

if (codeIds.length === 0) {
throw new Error(
'No code IDs found matching keys: ' + extractedCodeIdsKeys.join(', ')
)
}

const contracts = await Contract.findAll({
where: {
codeId: {
[Op.in]: codeIds,
},
},
})

console.log(contracts.join(','))

await sequelize.close()

process.exit(0)
}

main()

0 comments on commit c8546eb

Please sign in to comment.