From 51d431a956ba040cfdef4a983ffa0a96d0c6281c Mon Sep 17 00:00:00 2001 From: willclarktech Date: Tue, 14 Jul 2020 11:49:21 +0200 Subject: [PATCH] faucet: Update for sdk38 OfflineSigner --- packages/faucet/src/actions/generate.ts | 4 ++-- packages/faucet/src/faucet.ts | 20 +++++++++----------- packages/faucet/src/profile.ts | 16 ++++++++-------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/packages/faucet/src/actions/generate.ts b/packages/faucet/src/actions/generate.ts index 73ed15c1..ad876dae 100644 --- a/packages/faucet/src/actions/generate.ts +++ b/packages/faucet/src/actions/generate.ts @@ -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 { if (args.length < 1) { @@ -16,5 +16,5 @@ export async function generate(args: readonly string[]): Promise { console.info(`FAUCET_MNEMONIC="${mnemonic}"`); // Log the addresses - await createPens(mnemonic, chainId, constants.concurrency, true); + await createWallets(mnemonic, chainId, constants.concurrency, true); } diff --git a/packages/faucet/src/faucet.ts b/packages/faucet/src/faucet.ts index b6450956..d1b0ee6f 100644 --- a/packages/faucet/src/faucet.ts +++ b/packages/faucet/src/faucet.ts @@ -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 { - 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, + wallets: ReadonlyArray, 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; diff --git a/packages/faucet/src/profile.ts b/packages/faucet/src/profile.ts index 0abc05a9..f5355fba 100644 --- a/packages/faucet/src/profile.ts +++ b/packages/faucet/src/profile.ts @@ -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> { - const pens = new Array(); +): Promise> { + const wallets = new Array(); // 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; }