From 939b2b9964c6aeb5493a75850b6260727c2fe5de Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 27 Jul 2020 10:06:44 +0200 Subject: [PATCH] Use *PostTx* types and helpers from sdk38 in cosmwasm --- CHANGELOG.md | 2 ++ packages/cli/src/cli.ts | 2 +- .../src/cosmwasmclient.searchtx.spec.ts | 3 ++- packages/cosmwasm/src/cosmwasmclient.spec.ts | 6 ++--- packages/cosmwasm/src/cosmwasmclient.ts | 25 ++----------------- packages/cosmwasm/src/index.ts | 1 - .../src/signingcosmwasmclient.spec.ts | 7 +++--- .../cosmwasm/src/signingcosmwasmclient.ts | 12 +++------ packages/cosmwasm/types/cosmwasmclient.d.ts | 18 +------------ packages/cosmwasm/types/index.d.ts | 1 - .../cosmwasm/types/signingcosmwasmclient.d.ts | 4 +-- 11 files changed, 21 insertions(+), 60 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8b33ef0..1768da89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ - @cosmjs/cosmwasm: Add `SigningCosmWasmClient.signAndPost` as a mid-level abstraction between `SigningCosmWasmClient.upload`/`.instantiate`/`.execute` and `.postTx`. +- @cosmjs/cosmwasm: Use `*PostTx*` types and helpers from @cosmjs/sdk38. Remove + exported `PostTxResult`. - @cosmjs/sdk38: Rename `CosmosClient.getNonce` method to `.getSequence`. - @cosmjs/sdk38: Remove `RestClient` class in favour of new modular `LcdClient` class. diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index cb53e7b9..fa7f892f 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -42,7 +42,6 @@ export function main(originalArgs: readonly string[]): void { "ContractDetails", "CosmWasmClient", "GetSequenceResult", - "PostTxResult", "SearchByHeightQuery", "SearchByIdQuery", "SearchBySentFromOrToQuery", @@ -98,6 +97,7 @@ export function main(originalArgs: readonly string[]): void { "MsgSend", "LcdClient", "OfflineSigner", + "PostTxResult", "PubKey", "pubkeyToAddress", "Secp256k1Wallet", diff --git a/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts b/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts index 8fc6fcf0..6d902e95 100644 --- a/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts +++ b/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts @@ -4,6 +4,7 @@ import { coins, CosmosSdkTx, isMsgSend, + isPostTxFailure, LcdClient, makeSignBytes, MsgSend, @@ -11,7 +12,7 @@ import { } from "@cosmjs/sdk38"; import { assert, sleep } from "@cosmjs/utils"; -import { CosmWasmClient, isPostTxFailure } from "./cosmwasmclient"; +import { CosmWasmClient } from "./cosmwasmclient"; import { isMsgExecuteContract, isMsgInstantiateContract } from "./msgs"; import { SigningCosmWasmClient } from "./signingcosmwasmclient"; import { diff --git a/packages/cosmwasm/src/cosmwasmclient.spec.ts b/packages/cosmwasm/src/cosmwasmclient.spec.ts index 5f4121d6..8873281c 100644 --- a/packages/cosmwasm/src/cosmwasmclient.spec.ts +++ b/packages/cosmwasm/src/cosmwasmclient.spec.ts @@ -1,11 +1,11 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { Sha256 } from "@cosmjs/crypto"; import { Bech32, fromHex, fromUtf8, toAscii, toBase64 } from "@cosmjs/encoding"; -import { makeSignBytes, MsgSend, Secp256k1Wallet, StdFee } from "@cosmjs/sdk38"; +import { assertIsPostTxSuccess, makeSignBytes, MsgSend, Secp256k1Wallet, StdFee } from "@cosmjs/sdk38"; import { assert, sleep } from "@cosmjs/utils"; import { ReadonlyDate } from "readonly-date"; -import { Code, CosmWasmClient, isPostTxFailure, PrivateCosmWasmClient } from "./cosmwasmclient"; +import { Code, CosmWasmClient, PrivateCosmWasmClient } from "./cosmwasmclient"; import { findAttribute } from "./logs"; import { SigningCosmWasmClient } from "./signingcosmwasmclient"; import cosmoshub from "./testdata/cosmoshub.json"; @@ -243,7 +243,7 @@ describe("CosmWasmClient", () => { signatures: [signature], }; const result = await client.postTx(signedTx); - assert(!isPostTxFailure(result)); + assertIsPostTxSuccess(result); const { logs, transactionHash } = result; const amountAttr = findAttribute(logs, "transfer", "amount"); expect(amountAttr.value).toEqual("1234567ucosm"); diff --git a/packages/cosmwasm/src/cosmwasmclient.ts b/packages/cosmwasm/src/cosmwasmclient.ts index b22f6b94..f2543c97 100644 --- a/packages/cosmwasm/src/cosmwasmclient.ts +++ b/packages/cosmwasm/src/cosmwasmclient.ts @@ -9,13 +9,14 @@ import { decodeBech32Pubkey, IndexedTx, LcdClient, + PostTxResult, PubKey, setupAuthExtension, StdTx, } from "@cosmjs/sdk38"; import { setupWasmExtension, WasmExtension } from "./lcdapi/wasm"; -import { Log, parseLogs } from "./logs"; +import { parseLogs } from "./logs"; import { JsonObject } from "./types"; export interface GetSequenceResult { @@ -32,28 +33,6 @@ export interface Account { readonly sequence: number; } -export interface PostTxFailure { - /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ - readonly transactionHash: string; - readonly height: number; - readonly code: number; - readonly rawLog: string; -} - -export interface PostTxSuccess { - readonly logs: readonly Log[]; - readonly rawLog: string; - /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ - readonly transactionHash: string; - readonly data?: Uint8Array; -} - -export type PostTxResult = PostTxSuccess | PostTxFailure; - -export function isPostTxFailure(postTxResult: PostTxResult): postTxResult is PostTxFailure { - return !!(postTxResult as PostTxFailure).code; -} - export interface SearchByIdQuery { readonly id: string; } diff --git a/packages/cosmwasm/src/index.ts b/packages/cosmwasm/src/index.ts index 40161f60..e77ef6e9 100644 --- a/packages/cosmwasm/src/index.ts +++ b/packages/cosmwasm/src/index.ts @@ -12,7 +12,6 @@ export { ContractDetails, CosmWasmClient, GetSequenceResult, - PostTxResult, SearchByHeightQuery, SearchByIdQuery, SearchBySentFromOrToQuery, diff --git a/packages/cosmwasm/src/signingcosmwasmclient.spec.ts b/packages/cosmwasm/src/signingcosmwasmclient.spec.ts index 7a7a2936..35c53aa1 100644 --- a/packages/cosmwasm/src/signingcosmwasmclient.spec.ts +++ b/packages/cosmwasm/src/signingcosmwasmclient.spec.ts @@ -2,6 +2,7 @@ import { Sha256 } from "@cosmjs/crypto"; import { toHex } from "@cosmjs/encoding"; import { + assertIsPostTxSuccess, AuthExtension, coin, coins, @@ -12,7 +13,7 @@ import { } from "@cosmjs/sdk38"; import { assert } from "@cosmjs/utils"; -import { isPostTxFailure, PrivateCosmWasmClient } from "./cosmwasmclient"; +import { PrivateCosmWasmClient } from "./cosmwasmclient"; import { setupWasmExtension, WasmExtension } from "./lcdapi/wasm"; import { SigningCosmWasmClient, UploadMeta } from "./signingcosmwasmclient"; import { @@ -332,7 +333,7 @@ describe("SigningCosmWasmClient", () => { // send const result = await client.sendTokens(beneficiaryAddress, transferAmount, "for dinner"); - assert(!isPostTxFailure(result)); + assertIsPostTxSuccess(result); const [firstLog] = result.logs; expect(firstLog).toBeTruthy(); @@ -362,7 +363,7 @@ describe("SigningCosmWasmClient", () => { gas: "120000", // 120k }; const result = await client.signAndPost([msg], fee, "Use your power wisely"); - assert(!isPostTxFailure(result)); + assertIsPostTxSuccess(result); }); }); }); diff --git a/packages/cosmwasm/src/signingcosmwasmclient.ts b/packages/cosmwasm/src/signingcosmwasmclient.ts index c6fd17cc..83715b26 100644 --- a/packages/cosmwasm/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm/src/signingcosmwasmclient.ts @@ -6,10 +6,13 @@ import { BroadcastMode, Coin, coins, + isPostTxFailure, makeSignBytes, Msg, MsgSend, OfflineSigner, + PostTxFailure, + PostTxResult, StdFee, StdSignature, StdTx, @@ -17,14 +20,7 @@ import { import pako from "pako"; import { isValidBuilder } from "./builder"; -import { - Account, - CosmWasmClient, - GetSequenceResult, - isPostTxFailure, - PostTxFailure, - PostTxResult, -} from "./cosmwasmclient"; +import { Account, CosmWasmClient, GetSequenceResult } from "./cosmwasmclient"; import { findAttribute, Log } from "./logs"; import { MsgClearAdmin, diff --git a/packages/cosmwasm/types/cosmwasmclient.d.ts b/packages/cosmwasm/types/cosmwasmclient.d.ts index ac245804..ed3b6689 100644 --- a/packages/cosmwasm/types/cosmwasmclient.d.ts +++ b/packages/cosmwasm/types/cosmwasmclient.d.ts @@ -5,11 +5,11 @@ import { CosmosSdkTx, IndexedTx, LcdClient, + PostTxResult, PubKey, StdTx, } from "@cosmjs/sdk38"; import { WasmExtension } from "./lcdapi/wasm"; -import { Log } from "./logs"; import { JsonObject } from "./types"; export interface GetSequenceResult { readonly accountNumber: number; @@ -23,22 +23,6 @@ export interface Account { readonly accountNumber: number; readonly sequence: number; } -export interface PostTxFailure { - /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ - readonly transactionHash: string; - readonly height: number; - readonly code: number; - readonly rawLog: string; -} -export interface PostTxSuccess { - readonly logs: readonly Log[]; - readonly rawLog: string; - /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ - readonly transactionHash: string; - readonly data?: Uint8Array; -} -export declare type PostTxResult = PostTxSuccess | PostTxFailure; -export declare function isPostTxFailure(postTxResult: PostTxResult): postTxResult is PostTxFailure; export interface SearchByIdQuery { readonly id: string; } diff --git a/packages/cosmwasm/types/index.d.ts b/packages/cosmwasm/types/index.d.ts index a6406556..517e261b 100644 --- a/packages/cosmwasm/types/index.d.ts +++ b/packages/cosmwasm/types/index.d.ts @@ -11,7 +11,6 @@ export { ContractDetails, CosmWasmClient, GetSequenceResult, - PostTxResult, SearchByHeightQuery, SearchByIdQuery, SearchBySentFromOrToQuery, diff --git a/packages/cosmwasm/types/signingcosmwasmclient.d.ts b/packages/cosmwasm/types/signingcosmwasmclient.d.ts index 5c3e0fc4..71de1463 100644 --- a/packages/cosmwasm/types/signingcosmwasmclient.d.ts +++ b/packages/cosmwasm/types/signingcosmwasmclient.d.ts @@ -1,5 +1,5 @@ -import { BroadcastMode, Coin, Msg, OfflineSigner, StdFee, StdSignature } from "@cosmjs/sdk38"; -import { Account, CosmWasmClient, GetSequenceResult, PostTxResult } from "./cosmwasmclient"; +import { BroadcastMode, Coin, Msg, OfflineSigner, PostTxResult, StdFee, StdSignature } from "@cosmjs/sdk38"; +import { Account, CosmWasmClient, GetSequenceResult } from "./cosmwasmclient"; import { Log } from "./logs"; export interface SigningCallback { (signBytes: Uint8Array): Promise;