From 7f705fcb53a4965d0f93cc4241a38d269f5a472b Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 3 Mar 2020 11:39:18 +0100 Subject: [PATCH 1/7] Use assert in selftest --- packages/cli/src/cli.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 37489d2d..e9af2618 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -80,7 +80,7 @@ export function main(originalArgs: readonly string[]): void { "Uint64", ], ], - ["@iov/utils", ["sleep"]], + ["@iov/utils", ["assert", "sleep"]], ]); console.info(colors.green("Initializing session for you. Have fun!")); @@ -128,8 +128,10 @@ export function main(originalArgs: readonly string[]): void { const hexHash = toHex(hash); export class NewDummyClass {}; - const encoded = toHex(toUtf8(toBase64(toAscii("hello world")))); + const original = "hello world"; + const encoded = toHex(toUtf8(toBase64(toAscii(original)))); const decoded = fromAscii(fromBase64(fromUtf8(fromHex(encoded)))); + assert(decoded === original); const mnemonic = Bip39.encode(Random.getBytes(16)).toString(); const pen = await Secp256k1Pen.fromMnemonic(mnemonic); From 5e26a8605f135771ec34d2f8475929dbaa2bd394 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 3 Mar 2020 11:39:49 +0100 Subject: [PATCH 2/7] Import Decimal in cli --- packages/cli/src/cli.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index e9af2618..7508d115 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -73,6 +73,7 @@ export function main(originalArgs: readonly string[]): void { [ "Bech32", "Encoding", + "Decimal", // integers "Int53", "Uint32", @@ -133,6 +134,8 @@ export function main(originalArgs: readonly string[]): void { const decoded = fromAscii(fromBase64(fromUtf8(fromHex(encoded)))); assert(decoded === original); + assert(Decimal.fromAtomics("12870000", 6).toString() === "12.87"); + const mnemonic = Bip39.encode(Random.getBytes(16)).toString(); const pen = await Secp256k1Pen.fromMnemonic(mnemonic); const pubkey = encodeSecp256k1Pubkey(pen.pubkey); From 545e1e8833a445fd06f83fff20a56cdc0e8b1efd Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Fri, 6 Mar 2020 10:03:11 +0100 Subject: [PATCH 3/7] Remove Long import from CLI package is not heavily used anymore, at least not exposed to user --- packages/cli/src/cli.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 7508d115..d2f773dc 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -88,8 +88,6 @@ export function main(originalArgs: readonly string[]): void { console.info(colors.yellow("Available imports:")); console.info(colors.yellow(" * http")); console.info(colors.yellow(" * https")); - console.info(colors.yellow(" * from long")); - console.info(colors.yellow(" - Long")); for (const moduleName of imports.keys()) { console.info(colors.yellow(` * from ${moduleName}`)); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion @@ -110,7 +108,6 @@ export function main(originalArgs: readonly string[]): void { let init = ` import * as http from 'http'; import * as https from 'https'; - import Long from "long"; `; for (const moduleName of imports.keys()) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion From efbce56ca8b51db01b1f01ac4ecdc94ae5fc5fcb Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Fri, 6 Mar 2020 10:16:51 +0100 Subject: [PATCH 4/7] Add yarn start command for development --- packages/cli/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/cli/package.json b/packages/cli/package.json index 2bde2e78..82ba370d 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -20,6 +20,7 @@ "lint": "eslint --max-warnings 0 \"**/*.{js,ts}\"", "build": "tsc", "build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build", + "start": "yarn build-or-skip && ./bin/cosmwasm-cli", "selftest": "yarn build-or-skip && ./bin/cosmwasm-cli --selftest", "test-node": "node jasmine-testrunner.js", "test": "yarn build-or-skip && yarn test-node" From 27675cfc94422a3431e7dff036e0bcae90cde149 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Fri, 6 Mar 2020 10:17:15 +0100 Subject: [PATCH 5/7] Print imports more compact --- packages/cli/src/cli.ts | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index d2f773dc..a5f485c2 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -88,35 +88,30 @@ export function main(originalArgs: readonly string[]): void { console.info(colors.yellow("Available imports:")); console.info(colors.yellow(" * http")); console.info(colors.yellow(" * https")); - for (const moduleName of imports.keys()) { - console.info(colors.yellow(` * from ${moduleName}`)); - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - for (const symbol of imports.get(moduleName)!) { - console.info(colors.yellow(` - ${symbol}`)); - } + for (const [moduleName, symbols] of imports.entries()) { + console.info(colors.yellow(` * from ${moduleName}: ${symbols.join(", ")}`)); } - console.info(colors.yellow(" * helper functions")); - console.info(colors.yellow(" - fromAscii")); - console.info(colors.yellow(" - fromBase64")); - console.info(colors.yellow(" - fromHex")); - console.info(colors.yellow(" - fromUtf8")); - console.info(colors.yellow(" - toAscii")); - console.info(colors.yellow(" - toBase64")); - console.info(colors.yellow(" - toHex")); - console.info(colors.yellow(" - toUtf8")); + const encodingHelpers = [ + "fromAscii", + "fromBase64", + "fromHex", + "fromUtf8", + "toAscii", + "toBase64", + "toHex", + "toUtf8", + ]; + console.info(colors.yellow(` * helper functions: ${encodingHelpers.join(", ")}`)); let init = ` import * as http from 'http'; import * as https from 'https'; `; - for (const moduleName of imports.keys()) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - init += `import { ${imports.get(moduleName)!.join(", ")} } from "${moduleName}";\n`; + for (const [moduleName, symbols] of imports.entries()) { + init += `import { ${symbols.join(", ")} } from "${moduleName}";\n`; } // helper functions - init += ` - const { fromAscii, fromBase64, fromHex, fromUtf8, toAscii, toBase64, toHex, toUtf8 } = Encoding; - `; + init += `const { ${encodingHelpers.join(", ")} } = Encoding;\n`; if (args.selftest) { // execute some trival stuff and exit From fae28ab0e41ee7b1119df1a56408c4d348d3c4f8 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Fri, 6 Mar 2020 10:22:19 +0100 Subject: [PATCH 6/7] Add all the cosmwasmclient and signingcosmwasmclient imports --- packages/cli/src/cli.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index a5f485c2..80ac483c 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -50,6 +50,30 @@ export function main(originalArgs: readonly string[]): void { "RestClient", "Secp256k1Pen", "types", + // cosmwasmclient + "Account", + "Block", + "BlockHeader", + "Code", + "CodeDetails", + "Contract", + "ContractDetails", + "CosmWasmClient", + "GetNonceResult", + "IndexedTx", + "PostTxResult", + "SearchByHeightQuery", + "SearchByIdQuery", + "SearchBySentFromOrToQuery", + "SearchTxQuery", + "SearchTxFilter", + // signingcosmwasmclient + "ExecuteResult", + "InstantiateResult", + "SigningCallback", + "SigningCosmWasmClient", + "UploadMeta", + "UploadResult", ], ], [ From a1f487ebb47f558f0f08cc7485b9661e309e3af5 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Fri, 6 Mar 2020 11:03:48 +0100 Subject: [PATCH 7/7] Use any instead of object, which allows accessing members unknown to the type system --- packages/bcp/src/decode.ts | 4 ++-- packages/sdk/src/types.ts | 6 +++--- packages/sdk/types/types.d.ts | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/bcp/src/decode.ts b/packages/bcp/src/decode.ts index aa4edb9c..4d4cea12 100644 --- a/packages/bcp/src/decode.ts +++ b/packages/bcp/src/decode.ts @@ -101,10 +101,10 @@ export function parseMsg( }; } - const recipient: string | undefined = (msg.value.msg as any).transfer?.recipient; + const recipient: string | undefined = msg.value.msg.transfer?.recipient; if (!recipient) throw new Error("Could not read recipient"); - const amount: string | undefined = (msg.value.msg as any).transfer?.amount; + const amount: string | undefined = msg.value.msg.transfer?.amount; if (!amount) throw new Error("Could not read recipient"); const send: SendTransaction = { diff --git a/packages/sdk/src/types.ts b/packages/sdk/src/types.ts index 1a354ade..4b519f69 100644 --- a/packages/sdk/src/types.ts +++ b/packages/sdk/src/types.ts @@ -24,7 +24,7 @@ export interface CosmosSdkTx { interface MsgTemplate { readonly type: string; - readonly value: object; + readonly value: any; } /** A Cosmos SDK token transfer message */ @@ -73,7 +73,7 @@ export interface MsgInstantiateContract extends MsgTemplate { /** Human-readable label for this contract */ readonly label: string; /** Init message as JavaScript object */ - readonly init_msg: object; + readonly init_msg: any; readonly init_funds: ReadonlyArray; }; } @@ -91,7 +91,7 @@ export interface MsgExecuteContract extends MsgTemplate { /** Bech32 account address */ readonly contract: string; /** Handle message as JavaScript object */ - readonly msg: object; + readonly msg: any; readonly sent_funds: ReadonlyArray; }; } diff --git a/packages/sdk/types/types.d.ts b/packages/sdk/types/types.d.ts index 1a62733a..b5a1da7a 100644 --- a/packages/sdk/types/types.d.ts +++ b/packages/sdk/types/types.d.ts @@ -12,7 +12,7 @@ export interface CosmosSdkTx { } interface MsgTemplate { readonly type: string; - readonly value: object; + readonly value: any; } /** A Cosmos SDK token transfer message */ export interface MsgSend extends MsgTemplate { @@ -58,7 +58,7 @@ export interface MsgInstantiateContract extends MsgTemplate { /** Human-readable label for this contract */ readonly label: string; /** Init message as JavaScript object */ - readonly init_msg: object; + readonly init_msg: any; readonly init_funds: ReadonlyArray; }; } @@ -75,7 +75,7 @@ export interface MsgExecuteContract extends MsgTemplate { /** Bech32 account address */ readonly contract: string; /** Handle message as JavaScript object */ - readonly msg: object; + readonly msg: any; readonly sent_funds: ReadonlyArray; }; }