From e99e0f2eefff19abcbf06241b6438310f672dfb5 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 19 Aug 2020 12:54:11 +0200 Subject: [PATCH 1/2] Add CLI example to show the new GasPrice/GasLimits interface --- .circleci/config.yml | 1 + packages/cli/examples/coralnet.ts | 28 ++++++++++++++++++++++++++++ packages/cli/src/cli.ts | 1 + 3 files changed, 30 insertions(+) create mode 100644 packages/cli/examples/coralnet.ts diff --git a/.circleci/config.yml b/.circleci/config.yml index 2ff4af33..141c4db7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -145,6 +145,7 @@ jobs: 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)" diff --git a/packages/cli/examples/coralnet.ts b/packages/cli/examples/coralnet.ts new file mode 100644 index 00000000..9a489f66 --- /dev/null +++ b/packages/cli/examples/coralnet.ts @@ -0,0 +1,28 @@ +interface Options { + readonly httpUrl: string; + readonly bech32prefix: string; + readonly hdPath: readonly Slip10RawIndex[]; + readonly gasPrice: GasPrice; + readonly gasLimits: Partial>; // only set the ones you want to override +} + +const coralnetOptions: Options = { + httpUrl: 'https://lcd.coralnet.cosmwasm.com', + gasPrice: GasPrice.fromString("0.025ushell"), + bech32prefix: 'coral', + hdPath: makeCosmoshubPath(0), + gasLimits: { + upload: 1500000, + } +} + +const wallet = await Secp256k1Wallet.generate(12, coralnetOptions.hdPath, coralnetOptions.bech32prefix); +const [{ address }] = await wallet.getAccounts(); + +const client = new SigningCosmWasmClient( + coralnetOptions.httpUrl, + address, + wallet, + coralnetOptions.gasPrice, + coralnetOptions.gasLimits, +); diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index f72023af..e84a737e 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -102,6 +102,7 @@ export async function main(originalArgs: readonly string[]): Promise { "BroadcastTxResult", "Coin", "CosmosClient", + "GasLimits", "GasPrice", "Msg", "MsgDelegate", From bfeeb3ad33780031af199fa18e8470180e3a8d1a Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 19 Aug 2020 12:55:22 +0200 Subject: [PATCH 2/2] Remove obsolete buildFeeTable helper --- packages/cli/examples/helpers.ts | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/packages/cli/examples/helpers.ts b/packages/cli/examples/helpers.ts index b3898317..fc82497c 100644 --- a/packages/cli/examples/helpers.ts +++ b/packages/cli/examples/helpers.ts @@ -16,25 +16,6 @@ const defaultOptions: Options = { const defaultFaucetUrl = "https://faucet.demo-10.cosmwasm.com/credit"; -const buildFeeTable = (feeToken: string, gasPrice: number): CosmWasmFeeTable => { - const calculateFee = (gas: number, denom: string, price: number) => { - const amount = Math.floor(gas * price); - return { - amount: [{ amount: amount.toString(), denom: denom }], - gas: gas.toString(), - }; - }; - - return { - upload: calculateFee(1000000, feeToken, gasPrice), - init: calculateFee(500000, feeToken, gasPrice), - migrate: calculateFee(500000, feeToken, gasPrice), - exec: calculateFee(200000, feeToken, gasPrice), - send: calculateFee(80000, feeToken, gasPrice), - changeAdmin: calculateFee(80000, feeToken, gasPrice), - }; -}; - // TODO: hit faucet // if (config.faucetUrl) { // const acct = await client.getAccount();