faucet: Update for sdk38 OfflineSigner
This commit is contained in:
parent
64eba761c8
commit
51d431a956
@ -1,7 +1,7 @@
|
||||
import { Bip39, Random } from "@cosmjs/crypto";
|
||||
|
||||
import * as constants from "../constants";
|
||||
import { createPens } from "../profile";
|
||||
import { createWallets } from "../profile";
|
||||
|
||||
export async function generate(args: readonly string[]): Promise<void> {
|
||||
if (args.length < 1) {
|
||||
@ -16,5 +16,5 @@ export async function generate(args: readonly string[]): Promise<void> {
|
||||
console.info(`FAUCET_MNEMONIC="${mnemonic}"`);
|
||||
|
||||
// Log the addresses
|
||||
await createPens(mnemonic, chainId, constants.concurrency, true);
|
||||
await createWallets(mnemonic, chainId, constants.concurrency, true);
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { CosmosClient, Pen, SigningCosmosClient } from "@cosmjs/sdk38";
|
||||
import { CosmosClient, OfflineSigner, SigningCosmosClient } from "@cosmjs/sdk38";
|
||||
import { sleep } from "@cosmjs/utils";
|
||||
|
||||
import { debugAccount, logAccountsState, logSendJob } from "./debugging";
|
||||
import { createPens } from "./profile";
|
||||
import { createWallets } from "./profile";
|
||||
import { TokenManager } from "./tokenmanager";
|
||||
import { MinimalAccount, SendJob, TokenConfiguration } from "./types";
|
||||
|
||||
@ -19,8 +19,8 @@ export class Faucet {
|
||||
numberOfDistributors: number,
|
||||
logging = false,
|
||||
): Promise<Faucet> {
|
||||
const pens = await createPens(mnemonic, addressPrefix, numberOfDistributors, logging);
|
||||
return new Faucet(apiUrl, addressPrefix, config, pens, logging);
|
||||
const wallets = await createWallets(mnemonic, addressPrefix, numberOfDistributors, logging);
|
||||
return new Faucet(apiUrl, addressPrefix, config, wallets, logging);
|
||||
}
|
||||
|
||||
public readonly addressPrefix: string;
|
||||
@ -38,7 +38,7 @@ export class Faucet {
|
||||
apiUrl: string,
|
||||
addressPrefix: string,
|
||||
config: TokenConfiguration,
|
||||
pens: ReadonlyArray<readonly [string, Pen]>,
|
||||
wallets: ReadonlyArray<readonly [string, OfflineSigner]>,
|
||||
logging = false,
|
||||
) {
|
||||
this.addressPrefix = addressPrefix;
|
||||
@ -47,15 +47,13 @@ export class Faucet {
|
||||
|
||||
this.readOnlyClient = new CosmosClient(apiUrl);
|
||||
|
||||
this.holderAddress = pens[0][0];
|
||||
this.distributorAddresses = pens.slice(1).map((pair) => pair[0]);
|
||||
this.holderAddress = wallets[0][0];
|
||||
this.distributorAddresses = wallets.slice(1).map((pair) => pair[0]);
|
||||
|
||||
// we need one client per sender
|
||||
const clients: { [senderAddress: string]: SigningCosmosClient } = {};
|
||||
for (const [senderAddress, pen] of pens) {
|
||||
clients[senderAddress] = new SigningCosmosClient(apiUrl, senderAddress, (signBytes) =>
|
||||
pen.sign(signBytes),
|
||||
);
|
||||
for (const [senderAddress, wallet] of wallets) {
|
||||
clients[senderAddress] = new SigningCosmosClient(apiUrl, senderAddress, wallet);
|
||||
}
|
||||
this.clients = clients;
|
||||
this.logging = logging;
|
||||
|
||||
@ -1,26 +1,26 @@
|
||||
import { pathToString } from "@cosmjs/crypto";
|
||||
import { makeCosmoshubPath, Pen, Secp256k1Pen } from "@cosmjs/sdk38";
|
||||
import { makeCosmoshubPath, OfflineSigner, Secp256k1OfflineWallet } from "@cosmjs/sdk38";
|
||||
|
||||
export async function createPens(
|
||||
export async function createWallets(
|
||||
mnemonic: string,
|
||||
addressPrefix: string,
|
||||
numberOfDistributors: number,
|
||||
logging = false,
|
||||
): Promise<ReadonlyArray<readonly [string, Pen]>> {
|
||||
const pens = new Array<readonly [string, Pen]>();
|
||||
): 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 = makeCosmoshubPath(i);
|
||||
const pen = await Secp256k1Pen.fromMnemonic(mnemonic, path);
|
||||
const address = pen.address(addressPrefix);
|
||||
const wallet = await Secp256k1OfflineWallet.fromMnemonic(mnemonic, path, addressPrefix);
|
||||
const [{ address }] = await wallet.getAccounts();
|
||||
if (logging) {
|
||||
const role = i === 0 ? "token holder " : `distributor ${i}`;
|
||||
console.info(`Created ${role} (${pathToString(path)}): ${address}`);
|
||||
}
|
||||
pens.push([address, pen]);
|
||||
wallets.push([address, wallet]);
|
||||
}
|
||||
|
||||
return pens;
|
||||
return wallets;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user