-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathgenerate_wallets.ts
More file actions
45 lines (38 loc) · 1.28 KB
/
Copy pathgenerate_wallets.ts
File metadata and controls
45 lines (38 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { writeFile } from "fs";
import { ShelleyWallet } from "./lib/helpers/crypto";
import extractDRepFromWallet from "./lib/helpers/shellyWallet";
async function generateWallets(num: number): Promise<ShelleyWallet[]> {
const wallets: ShelleyWallet[] = [];
for (let i = 0; i < num; i++) {
wallets.push(await ShelleyWallet.generate());
}
return wallets;
}
function saveWallets(wallets: ShelleyWallet[]): void {
const jsonWallets = [];
for (let i = 0; i < wallets.length; i++) {
const dRepId = extractDRepFromWallet(wallets[i]);
const networkId = process.env.NETWORK === "mainnet" ? 1 : 0;
jsonWallets.push({
...wallets[i].json(),
address: wallets[i].addressBech32(networkId),
dRepId,
});
}
const jsonString = JSON.stringify(jsonWallets, null, 2);
writeFile("lib/_mock/wallets.json", jsonString, "utf-8", (err) => {
if (err) {
throw new Error("Failed to write wallets into file");
}
});
}
// Get the number of wallets from command line arguments
const numWallets = parseInt(process.argv[2], 10);
if (isNaN(numWallets) || numWallets <= 0) {
console.error("Please provide a valid number of wallets to generate.");
process.exit(1);
}
(async () => {
const wallets = await generateWallets(numWallets);
saveWallets(wallets);
})();