Add a script to get stage1 participants with given validators

This commit is contained in:
Prathamesh Musale 2024-08-19 10:34:02 +05:30
parent 98e882bf28
commit 5af0500d18
2 changed files with 83 additions and 1 deletions

View File

@ -32,5 +32,14 @@
yarn map-subscribers-to-participants --subscribers-csv <subscribers-csv-file> --output <output-csv-file>
# 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 <validators-csv-file> --output <output-csv-file>
# Example:
# yarn participants-with-filtered-validators --validators-csv ./validators.csv --output stage1-participants-$(date +"%Y-%m-%dT%H%M%S").csv
```

View File

@ -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<void> {
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<string>).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<any> {
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);
});