-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -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": { | ||
|
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,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() |