Merge pull request #667 from cosmos/no-auto-imports

Avoid auto-importing types in CLI and install stargate deps
This commit is contained in:
mergify[bot] 2021-02-11 15:07:04 +00:00 committed by GitHub
commit f0ad11b69e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 120 additions and 114 deletions

View File

@ -305,14 +305,7 @@ jobs:
working_directory: packages/cli
environment:
SKIP_BUILD: 1
command: |
./bin/cosmwasm-cli --init examples/coralnet.ts --code "process.exit(0)"
./bin/cosmwasm-cli --init examples/delegate.ts --code "process.exit(0)"
./bin/cosmwasm-cli --init examples/faucet_addresses.ts --code "process.exit(0)"
./bin/cosmwasm-cli --init examples/generate_address.ts --code "process.exit(0)"
./bin/cosmwasm-cli --init examples/helpers.ts --code "process.exit(0)"
./bin/cosmwasm-cli --init examples/local_faucet.ts --code "process.exit(0)"
./bin/cosmwasm-cli --init examples/mask.ts --code "process.exit(0)"
command: ./run_examples.sh
- run:
name: Stop chains
command: |

View File

@ -1,3 +1,7 @@
import { HdPath } from "@cosmjs/crypto";
import { CosmWasmFeeTable, SigningCosmWasmClient } from "@cosmjs/cosmwasm-launchpad";
import { GasPrice, GasLimits, makeCosmoshubPath, Secp256k1HdWallet } from "@cosmjs/launchpad";
interface Options {
readonly httpUrl: string;
readonly bech32prefix: string;

View File

@ -1,3 +1,5 @@
import { coin, coins, makeSignDoc, makeStdTx, CosmosClient, MsgDelegate, Secp256k1HdWallet } from "@cosmjs/launchpad";
const wallet = await Secp256k1HdWallet.fromMnemonic(
"enlist hip relief stomach skate base shallow young switch frequent cry park",
);

View File

@ -1,3 +1,6 @@
import { toBase64 } from "@cosmjs/encoding";
import { makeCosmoshubPath, Secp256k1HdWallet } from "@cosmjs/launchpad";
const mnemonic =
"economy stock theory fatal elder harbor betray wasp final emotion task crumble siren bottom lizard educate guess current outdoor pair theory focus wife stone";

View File

@ -1,3 +1,6 @@
import { Bip39, Random } from "@cosmjs/crypto";
import { encodeSecp256k1Pubkey, Secp256k1HdWallet } from "@cosmjs/launchpad";
const mnemonic = Bip39.encode(Random.getBytes(16)).toString();
const wallet = await Secp256k1HdWallet.fromMnemonic(mnemonic);
const [{ address, pubkey }] = await wallet.getAccounts();

View File

@ -1,3 +1,10 @@
import axios from "axios";
import * as fs from "fs";
import { Bip39, Random } from "@cosmjs/crypto";
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-launchpad";
import { logs, GasPrice, Secp256k1HdWallet } from "@cosmjs/launchpad";
interface Options {
httpUrl: string;
networkId: string;

View File

@ -1,3 +1,5 @@
import { LcdClient, Secp256k1HdWallet, StdFee } from "@cosmjs/launchpad";
const defaultHttpUrl = "http://localhost:1317";
const defaultNetworkId = "testing";
const defaultFee: StdFee = {

View File

@ -1,3 +1,6 @@
import { toBase64, toUtf8 } from "@cosmjs/encoding";
import { Coin } from "@cosmjs/launchpad";
// types auto-generated by wasm.glass and cleaned up manually
export type HandleMsg =
| {

View File

@ -0,0 +1,23 @@
import { makeCosmoshubPath, DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { assertIsBroadcastTxSuccess, SigningStargateClient } from "@cosmjs/stargate";
const mnemonic = "economy stock theory fatal elder harbor betray wasp final emotion task crumble siren bottom lizard educate guess current outdoor pair theory focus wife stone";
const path = makeCosmoshubPath(3);
const prefix = "cosmos";
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, path, prefix);
const [firstAccount] = await wallet.getAccounts();
console.log("Signer address:", firstAccount.address);
const rpcEndpoint = "ws://localhost:26658";
const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, wallet);
const recipient = "cosmos1xv9tklw7d82sezh9haa573wufgy59vmwe6xxe5";
const amount = {
denom: "ucosm",
amount: "1234567",
};
const result = await client.sendTokens(firstAccount.address, recipient, [amount], "Have fun with your star coins");
assertIsBroadcastTxSuccess(result);
console.log("Successfully broadcasted:", result);
client.disconnect();

View File

@ -40,11 +40,15 @@
],
"dependencies": {
"@cosmjs/cosmwasm-launchpad": "^0.24.0-alpha.24",
"@cosmjs/cosmwasm-stargate": "^0.24.0-alpha.24",
"@cosmjs/crypto": "^0.24.0-alpha.24",
"@cosmjs/encoding": "^0.24.0-alpha.24",
"@cosmjs/faucet-client": "^0.24.0-alpha.24",
"@cosmjs/launchpad": "^0.24.0-alpha.24",
"@cosmjs/math": "^0.24.0-alpha.24",
"@cosmjs/proto-signing": "^0.24.0-alpha.24",
"@cosmjs/stargate": "^0.24.0-alpha.24",
"@cosmjs/tendermint-rpc": "^0.24.0-alpha.24",
"@cosmjs/utils": "^0.24.0-alpha.24",
"axios": "^0.21.1",
"babylon": "^6.18.0",

18
packages/cli/run_examples.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail
command -v shellcheck >/dev/null && shellcheck "$0"
PATH="$(realpath ./bin):$PATH"
cosmwasm-cli --init examples/coralnet.ts --code "process.exit(0)"
if [ -n "${LAUNCHPAD_ENABLED:-}" ]; then
cosmwasm-cli --init examples/delegate.ts --code "process.exit(0)"
fi
cosmwasm-cli --init examples/faucet_addresses.ts --code "process.exit(0)"
cosmwasm-cli --init examples/generate_address.ts --code "process.exit(0)"
cosmwasm-cli --init examples/helpers.ts --code "process.exit(0)"
cosmwasm-cli --init examples/local_faucet.ts --code "process.exit(0)"
cosmwasm-cli --init examples/mask.ts --code "process.exit(0)"
if [ -n "${SIMAPP_ENABLED:-}" ]; then
cosmwasm-cli --init examples/stargate.ts --code "process.exit(0)"
fi

View File

@ -7,6 +7,20 @@ import { TsRepl } from "./tsrepl";
import colors = require("colors/safe");
export async function installedPackages(): Promise<string[]> {
return new Promise((resolve, reject) => {
fs.readFile(__dirname + "/../package.json", { encoding: "utf8" }, (error, data) => {
if (error) {
reject(error);
} else {
const packagejson = JSON.parse(data);
const deps = Object.keys(packagejson.dependencies).sort();
resolve(deps);
}
});
});
}
export async function main(originalArgs: readonly string[]): Promise<void> {
const args = yargs
.options({
@ -35,117 +49,47 @@ export async function main(originalArgs: readonly string[]): Promise<void> {
.group(["debug", "selftest"], "Maintainer options")
.parse(originalArgs);
const imports = new Map<string, readonly string[]>([
[
"@cosmjs/cosmwasm-launchpad",
[
// cosmwasmclient
"Account",
"Block",
"BlockHeader",
"Code",
"CodeDetails",
"Contract",
"ContractCodeHistoryEntry",
"CosmWasmClient",
"GetSequenceResult",
"SearchByHeightQuery",
"SearchBySentFromOrToQuery",
"SearchByTagsQuery",
"SearchTxQuery",
"SearchTxFilter",
// signingcosmwasmclient
"ExecuteResult",
"CosmWasmFeeTable",
"InstantiateResult",
"SigningCosmWasmClient",
"UploadMeta",
"UploadResult",
],
],
[
"@cosmjs/crypto",
[
"Bip39",
"Ed25519",
"Ed25519Keypair",
"EnglishMnemonic",
"HdPath",
"Random",
"Secp256k1",
"Sha256",
"sha256",
"Sha512",
"sha512",
"Slip10",
"Slip10Curve",
"Slip10RawIndex",
],
],
[
"@cosmjs/encoding",
["fromAscii", "fromBase64", "fromHex", "fromUtf8", "toAscii", "toBase64", "toHex", "toUtf8", "Bech32"],
],
["@cosmjs/faucet-client", ["FaucetClient"]],
[
"@cosmjs/launchpad",
[
"coin",
"coins",
"decodeAminoPubkey",
"decodeBech32Pubkey",
"encodeAminoPubkey",
"encodeBech32Pubkey",
"encodeSecp256k1Pubkey",
"encodeSecp256k1Signature",
"logs",
"makeCosmoshubPath",
"makeSignDoc",
"makeStdTx",
"IndexedTx",
"BroadcastTxResult",
"Coin",
"CosmosClient",
"GasLimits",
"GasPrice",
"Msg",
"MsgDelegate",
"MsgSend",
"LcdClient",
"OfflineSigner",
"PubKey",
"pubkeyToAddress",
"Secp256k1HdWallet",
"Secp256k1Wallet",
"SigningCosmosClient",
"StdFee",
"StdSignDoc",
"StdTx",
],
],
["@cosmjs/math", ["Decimal", "Int53", "Uint32", "Uint53", "Uint64"]],
["@cosmjs/utils", ["assert", "arrayContentEquals", "sleep"]],
]);
console.info(colors.green("Initializing session for you. Have fun!"));
console.info(colors.yellow("Available imports:"));
console.info(colors.yellow(" * axios"));
console.info(colors.yellow(" * fs"));
for (const [moduleName, symbols] of imports.entries()) {
console.info(colors.yellow(` * from ${moduleName}: ${symbols.join(", ")}`));
}
let init = `
import axios from "axios";
import * as fs from "fs";
`;
for (const [moduleName, symbols] of imports.entries()) {
init += `import { ${symbols.join(", ")} } from "${moduleName}";\n`;
}
const visiblePackages = (await installedPackages()).filter(
(name) => name.startsWith("@cosmjs/") || name === "axios",
);
console.info(colors.yellow("The following packages have been installed and can be imported:"));
console.info(colors.yellow(visiblePackages.join(", ")));
let init = "";
if (args.selftest) {
// execute some trival stuff and exit
init += `
import axios from "axios";
import * as fs from "fs";
import {
fromAscii,
fromBase64,
fromHex,
fromUtf8,
toAscii,
toBase64,
toHex,
toUtf8,
Bech32,
} from "@cosmjs/encoding";
import { sha512, Bip39, Random } from "@cosmjs/crypto";
import {
coins,
encodeAminoPubkey,
encodeBech32Pubkey,
decodeBech32Pubkey,
decodeAminoPubkey,
makeCosmoshubPath,
makeSignDoc,
Secp256k1HdWallet,
Secp256k1Wallet,
StdFee,
} from "@cosmjs/launchpad";
import { Decimal } from "@cosmjs/math";
import { assert, arrayContentEquals, sleep } from "@cosmjs/utils";
await sleep(123);
const readmeContent = fs.readFileSync(process.cwd() + "/README.md");