Add a script to get subscribed and onboarded laconicd accounts #22
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Update the values as required
|
# Update the values as required
|
||||||
|
# By default, live laconicd testnet (laconicd.laconic.com) endpoint is configured
|
||||||
cp .env.example .env
|
cp .env.example .env
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import { hideBin } from 'yargs/helpers';
|
|||||||
import { parse as csvParse } from 'csv-parse';
|
import { parse as csvParse } from 'csv-parse';
|
||||||
import * as csvWriter from 'csv-writer';
|
import * as csvWriter from 'csv-writer';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
|
import * as cliProgress from 'cli-progress';
|
||||||
|
|
||||||
import { StargateClient } from '@cosmjs/stargate';
|
import { StargateClient } from '@cosmjs/stargate';
|
||||||
import { Registry } from '@cerc-io/registry-sdk';
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
@ -29,7 +30,7 @@ async function main(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function readSubscribers(subscribersCsvPath: string): Promise<any> {
|
async function readSubscribers(subscribersCsvPath: string): Promise<any> {
|
||||||
const fileContent = fs.readFileSync(subscribersCsvPath, { encoding: 'utf-8' });
|
const fileContent = fs.readFileSync(path.resolve(subscribersCsvPath), { encoding: 'utf-8' });
|
||||||
const headers = ['subscriber_id', 'email', 'status', 'premium?', 'created_at', 'api_subscription_id'];
|
const headers = ['subscriber_id', 'email', 'status', 'premium?', 'created_at', 'api_subscription_id'];
|
||||||
|
|
||||||
return csvParse(fileContent, { delimiter: ',', columns: headers }).toArray();
|
return csvParse(fileContent, { delimiter: ',', columns: headers }).toArray();
|
||||||
@ -46,8 +47,14 @@ async function processSubscribers(client: StargateClient, participants: any[], s
|
|||||||
kycMap[participant.kycId] = participant;
|
kycMap[participant.kycId] = participant;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Create a new progress bar instance
|
||||||
|
const progressBar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
|
||||||
|
progressBar.start(subscribers.length, 0);
|
||||||
|
|
||||||
const onboardedSubscribers: any[] = [];
|
const onboardedSubscribers: any[] = [];
|
||||||
for (const subscriber of subscribers) {
|
for (let i = 0; i < subscribers.length; i++) {
|
||||||
|
const subscriber = subscribers[i];
|
||||||
|
|
||||||
const hashedSubscriberId = hashSubscriberId(subscriber['subscriber_id']);
|
const hashedSubscriberId = hashSubscriberId(subscriber['subscriber_id']);
|
||||||
const participant = kycMap[hashedSubscriberId];
|
const participant = kycMap[hashedSubscriberId];
|
||||||
if (!participant) {
|
if (!participant) {
|
||||||
@ -91,8 +98,19 @@ async function processSubscribers(client: StargateClient, participants: any[], s
|
|||||||
};
|
};
|
||||||
|
|
||||||
onboardedSubscribers.push(onboardedSubscriber);
|
onboardedSubscribers.push(onboardedSubscriber);
|
||||||
|
|
||||||
|
// Update the progress bar
|
||||||
|
progressBar.update(i + 1);
|
||||||
|
|
||||||
|
// Wait for a second every 10 entries
|
||||||
|
if (i % 10 === 0) {
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop the progress bar
|
||||||
|
progressBar.stop();
|
||||||
|
|
||||||
const writer = csvWriter.createObjectCsvWriter({
|
const writer = csvWriter.createObjectCsvWriter({
|
||||||
path: path.resolve(outputPath),
|
path: path.resolve(outputPath),
|
||||||
header: [
|
header: [
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/cli-progress": "^3.11.6",
|
||||||
"@types/node": "^22.2.0",
|
"@types/node": "^22.2.0",
|
||||||
"@types/yargs": "^17.0.33",
|
"@types/yargs": "^17.0.33",
|
||||||
"typescript": "^5.5.4"
|
"typescript": "^5.5.4"
|
||||||
@ -13,6 +14,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@cerc-io/registry-sdk": "^0.2.6",
|
"@cerc-io/registry-sdk": "^0.2.6",
|
||||||
"@cosmjs/stargate": "^0.32.4",
|
"@cosmjs/stargate": "^0.32.4",
|
||||||
|
"cli-progress": "^3.12.0",
|
||||||
"csv-parse": "^5.5.6",
|
"csv-parse": "^5.5.6",
|
||||||
"csv-parser": "^3.0.0",
|
"csv-parser": "^3.0.0",
|
||||||
"csv-writer": "^1.6.0",
|
"csv-writer": "^1.6.0",
|
||||||
|
14
yarn.lock
14
yarn.lock
@ -751,6 +751,13 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
"@types/node" "*"
|
"@types/node" "*"
|
||||||
|
|
||||||
|
"@types/cli-progress@^3.11.6":
|
||||||
|
version "3.11.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/cli-progress/-/cli-progress-3.11.6.tgz#94b334ebe4190f710e51c1bf9b4fedb681fa9e45"
|
||||||
|
integrity sha512-cE3+jb9WRlu+uOSAugewNpITJDt1VF8dHOopPO4IABFc3SXYL5WE/+PTz/FCdZRRfIujiWW3n3aMbv1eIGVRWA==
|
||||||
|
dependencies:
|
||||||
|
"@types/node" "*"
|
||||||
|
|
||||||
"@types/google-protobuf@^3.15.5":
|
"@types/google-protobuf@^3.15.5":
|
||||||
version "3.15.12"
|
version "3.15.12"
|
||||||
resolved "https://registry.yarnpkg.com/@types/google-protobuf/-/google-protobuf-3.15.12.tgz#eb2ba0eddd65712211a2b455dc6071d665ccf49b"
|
resolved "https://registry.yarnpkg.com/@types/google-protobuf/-/google-protobuf-3.15.12.tgz#eb2ba0eddd65712211a2b455dc6071d665ccf49b"
|
||||||
@ -1024,6 +1031,13 @@ cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3:
|
|||||||
inherits "^2.0.1"
|
inherits "^2.0.1"
|
||||||
safe-buffer "^5.0.1"
|
safe-buffer "^5.0.1"
|
||||||
|
|
||||||
|
cli-progress@^3.12.0:
|
||||||
|
version "3.12.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/cli-progress/-/cli-progress-3.12.0.tgz#807ee14b66bcc086258e444ad0f19e7d42577942"
|
||||||
|
integrity sha512-tRkV3HJ1ASwm19THiiLIXLO7Im7wlTuKnvkYaTkyoAPefqjNg7W7DHKUlGRxy9vxDvbyCYQkQozvptuMkGCg8A==
|
||||||
|
dependencies:
|
||||||
|
string-width "^4.2.3"
|
||||||
|
|
||||||
cliui@^8.0.1:
|
cliui@^8.0.1:
|
||||||
version "8.0.1"
|
version "8.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/cliui/-/cliui-8.0.1.tgz#0c04b075db02cbfe60dc8e6cf2f5486b1a3608aa"
|
resolved "https://registry.yarnpkg.com/cliui/-/cliui-8.0.1.tgz#0c04b075db02cbfe60dc8e6cf2f5486b1a3608aa"
|
||||||
|
Loading…
Reference in New Issue
Block a user