mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 13:47:12 +00:00
Make FAUCET_PATH_PATTERN configurable
This commit is contained in:
parent
22aac20160
commit
b156d68dea
@ -22,6 +22,10 @@ and this project adheres to
|
||||
- @cosmjs/cosmwasm-stargate: Copy symbols `Code`, `CodeDetails`, `Contract`,
|
||||
`ContractCodeHistoryEntry` and `JsonObject` from @cosmjs/cosmwasm-launchpad
|
||||
and remove dependency on @cosmjs/cosmwasm-launchpad.
|
||||
- @cosmjs/faucet: Add new configuration variable `FAUCET_PATH_PATTERN` to
|
||||
configure the HD path of the faucet accounts ([#832]).
|
||||
|
||||
[#832]: https://github.com/cosmos/cosmjs/issues/832
|
||||
|
||||
### Changed
|
||||
|
||||
|
@ -52,6 +52,10 @@ FAUCET_GAS_PRICE Gas price for transactions as a comma separated list.
|
||||
FAUCET_GAS_LIMIT Gas limit for send transactions. Defaults to 80000.
|
||||
FAUCET_MNEMONIC Secret mnemonic that serves as the base secret for the
|
||||
faucet HD accounts
|
||||
FAUCET_PATH_PATTERN The pattern of BIP32 paths for the faucet accounts.
|
||||
Must contain one "a" placeholder that is replaced with
|
||||
the account index.
|
||||
Defaults to the Cosmos Hub path "m/44'/118'/0'/0/a".
|
||||
FAUCET_ADDRESS_PREFIX The bech32 address prefix. Defaults to "cosmos".
|
||||
FAUCET_TOKENS A comma separated list of token denoms, e.g.
|
||||
"uatom" or "ucosm, mstake".
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { Bip39, Random } from "@cosmjs/crypto";
|
||||
|
||||
import * as constants from "../constants";
|
||||
import { makePathBuilder } from "../pathbuilder";
|
||||
import { createWallets } from "../profile";
|
||||
|
||||
export async function generate(args: readonly string[]): Promise<void> {
|
||||
@ -13,6 +14,9 @@ export async function generate(args: readonly string[]): Promise<void> {
|
||||
const mnemonic = Bip39.encode(Random.getBytes(16)).toString();
|
||||
console.info(`FAUCET_MNEMONIC="${mnemonic}"`);
|
||||
|
||||
const pathBuilder = makePathBuilder(constants.pathPattern);
|
||||
console.info(`FAUCET_PATH_PATTERN="${constants.pathPattern}"`);
|
||||
|
||||
// Log the addresses
|
||||
await createWallets(mnemonic, constants.addressPrefix, constants.concurrency, true);
|
||||
await createWallets(mnemonic, pathBuilder, constants.addressPrefix, constants.concurrency, true);
|
||||
}
|
||||
|
@ -25,6 +25,10 @@ FAUCET_GAS_PRICE Gas price for transactions as a comma separated list.
|
||||
FAUCET_GAS_LIMIT Gas limit for send transactions. Defaults to 80000.
|
||||
FAUCET_MNEMONIC Secret mnemonic that serves as the base secret for the
|
||||
faucet HD accounts
|
||||
FAUCET_PATH_PATTERN The pattern of BIP32 paths for the faucet accounts.
|
||||
Must contain one "a" placeholder that is replaced with
|
||||
the account index.
|
||||
Defaults to the Cosmos Hub path "m/44'/118'/0'/0/a".
|
||||
FAUCET_ADDRESS_PREFIX The bech32 address prefix. Defaults to "cosmos".
|
||||
FAUCET_TOKENS A comma separated list of token denoms, e.g.
|
||||
"uatom" or "ucosm, mstake".
|
||||
|
@ -5,6 +5,7 @@ import { Webserver } from "../api/webserver";
|
||||
import * as constants from "../constants";
|
||||
import { logAccountsState } from "../debugging";
|
||||
import { Faucet } from "../faucet";
|
||||
import { makePathBuilder } from "../pathbuilder";
|
||||
|
||||
export async function start(args: readonly string[]): Promise<void> {
|
||||
if (args.length < 1) {
|
||||
@ -29,11 +30,13 @@ export async function start(args: readonly string[]): Promise<void> {
|
||||
// Faucet
|
||||
if (!constants.mnemonic) throw new Error("The FAUCET_MNEMONIC environment variable is not set");
|
||||
const logging = true;
|
||||
const pathBuilder = makePathBuilder(constants.pathPattern);
|
||||
const faucet = await Faucet.make(
|
||||
blockchainBaseUrl,
|
||||
constants.addressPrefix,
|
||||
constants.tokenConfig,
|
||||
constants.mnemonic,
|
||||
pathBuilder,
|
||||
constants.concurrency,
|
||||
stargate,
|
||||
logging,
|
||||
|
@ -13,6 +13,7 @@ export const concurrency: number = Number.parseInt(process.env.FAUCET_CONCURRENC
|
||||
export const port: number = Number.parseInt(process.env.FAUCET_PORT || "", 10) || 8000;
|
||||
export const mnemonic: string | undefined = process.env.FAUCET_MNEMONIC;
|
||||
export const addressPrefix = process.env.FAUCET_ADDRESS_PREFIX || "cosmos";
|
||||
export const pathPattern = process.env.FAUCET_PATH_PATTERN || "m/44'/118'/0'/0/a";
|
||||
export const tokenConfig: TokenConfiguration = {
|
||||
bankTokens: parseBankTokens(process.env.FAUCET_TOKENS || "ucosm, ustake"),
|
||||
};
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Random } from "@cosmjs/crypto";
|
||||
import { Bech32 } from "@cosmjs/encoding";
|
||||
import { CosmosClient } from "@cosmjs/launchpad";
|
||||
import { StargateClient } from "@cosmjs/stargate";
|
||||
import { makeCosmoshubPath, StargateClient } from "@cosmjs/stargate";
|
||||
import { assert } from "@cosmjs/utils";
|
||||
|
||||
import { Faucet } from "./faucet";
|
||||
@ -32,6 +32,8 @@ const faucetMnemonic =
|
||||
"economy stock theory fatal elder harbor betray wasp final emotion task crumble siren bottom lizard educate guess current outdoor pair theory focus wife stone";
|
||||
|
||||
describe("Faucet", () => {
|
||||
const pathBuilder = makeCosmoshubPath;
|
||||
|
||||
describe("launchpad", () => {
|
||||
const apiUrl = "http://localhost:1317";
|
||||
const stargate = false;
|
||||
@ -44,6 +46,7 @@ describe("Faucet", () => {
|
||||
defaultAddressPrefix,
|
||||
defaultTokenConfig,
|
||||
faucetMnemonic,
|
||||
pathBuilder,
|
||||
3,
|
||||
stargate,
|
||||
);
|
||||
@ -59,6 +62,7 @@ describe("Faucet", () => {
|
||||
defaultAddressPrefix,
|
||||
{ bankTokens: [] },
|
||||
faucetMnemonic,
|
||||
pathBuilder,
|
||||
3,
|
||||
stargate,
|
||||
);
|
||||
@ -73,6 +77,7 @@ describe("Faucet", () => {
|
||||
defaultAddressPrefix,
|
||||
defaultTokenConfig,
|
||||
faucetMnemonic,
|
||||
pathBuilder,
|
||||
3,
|
||||
stargate,
|
||||
);
|
||||
@ -89,6 +94,7 @@ describe("Faucet", () => {
|
||||
defaultAddressPrefix,
|
||||
defaultTokenConfig,
|
||||
faucetMnemonic,
|
||||
pathBuilder,
|
||||
3,
|
||||
stargate,
|
||||
);
|
||||
@ -122,6 +128,7 @@ describe("Faucet", () => {
|
||||
defaultAddressPrefix,
|
||||
defaultTokenConfig,
|
||||
faucetMnemonic,
|
||||
pathBuilder,
|
||||
3,
|
||||
stargate,
|
||||
);
|
||||
@ -150,6 +157,7 @@ describe("Faucet", () => {
|
||||
defaultAddressPrefix,
|
||||
defaultTokenConfig,
|
||||
faucetMnemonic,
|
||||
pathBuilder,
|
||||
3,
|
||||
stargate,
|
||||
);
|
||||
@ -174,6 +182,7 @@ describe("Faucet", () => {
|
||||
defaultAddressPrefix,
|
||||
defaultTokenConfig,
|
||||
faucetMnemonic,
|
||||
pathBuilder,
|
||||
3,
|
||||
stargate,
|
||||
);
|
||||
@ -200,6 +209,7 @@ describe("Faucet", () => {
|
||||
defaultAddressPrefix,
|
||||
defaultTokenConfig,
|
||||
faucetMnemonic,
|
||||
pathBuilder,
|
||||
3,
|
||||
stargate,
|
||||
);
|
||||
@ -216,6 +226,7 @@ describe("Faucet", () => {
|
||||
defaultAddressPrefix,
|
||||
defaultTokenConfig,
|
||||
faucetMnemonic,
|
||||
pathBuilder,
|
||||
1,
|
||||
stargate,
|
||||
);
|
||||
@ -262,6 +273,7 @@ describe("Faucet", () => {
|
||||
defaultAddressPrefix,
|
||||
defaultTokenConfig,
|
||||
faucetMnemonic,
|
||||
pathBuilder,
|
||||
3,
|
||||
stargate,
|
||||
);
|
||||
@ -277,6 +289,7 @@ describe("Faucet", () => {
|
||||
defaultAddressPrefix,
|
||||
{ bankTokens: [] },
|
||||
faucetMnemonic,
|
||||
pathBuilder,
|
||||
3,
|
||||
stargate,
|
||||
);
|
||||
@ -291,6 +304,7 @@ describe("Faucet", () => {
|
||||
defaultAddressPrefix,
|
||||
defaultTokenConfig,
|
||||
faucetMnemonic,
|
||||
pathBuilder,
|
||||
3,
|
||||
stargate,
|
||||
);
|
||||
@ -307,6 +321,7 @@ describe("Faucet", () => {
|
||||
defaultAddressPrefix,
|
||||
defaultTokenConfig,
|
||||
faucetMnemonic,
|
||||
pathBuilder,
|
||||
3,
|
||||
stargate,
|
||||
);
|
||||
@ -340,6 +355,7 @@ describe("Faucet", () => {
|
||||
defaultAddressPrefix,
|
||||
defaultTokenConfig,
|
||||
faucetMnemonic,
|
||||
pathBuilder,
|
||||
3,
|
||||
stargate,
|
||||
);
|
||||
@ -368,6 +384,7 @@ describe("Faucet", () => {
|
||||
defaultAddressPrefix,
|
||||
defaultTokenConfig,
|
||||
faucetMnemonic,
|
||||
pathBuilder,
|
||||
3,
|
||||
stargate,
|
||||
);
|
||||
@ -392,6 +409,7 @@ describe("Faucet", () => {
|
||||
defaultAddressPrefix,
|
||||
defaultTokenConfig,
|
||||
faucetMnemonic,
|
||||
pathBuilder,
|
||||
3,
|
||||
stargate,
|
||||
);
|
||||
@ -418,6 +436,7 @@ describe("Faucet", () => {
|
||||
defaultAddressPrefix,
|
||||
defaultTokenConfig,
|
||||
faucetMnemonic,
|
||||
pathBuilder,
|
||||
3,
|
||||
stargate,
|
||||
);
|
||||
@ -434,6 +453,7 @@ describe("Faucet", () => {
|
||||
defaultAddressPrefix,
|
||||
defaultTokenConfig,
|
||||
faucetMnemonic,
|
||||
pathBuilder,
|
||||
1,
|
||||
stargate,
|
||||
);
|
||||
|
@ -13,6 +13,7 @@ import { sleep } from "@cosmjs/utils";
|
||||
|
||||
import * as constants from "./constants";
|
||||
import { debugAccount, logAccountsState, logSendJob } from "./debugging";
|
||||
import { PathBuilder } from "./pathbuilder";
|
||||
import { createClients, createWallets } from "./profile";
|
||||
import { TokenConfiguration, TokenManager } from "./tokenmanager";
|
||||
import { MinimalAccount, SendJob } from "./types";
|
||||
@ -27,11 +28,19 @@ export class Faucet {
|
||||
addressPrefix: string,
|
||||
config: TokenConfiguration,
|
||||
mnemonic: string,
|
||||
pathBuilder: PathBuilder,
|
||||
numberOfDistributors: number,
|
||||
stargate = true,
|
||||
logging = false,
|
||||
): Promise<Faucet> {
|
||||
const wallets = await createWallets(mnemonic, addressPrefix, numberOfDistributors, stargate, logging);
|
||||
const wallets = await createWallets(
|
||||
mnemonic,
|
||||
pathBuilder,
|
||||
addressPrefix,
|
||||
numberOfDistributors,
|
||||
stargate,
|
||||
logging,
|
||||
);
|
||||
const clients = await createClients(apiUrl, wallets);
|
||||
const readonlyClient = stargate ? await StargateClient.connect(apiUrl) : new CosmosClient(apiUrl);
|
||||
return new Faucet(addressPrefix, config, clients, readonlyClient, logging);
|
||||
|
@ -1,12 +1,14 @@
|
||||
import { pathToString } from "@cosmjs/crypto";
|
||||
import { makeCosmoshubPath, Secp256k1HdWallet, SigningCosmosClient } from "@cosmjs/launchpad";
|
||||
import { Secp256k1HdWallet, SigningCosmosClient } from "@cosmjs/launchpad";
|
||||
import { DirectSecp256k1HdWallet, isOfflineDirectSigner, OfflineSigner } from "@cosmjs/proto-signing";
|
||||
import { SigningStargateClient } from "@cosmjs/stargate";
|
||||
|
||||
import * as constants from "./constants";
|
||||
import { PathBuilder } from "./pathbuilder";
|
||||
|
||||
export async function createWallets(
|
||||
mnemonic: string,
|
||||
pathBuilder: PathBuilder,
|
||||
addressPrefix: string,
|
||||
numberOfDistributors: number,
|
||||
stargate = true,
|
||||
@ -18,7 +20,7 @@ export async function createWallets(
|
||||
// first account is the token holder
|
||||
const numberOfIdentities = 1 + numberOfDistributors;
|
||||
for (let i = 0; i < numberOfIdentities; i++) {
|
||||
const path = makeCosmoshubPath(i);
|
||||
const path = pathBuilder(i);
|
||||
const wallet = await createWallet(mnemonic, { hdPaths: [path], prefix: addressPrefix });
|
||||
const [{ address }] = await wallet.getAccounts();
|
||||
if (logging) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user