-
Notifications
You must be signed in to change notification settings - Fork 351
/
Copy pathprofile.ts
47 lines (42 loc) · 1.57 KB
/
profile.ts
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
46
47
import { pathToString } from "@cosmjs/crypto";
import { DirectSecp256k1HdWallet, OfflineSigner } from "@cosmjs/proto-signing";
import { SigningStargateClient } from "@cosmjs/stargate";
import { PathBuilder } from "./pathbuilder";
export async function createWallets(
mnemonic: string,
pathBuilder: PathBuilder,
addressPrefix: string,
numberOfDistributors: number,
logging: boolean,
): Promise<ReadonlyArray<readonly [string, OfflineSigner]>> {
const wallets = new Array<readonly [string, OfflineSigner]>();
// first account is the token holder
const numberOfIdentities = 1 + numberOfDistributors;
for (let i = 0; i < numberOfIdentities; i++) {
const path = pathBuilder(i);
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
hdPaths: [path],
prefix: addressPrefix,
});
const [{ address }] = await wallet.getAccounts();
if (logging) {
const role = i === 0 ? "token holder " : `distributor ${i}`;
console.info(`Created ${role} (${pathToString(path)}): ${address}`);
}
wallets.push([address, wallet]);
}
return wallets;
}
export async function createClients(
apiUrl: string,
wallets: ReadonlyArray<readonly [string, OfflineSigner]>,
): Promise<ReadonlyArray<readonly [string, SigningStargateClient]>> {
// we need one client per sender
const pendingClients = wallets.map(
async ([senderAddress, wallet]): Promise<readonly [string, SigningStargateClient]> => [
senderAddress,
await SigningStargateClient.connectWithSigner(apiUrl, wallet),
],
);
return Promise.all(pendingClients);
}