From 5af0500d1871fbf21565bc3b9362910503474ae1 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 19 Aug 2024 10:34:02 +0530 Subject: [PATCH] Add a script to get stage1 participants with given validators --- scripts/README.md | 11 ++- .../participants-with-filtered-validators.ts | 73 +++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 scripts/src/participants-with-filtered-validators.ts diff --git a/scripts/README.md b/scripts/README.md index dc131e4..3f2e039 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -32,5 +32,14 @@ yarn map-subscribers-to-participants --subscribers-csv --output # Example: - # yarn map-subscribers-to-participants --subscribers-csv subscribers.csv --output result-$(date +"%Y-%m-%d%Y%m%d").csv + # yarn map-subscribers-to-participants --subscribers-csv subscribers.csv --output result-$(date +"%Y-%m-%dT%H%M%S").csv + ``` + +- Generate a list of onboarded participants with given list of validators: + + ```bash + yarn participants-with-filtered-validators --validators-csv --output + + # Example: + # yarn participants-with-filtered-validators --validators-csv ./validators.csv --output stage1-participants-$(date +"%Y-%m-%dT%H%M%S").csv ``` diff --git a/scripts/src/participants-with-filtered-validators.ts b/scripts/src/participants-with-filtered-validators.ts new file mode 100644 index 0000000..94ad544 --- /dev/null +++ b/scripts/src/participants-with-filtered-validators.ts @@ -0,0 +1,73 @@ +import * as fs from 'fs'; +import * as path from 'path'; +import yargs from 'yargs'; +import { hideBin } from 'yargs/helpers'; +import dotenv from 'dotenv'; + +import { Registry } from '@cerc-io/registry-sdk'; + +dotenv.config(); + +const LACONICD_GQL_ENDPOINT = process.env.LACONICD_GQL_ENDPOINT || 'https://laconicd.laconic.com/api'; +const LACONICD_RPC_ENDPOINT = process.env.LACONICD_RPC_ENDPOINT || 'https://laconicd.laconic.com'; +const LACONICD_CHAIN_ID = process.env.LACONICD_CHAIN_ID || 'laconic_9000-1'; + +async function main(): Promise { + const argv = _getArgv(); + + const registry = new Registry(LACONICD_GQL_ENDPOINT, LACONICD_RPC_ENDPOINT, LACONICD_CHAIN_ID); + + console.time('time_taken_getParticipants'); + const participants = await registry.getParticipants(); + console.timeEnd('time_taken_getParticipants'); + + const validators = await readValidators(argv.validatorsCsv); + console.log('Read validators, count:', validators.length); + + const stage1Participants = participants.map((participant: any) => { + const outputParticipant: any = { + 'cosmos_address': participant.cosmosAddress, + 'nitro_address': participant.nitroAddress, + 'kyc_id': participant.kycId + }; + + if ((validators as Array).includes(participant.cosmosAddress)) { + outputParticipant.role = 'validator'; + } else { + outputParticipant.role = 'participant'; + } + + return outputParticipant; + }); + + const outputFilePath = path.resolve(argv.output); + fs.writeFileSync(outputFilePath, JSON.stringify(stage1Participants, null, 2)); + console.log(`Onboarded participants with filtered validators written to ${outputFilePath}`); +} + +async function readValidators(subscribersCsvPath: string): Promise { + const fileContent = fs.readFileSync(path.resolve(subscribersCsvPath), { encoding: 'utf-8' }); + return fileContent.split('\r\n').map(address => address.trim()); +} + +function _getArgv (): any { + return yargs(hideBin(process.argv)) + .option('validatorsCsv', { + alias: 'v', + type: 'string', + demandOption: true, + describe: 'Path to a CSV file with validators list', + }) + .option('output', { + alias: 'o', + type: 'string', + demandOption: true, + describe: 'Path to the output CSV file', + }) + .help() + .argv; +} + +main().catch(err => { + console.log(err); +});