mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +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`,
|
- @cosmjs/cosmwasm-stargate: Copy symbols `Code`, `CodeDetails`, `Contract`,
|
||||||
`ContractCodeHistoryEntry` and `JsonObject` from @cosmjs/cosmwasm-launchpad
|
`ContractCodeHistoryEntry` and `JsonObject` from @cosmjs/cosmwasm-launchpad
|
||||||
and remove dependency on @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
|
### 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_GAS_LIMIT Gas limit for send transactions. Defaults to 80000.
|
||||||
FAUCET_MNEMONIC Secret mnemonic that serves as the base secret for the
|
FAUCET_MNEMONIC Secret mnemonic that serves as the base secret for the
|
||||||
faucet HD accounts
|
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_ADDRESS_PREFIX The bech32 address prefix. Defaults to "cosmos".
|
||||||
FAUCET_TOKENS A comma separated list of token denoms, e.g.
|
FAUCET_TOKENS A comma separated list of token denoms, e.g.
|
||||||
"uatom" or "ucosm, mstake".
|
"uatom" or "ucosm, mstake".
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Bip39, Random } from "@cosmjs/crypto";
|
import { Bip39, Random } from "@cosmjs/crypto";
|
||||||
|
|
||||||
import * as constants from "../constants";
|
import * as constants from "../constants";
|
||||||
|
import { makePathBuilder } from "../pathbuilder";
|
||||||
import { createWallets } from "../profile";
|
import { createWallets } from "../profile";
|
||||||
|
|
||||||
export async function generate(args: readonly string[]): Promise<void> {
|
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();
|
const mnemonic = Bip39.encode(Random.getBytes(16)).toString();
|
||||||
console.info(`FAUCET_MNEMONIC="${mnemonic}"`);
|
console.info(`FAUCET_MNEMONIC="${mnemonic}"`);
|
||||||
|
|
||||||
|
const pathBuilder = makePathBuilder(constants.pathPattern);
|
||||||
|
console.info(`FAUCET_PATH_PATTERN="${constants.pathPattern}"`);
|
||||||
|
|
||||||
// Log the addresses
|
// 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_GAS_LIMIT Gas limit for send transactions. Defaults to 80000.
|
||||||
FAUCET_MNEMONIC Secret mnemonic that serves as the base secret for the
|
FAUCET_MNEMONIC Secret mnemonic that serves as the base secret for the
|
||||||
faucet HD accounts
|
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_ADDRESS_PREFIX The bech32 address prefix. Defaults to "cosmos".
|
||||||
FAUCET_TOKENS A comma separated list of token denoms, e.g.
|
FAUCET_TOKENS A comma separated list of token denoms, e.g.
|
||||||
"uatom" or "ucosm, mstake".
|
"uatom" or "ucosm, mstake".
|
||||||
|
@ -5,6 +5,7 @@ import { Webserver } from "../api/webserver";
|
|||||||
import * as constants from "../constants";
|
import * as constants from "../constants";
|
||||||
import { logAccountsState } from "../debugging";
|
import { logAccountsState } from "../debugging";
|
||||||
import { Faucet } from "../faucet";
|
import { Faucet } from "../faucet";
|
||||||
|
import { makePathBuilder } from "../pathbuilder";
|
||||||
|
|
||||||
export async function start(args: readonly string[]): Promise<void> {
|
export async function start(args: readonly string[]): Promise<void> {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
@ -29,11 +30,13 @@ export async function start(args: readonly string[]): Promise<void> {
|
|||||||
// Faucet
|
// Faucet
|
||||||
if (!constants.mnemonic) throw new Error("The FAUCET_MNEMONIC environment variable is not set");
|
if (!constants.mnemonic) throw new Error("The FAUCET_MNEMONIC environment variable is not set");
|
||||||
const logging = true;
|
const logging = true;
|
||||||
|
const pathBuilder = makePathBuilder(constants.pathPattern);
|
||||||
const faucet = await Faucet.make(
|
const faucet = await Faucet.make(
|
||||||
blockchainBaseUrl,
|
blockchainBaseUrl,
|
||||||
constants.addressPrefix,
|
constants.addressPrefix,
|
||||||
constants.tokenConfig,
|
constants.tokenConfig,
|
||||||
constants.mnemonic,
|
constants.mnemonic,
|
||||||
|
pathBuilder,
|
||||||
constants.concurrency,
|
constants.concurrency,
|
||||||
stargate,
|
stargate,
|
||||||
logging,
|
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 port: number = Number.parseInt(process.env.FAUCET_PORT || "", 10) || 8000;
|
||||||
export const mnemonic: string | undefined = process.env.FAUCET_MNEMONIC;
|
export const mnemonic: string | undefined = process.env.FAUCET_MNEMONIC;
|
||||||
export const addressPrefix = process.env.FAUCET_ADDRESS_PREFIX || "cosmos";
|
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 = {
|
export const tokenConfig: TokenConfiguration = {
|
||||||
bankTokens: parseBankTokens(process.env.FAUCET_TOKENS || "ucosm, ustake"),
|
bankTokens: parseBankTokens(process.env.FAUCET_TOKENS || "ucosm, ustake"),
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Random } from "@cosmjs/crypto";
|
import { Random } from "@cosmjs/crypto";
|
||||||
import { Bech32 } from "@cosmjs/encoding";
|
import { Bech32 } from "@cosmjs/encoding";
|
||||||
import { CosmosClient } from "@cosmjs/launchpad";
|
import { CosmosClient } from "@cosmjs/launchpad";
|
||||||
import { StargateClient } from "@cosmjs/stargate";
|
import { makeCosmoshubPath, StargateClient } from "@cosmjs/stargate";
|
||||||
import { assert } from "@cosmjs/utils";
|
import { assert } from "@cosmjs/utils";
|
||||||
|
|
||||||
import { Faucet } from "./faucet";
|
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";
|
"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", () => {
|
describe("Faucet", () => {
|
||||||
|
const pathBuilder = makeCosmoshubPath;
|
||||||
|
|
||||||
describe("launchpad", () => {
|
describe("launchpad", () => {
|
||||||
const apiUrl = "http://localhost:1317";
|
const apiUrl = "http://localhost:1317";
|
||||||
const stargate = false;
|
const stargate = false;
|
||||||
@ -44,6 +46,7 @@ describe("Faucet", () => {
|
|||||||
defaultAddressPrefix,
|
defaultAddressPrefix,
|
||||||
defaultTokenConfig,
|
defaultTokenConfig,
|
||||||
faucetMnemonic,
|
faucetMnemonic,
|
||||||
|
pathBuilder,
|
||||||
3,
|
3,
|
||||||
stargate,
|
stargate,
|
||||||
);
|
);
|
||||||
@ -59,6 +62,7 @@ describe("Faucet", () => {
|
|||||||
defaultAddressPrefix,
|
defaultAddressPrefix,
|
||||||
{ bankTokens: [] },
|
{ bankTokens: [] },
|
||||||
faucetMnemonic,
|
faucetMnemonic,
|
||||||
|
pathBuilder,
|
||||||
3,
|
3,
|
||||||
stargate,
|
stargate,
|
||||||
);
|
);
|
||||||
@ -73,6 +77,7 @@ describe("Faucet", () => {
|
|||||||
defaultAddressPrefix,
|
defaultAddressPrefix,
|
||||||
defaultTokenConfig,
|
defaultTokenConfig,
|
||||||
faucetMnemonic,
|
faucetMnemonic,
|
||||||
|
pathBuilder,
|
||||||
3,
|
3,
|
||||||
stargate,
|
stargate,
|
||||||
);
|
);
|
||||||
@ -89,6 +94,7 @@ describe("Faucet", () => {
|
|||||||
defaultAddressPrefix,
|
defaultAddressPrefix,
|
||||||
defaultTokenConfig,
|
defaultTokenConfig,
|
||||||
faucetMnemonic,
|
faucetMnemonic,
|
||||||
|
pathBuilder,
|
||||||
3,
|
3,
|
||||||
stargate,
|
stargate,
|
||||||
);
|
);
|
||||||
@ -122,6 +128,7 @@ describe("Faucet", () => {
|
|||||||
defaultAddressPrefix,
|
defaultAddressPrefix,
|
||||||
defaultTokenConfig,
|
defaultTokenConfig,
|
||||||
faucetMnemonic,
|
faucetMnemonic,
|
||||||
|
pathBuilder,
|
||||||
3,
|
3,
|
||||||
stargate,
|
stargate,
|
||||||
);
|
);
|
||||||
@ -150,6 +157,7 @@ describe("Faucet", () => {
|
|||||||
defaultAddressPrefix,
|
defaultAddressPrefix,
|
||||||
defaultTokenConfig,
|
defaultTokenConfig,
|
||||||
faucetMnemonic,
|
faucetMnemonic,
|
||||||
|
pathBuilder,
|
||||||
3,
|
3,
|
||||||
stargate,
|
stargate,
|
||||||
);
|
);
|
||||||
@ -174,6 +182,7 @@ describe("Faucet", () => {
|
|||||||
defaultAddressPrefix,
|
defaultAddressPrefix,
|
||||||
defaultTokenConfig,
|
defaultTokenConfig,
|
||||||
faucetMnemonic,
|
faucetMnemonic,
|
||||||
|
pathBuilder,
|
||||||
3,
|
3,
|
||||||
stargate,
|
stargate,
|
||||||
);
|
);
|
||||||
@ -200,6 +209,7 @@ describe("Faucet", () => {
|
|||||||
defaultAddressPrefix,
|
defaultAddressPrefix,
|
||||||
defaultTokenConfig,
|
defaultTokenConfig,
|
||||||
faucetMnemonic,
|
faucetMnemonic,
|
||||||
|
pathBuilder,
|
||||||
3,
|
3,
|
||||||
stargate,
|
stargate,
|
||||||
);
|
);
|
||||||
@ -216,6 +226,7 @@ describe("Faucet", () => {
|
|||||||
defaultAddressPrefix,
|
defaultAddressPrefix,
|
||||||
defaultTokenConfig,
|
defaultTokenConfig,
|
||||||
faucetMnemonic,
|
faucetMnemonic,
|
||||||
|
pathBuilder,
|
||||||
1,
|
1,
|
||||||
stargate,
|
stargate,
|
||||||
);
|
);
|
||||||
@ -262,6 +273,7 @@ describe("Faucet", () => {
|
|||||||
defaultAddressPrefix,
|
defaultAddressPrefix,
|
||||||
defaultTokenConfig,
|
defaultTokenConfig,
|
||||||
faucetMnemonic,
|
faucetMnemonic,
|
||||||
|
pathBuilder,
|
||||||
3,
|
3,
|
||||||
stargate,
|
stargate,
|
||||||
);
|
);
|
||||||
@ -277,6 +289,7 @@ describe("Faucet", () => {
|
|||||||
defaultAddressPrefix,
|
defaultAddressPrefix,
|
||||||
{ bankTokens: [] },
|
{ bankTokens: [] },
|
||||||
faucetMnemonic,
|
faucetMnemonic,
|
||||||
|
pathBuilder,
|
||||||
3,
|
3,
|
||||||
stargate,
|
stargate,
|
||||||
);
|
);
|
||||||
@ -291,6 +304,7 @@ describe("Faucet", () => {
|
|||||||
defaultAddressPrefix,
|
defaultAddressPrefix,
|
||||||
defaultTokenConfig,
|
defaultTokenConfig,
|
||||||
faucetMnemonic,
|
faucetMnemonic,
|
||||||
|
pathBuilder,
|
||||||
3,
|
3,
|
||||||
stargate,
|
stargate,
|
||||||
);
|
);
|
||||||
@ -307,6 +321,7 @@ describe("Faucet", () => {
|
|||||||
defaultAddressPrefix,
|
defaultAddressPrefix,
|
||||||
defaultTokenConfig,
|
defaultTokenConfig,
|
||||||
faucetMnemonic,
|
faucetMnemonic,
|
||||||
|
pathBuilder,
|
||||||
3,
|
3,
|
||||||
stargate,
|
stargate,
|
||||||
);
|
);
|
||||||
@ -340,6 +355,7 @@ describe("Faucet", () => {
|
|||||||
defaultAddressPrefix,
|
defaultAddressPrefix,
|
||||||
defaultTokenConfig,
|
defaultTokenConfig,
|
||||||
faucetMnemonic,
|
faucetMnemonic,
|
||||||
|
pathBuilder,
|
||||||
3,
|
3,
|
||||||
stargate,
|
stargate,
|
||||||
);
|
);
|
||||||
@ -368,6 +384,7 @@ describe("Faucet", () => {
|
|||||||
defaultAddressPrefix,
|
defaultAddressPrefix,
|
||||||
defaultTokenConfig,
|
defaultTokenConfig,
|
||||||
faucetMnemonic,
|
faucetMnemonic,
|
||||||
|
pathBuilder,
|
||||||
3,
|
3,
|
||||||
stargate,
|
stargate,
|
||||||
);
|
);
|
||||||
@ -392,6 +409,7 @@ describe("Faucet", () => {
|
|||||||
defaultAddressPrefix,
|
defaultAddressPrefix,
|
||||||
defaultTokenConfig,
|
defaultTokenConfig,
|
||||||
faucetMnemonic,
|
faucetMnemonic,
|
||||||
|
pathBuilder,
|
||||||
3,
|
3,
|
||||||
stargate,
|
stargate,
|
||||||
);
|
);
|
||||||
@ -418,6 +436,7 @@ describe("Faucet", () => {
|
|||||||
defaultAddressPrefix,
|
defaultAddressPrefix,
|
||||||
defaultTokenConfig,
|
defaultTokenConfig,
|
||||||
faucetMnemonic,
|
faucetMnemonic,
|
||||||
|
pathBuilder,
|
||||||
3,
|
3,
|
||||||
stargate,
|
stargate,
|
||||||
);
|
);
|
||||||
@ -434,6 +453,7 @@ describe("Faucet", () => {
|
|||||||
defaultAddressPrefix,
|
defaultAddressPrefix,
|
||||||
defaultTokenConfig,
|
defaultTokenConfig,
|
||||||
faucetMnemonic,
|
faucetMnemonic,
|
||||||
|
pathBuilder,
|
||||||
1,
|
1,
|
||||||
stargate,
|
stargate,
|
||||||
);
|
);
|
||||||
|
@ -13,6 +13,7 @@ import { sleep } from "@cosmjs/utils";
|
|||||||
|
|
||||||
import * as constants from "./constants";
|
import * as constants from "./constants";
|
||||||
import { debugAccount, logAccountsState, logSendJob } from "./debugging";
|
import { debugAccount, logAccountsState, logSendJob } from "./debugging";
|
||||||
|
import { PathBuilder } from "./pathbuilder";
|
||||||
import { createClients, createWallets } from "./profile";
|
import { createClients, createWallets } from "./profile";
|
||||||
import { TokenConfiguration, TokenManager } from "./tokenmanager";
|
import { TokenConfiguration, TokenManager } from "./tokenmanager";
|
||||||
import { MinimalAccount, SendJob } from "./types";
|
import { MinimalAccount, SendJob } from "./types";
|
||||||
@ -27,11 +28,19 @@ export class Faucet {
|
|||||||
addressPrefix: string,
|
addressPrefix: string,
|
||||||
config: TokenConfiguration,
|
config: TokenConfiguration,
|
||||||
mnemonic: string,
|
mnemonic: string,
|
||||||
|
pathBuilder: PathBuilder,
|
||||||
numberOfDistributors: number,
|
numberOfDistributors: number,
|
||||||
stargate = true,
|
stargate = true,
|
||||||
logging = false,
|
logging = false,
|
||||||
): Promise<Faucet> {
|
): 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 clients = await createClients(apiUrl, wallets);
|
||||||
const readonlyClient = stargate ? await StargateClient.connect(apiUrl) : new CosmosClient(apiUrl);
|
const readonlyClient = stargate ? await StargateClient.connect(apiUrl) : new CosmosClient(apiUrl);
|
||||||
return new Faucet(addressPrefix, config, clients, readonlyClient, logging);
|
return new Faucet(addressPrefix, config, clients, readonlyClient, logging);
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
import { pathToString } from "@cosmjs/crypto";
|
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 { DirectSecp256k1HdWallet, isOfflineDirectSigner, OfflineSigner } from "@cosmjs/proto-signing";
|
||||||
import { SigningStargateClient } from "@cosmjs/stargate";
|
import { SigningStargateClient } from "@cosmjs/stargate";
|
||||||
|
|
||||||
import * as constants from "./constants";
|
import * as constants from "./constants";
|
||||||
|
import { PathBuilder } from "./pathbuilder";
|
||||||
|
|
||||||
export async function createWallets(
|
export async function createWallets(
|
||||||
mnemonic: string,
|
mnemonic: string,
|
||||||
|
pathBuilder: PathBuilder,
|
||||||
addressPrefix: string,
|
addressPrefix: string,
|
||||||
numberOfDistributors: number,
|
numberOfDistributors: number,
|
||||||
stargate = true,
|
stargate = true,
|
||||||
@ -18,7 +20,7 @@ export async function createWallets(
|
|||||||
// first account is the token holder
|
// first account is the token holder
|
||||||
const numberOfIdentities = 1 + numberOfDistributors;
|
const numberOfIdentities = 1 + numberOfDistributors;
|
||||||
for (let i = 0; i < numberOfIdentities; i++) {
|
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 wallet = await createWallet(mnemonic, { hdPaths: [path], prefix: addressPrefix });
|
||||||
const [{ address }] = await wallet.getAccounts();
|
const [{ address }] = await wallet.getAccounts();
|
||||||
if (logging) {
|
if (logging) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user