From 0f626a23200f04f874b39c205501a43e2720719a Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Thu, 24 Sep 2020 11:37:15 +0200 Subject: [PATCH] Cleanup StdTx --- CHANGELOG.md | 3 ++ .../src/cosmwasmclient.searchtx.spec.ts | 8 ++-- packages/cosmwasm/src/cosmwasmclient.spec.ts | 2 + packages/cosmwasm/src/cosmwasmclient.ts | 4 +- packages/cosmwasm/types/cosmwasmclient.d.ts | 4 +- .../src/cosmosclient.searchtx.spec.ts | 6 +-- packages/launchpad/src/cosmosclient.spec.ts | 6 ++- packages/launchpad/src/cosmosclient.ts | 7 +-- packages/launchpad/src/index.ts | 3 +- packages/launchpad/src/lcdapi/base.ts | 4 +- .../launchpad/src/lcdapi/lcdclient.spec.ts | 4 +- packages/launchpad/src/lcdapi/lcdclient.ts | 4 +- packages/launchpad/src/sequence.spec.ts | 11 +++++ packages/launchpad/src/sequence.ts | 4 +- packages/launchpad/src/signingcosmosclient.ts | 3 +- packages/launchpad/src/testutils.spec.ts | 3 +- packages/launchpad/src/tx.ts | 44 +++++++++++++++++++ packages/launchpad/src/types.ts | 25 ----------- packages/launchpad/types/cosmosclient.d.ts | 7 +-- packages/launchpad/types/index.d.ts | 3 +- packages/launchpad/types/lcdapi/base.d.ts | 4 +- .../launchpad/types/lcdapi/lcdclient.d.ts | 4 +- packages/launchpad/types/sequence.d.ts | 4 +- packages/launchpad/types/tx.d.ts | 31 +++++++++++++ packages/launchpad/types/types.d.ts | 17 ------- 25 files changed, 137 insertions(+), 78 deletions(-) create mode 100644 packages/launchpad/src/tx.ts create mode 100644 packages/launchpad/types/tx.d.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index b2f952aa..39c01ae8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,9 @@ `StdSignDoc`. - @cosmjs/launchpad: Remove `makeSignBytes` in favour of `makeSignDoc` and `serializeSignDoc`. +- @cosmjs/launchpad: Create `WrappedTx`, `WrappedStdTx` and `isWrappedStdTx` to + better represent the Amino tx interface. Deprecate `CosmosSdkTx`, which is an + alias for `WrappedStdTx`. - @cosmjs/launchpad-ledger: Add package supporting Ledger device integration for Launchpad. Two new classes are provided: `LedgerSigner` (for most use cases) and `LaunchpadLedger` for more fine-grained access. diff --git a/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts b/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts index 83a9f3c4..db6af67a 100644 --- a/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts +++ b/packages/cosmwasm/src/cosmwasmclient.searchtx.spec.ts @@ -2,13 +2,13 @@ import { Coin, coins, - CosmosSdkTx, isBroadcastTxFailure, isMsgSend, LcdClient, makeSignDoc, MsgSend, Secp256k1Wallet, + WrappedStdTx, } from "@cosmjs/launchpad"; import { assert, sleep } from "@cosmjs/utils"; @@ -30,7 +30,7 @@ interface TestTxSend { readonly recipient: string; readonly hash: string; readonly height: number; - readonly tx: CosmosSdkTx; + readonly tx: WrappedStdTx; } interface TestTxExecute { @@ -38,7 +38,7 @@ interface TestTxExecute { readonly contract: string; readonly hash: string; readonly height: number; - readonly tx: CosmosSdkTx; + readonly tx: WrappedStdTx; } describe("CosmWasmClient.searchTx", () => { @@ -105,7 +105,7 @@ describe("CosmWasmClient.searchTx", () => { const chainId = await client.getChainId(); const signDoc = makeSignDoc([sendMsg], fee, chainId, memo, accountNumber, sequence); const { signature } = await wallet.sign(alice.address0, signDoc); - const tx: CosmosSdkTx = { + const tx: WrappedStdTx = { type: "cosmos-sdk/StdTx", value: { msg: [sendMsg], diff --git a/packages/cosmwasm/src/cosmwasmclient.spec.ts b/packages/cosmwasm/src/cosmwasmclient.spec.ts index c554a4ac..ec0f895b 100644 --- a/packages/cosmwasm/src/cosmwasmclient.spec.ts +++ b/packages/cosmwasm/src/cosmwasmclient.spec.ts @@ -3,6 +3,7 @@ import { Sha256 } from "@cosmjs/crypto"; import { Bech32, fromHex, fromUtf8, toAscii, toBase64 } from "@cosmjs/encoding"; import { assertIsBroadcastTxSuccess, + isWrappedStdTx, makeSignDoc, MsgSend, Secp256k1Wallet, @@ -200,6 +201,7 @@ describe("CosmWasmClient", () => { it("works", async () => { pendingWithoutWasmd(); const client = new CosmWasmClient(wasmd.endpoint); + assert(isWrappedStdTx(cosmoshub.tx)); expect(await client.getIdentifier(cosmoshub.tx)).toEqual(cosmoshub.id); }); }); diff --git a/packages/cosmwasm/src/cosmwasmclient.ts b/packages/cosmwasm/src/cosmwasmclient.ts index 4541ed86..f2b26ab0 100644 --- a/packages/cosmwasm/src/cosmwasmclient.ts +++ b/packages/cosmwasm/src/cosmwasmclient.ts @@ -5,7 +5,6 @@ import { BroadcastMode, BroadcastTxResult, Coin, - CosmosSdkTx, IndexedTx, LcdClient, normalizePubkey, @@ -13,6 +12,7 @@ import { setupAuthExtension, StdTx, uint64ToNumber, + WrappedStdTx, } from "@cosmjs/launchpad"; import { Uint53 } from "@cosmjs/math"; @@ -199,7 +199,7 @@ export class CosmWasmClient { /** * Returns a 32 byte upper-case hex transaction hash (typically used as the transaction ID) */ - public async getIdentifier(tx: CosmosSdkTx): Promise { + public async getIdentifier(tx: WrappedStdTx): Promise { // We consult the REST API because we don't have a local amino encoder const response = await this.lcdClient.encodeTx(tx); const hash = new Sha256(fromBase64(response.tx)).digest(); diff --git a/packages/cosmwasm/types/cosmwasmclient.d.ts b/packages/cosmwasm/types/cosmwasmclient.d.ts index ca145907..bd4f4cb5 100644 --- a/packages/cosmwasm/types/cosmwasmclient.d.ts +++ b/packages/cosmwasm/types/cosmwasmclient.d.ts @@ -3,11 +3,11 @@ import { BroadcastMode, BroadcastTxResult, Coin, - CosmosSdkTx, IndexedTx, LcdClient, PubKey, StdTx, + WrappedStdTx, } from "@cosmjs/launchpad"; import { WasmExtension } from "./lcdapi/wasm"; import { JsonObject } from "./types"; @@ -132,7 +132,7 @@ export declare class CosmWasmClient { /** * Returns a 32 byte upper-case hex transaction hash (typically used as the transaction ID) */ - getIdentifier(tx: CosmosSdkTx): Promise; + getIdentifier(tx: WrappedStdTx): Promise; /** * Returns account number and sequence. * diff --git a/packages/launchpad/src/cosmosclient.searchtx.spec.ts b/packages/launchpad/src/cosmosclient.searchtx.spec.ts index 4a5f7a50..e6f06067 100644 --- a/packages/launchpad/src/cosmosclient.searchtx.spec.ts +++ b/packages/launchpad/src/cosmosclient.searchtx.spec.ts @@ -16,14 +16,14 @@ import { wasmd, wasmdEnabled, } from "./testutils.spec"; -import { CosmosSdkTx } from "./types"; +import { WrappedStdTx } from "./tx"; interface TestTxSend { readonly sender: string; readonly recipient: string; readonly hash: string; readonly height: number; - readonly tx: CosmosSdkTx; + readonly tx: WrappedStdTx; } describe("CosmosClient.searchTx", () => { @@ -57,7 +57,7 @@ describe("CosmosClient.searchTx", () => { const chainId = await client.getChainId(); const signDoc = makeSignDoc([sendMsg], fee, chainId, memo, accountNumber, sequence); const { signature } = await wallet.sign(walletAddress, signDoc); - const tx: CosmosSdkTx = { + const tx: WrappedStdTx = { type: "cosmos-sdk/StdTx", value: { msg: [sendMsg], diff --git a/packages/launchpad/src/cosmosclient.spec.ts b/packages/launchpad/src/cosmosclient.spec.ts index cdfd95b2..4cf1deba 100644 --- a/packages/launchpad/src/cosmosclient.spec.ts +++ b/packages/launchpad/src/cosmosclient.spec.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { sleep } from "@cosmjs/utils"; +import { assert, sleep } from "@cosmjs/utils"; import { ReadonlyDate } from "readonly-date"; import { assertIsBroadcastTxSuccess, CosmosClient, PrivateCosmosClient } from "./cosmosclient"; @@ -16,7 +16,8 @@ import { unused, wasmd, } from "./testutils.spec"; -import { StdFee, StdTx } from "./types"; +import { isWrappedStdTx, StdTx } from "./tx"; +import { StdFee } from "./types"; const blockTime = 1_000; // ms @@ -190,6 +191,7 @@ describe("CosmosClient", () => { it("works", async () => { pendingWithoutWasmd(); const client = new CosmosClient(wasmd.endpoint); + assert(isWrappedStdTx(cosmoshub.tx)); expect(await client.getIdentifier(cosmoshub.tx)).toEqual(cosmoshub.id); }); }); diff --git a/packages/launchpad/src/cosmosclient.ts b/packages/launchpad/src/cosmosclient.ts index 9bb0d2ca..c59ec73f 100644 --- a/packages/launchpad/src/cosmosclient.ts +++ b/packages/launchpad/src/cosmosclient.ts @@ -12,7 +12,8 @@ import { uint64ToNumber, } from "./lcdapi"; import { Log, parseLogs } from "./logs"; -import { CosmosSdkTx, PubKey, StdTx } from "./types"; +import { StdTx, WrappedStdTx } from "./tx"; +import { PubKey } from "./types"; export interface GetSequenceResult { readonly accountNumber: number; @@ -121,7 +122,7 @@ export interface IndexedTx { readonly code: number; readonly rawLog: string; readonly logs: readonly Log[]; - readonly tx: CosmosSdkTx; + readonly tx: WrappedStdTx; /** The gas limit as set by the user */ readonly gasWanted?: number; /** The gas used by the execution */ @@ -203,7 +204,7 @@ export class CosmosClient { /** * Returns a 32 byte upper-case hex transaction hash (typically used as the transaction ID) */ - public async getIdentifier(tx: CosmosSdkTx): Promise { + public async getIdentifier(tx: WrappedStdTx): Promise { // We consult the REST API because we don't have a local amino encoder const response = await this.lcdClient.encodeTx(tx); const hash = new Sha256(fromBase64(response.tx)).digest(); diff --git a/packages/launchpad/src/index.ts b/packages/launchpad/src/index.ts index 83087701..ed8aa4ad 100644 --- a/packages/launchpad/src/index.ts +++ b/packages/launchpad/src/index.ts @@ -100,6 +100,7 @@ export { findSequenceForSignedTx } from "./sequence"; export { encodeSecp256k1Signature, decodeSignature } from "./signature"; export { AccountData, Algo, OfflineSigner, SignResponse } from "./signer"; export { CosmosFeeTable, SigningCosmosClient } from "./signingcosmosclient"; -export { isStdTx, pubkeyType, CosmosSdkTx, PubKey, StdFee, StdSignature, StdTx } from "./types"; +export { isStdTx, isWrappedStdTx, CosmosSdkTx, StdTx, WrappedStdTx, WrappedTx } from "./tx"; +export { pubkeyType, PubKey, StdFee, StdSignature } from "./types"; export { makeCosmoshubPath, executeKdf, KdfConfiguration } from "./wallet"; export { extractKdfConfiguration, Secp256k1Wallet } from "./secp256k1wallet"; diff --git a/packages/launchpad/src/lcdapi/base.ts b/packages/launchpad/src/lcdapi/base.ts index 85465454..442eda3f 100644 --- a/packages/launchpad/src/lcdapi/base.ts +++ b/packages/launchpad/src/lcdapi/base.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { CosmosSdkTx } from "../types"; +import { WrappedStdTx } from "../tx"; /** * The mode used to send transaction @@ -109,7 +109,7 @@ export interface TxsResponse { readonly code?: number; readonly raw_log: string; readonly logs?: unknown[]; - readonly tx: CosmosSdkTx; + readonly tx: WrappedStdTx; /** The gas limit as set by the user */ readonly gas_wanted?: string; /** The gas used by the execution */ diff --git a/packages/launchpad/src/lcdapi/lcdclient.spec.ts b/packages/launchpad/src/lcdapi/lcdclient.spec.ts index 1a837842..b971823b 100644 --- a/packages/launchpad/src/lcdapi/lcdclient.spec.ts +++ b/packages/launchpad/src/lcdapi/lcdclient.spec.ts @@ -20,7 +20,8 @@ import { wasmd, wasmdEnabled, } from "../testutils.spec"; -import { StdFee, StdTx } from "../types"; +import { isWrappedStdTx, StdTx } from "../tx"; +import { StdFee } from "../types"; import { makeCosmoshubPath } from "../wallet"; import { setupAuthExtension } from "./auth"; import { TxsResponse } from "./base"; @@ -493,6 +494,7 @@ describe("LcdClient", () => { it("works for cosmoshub example", async () => { pendingWithoutWasmd(); const client = new LcdClient(wasmd.endpoint); + assert(isWrappedStdTx(cosmoshub.tx)); const response = await client.encodeTx(cosmoshub.tx); expect(response).toEqual( jasmine.objectContaining({ diff --git a/packages/launchpad/src/lcdapi/lcdclient.ts b/packages/launchpad/src/lcdapi/lcdclient.ts index 25bcb64a..02afc4cc 100644 --- a/packages/launchpad/src/lcdapi/lcdclient.ts +++ b/packages/launchpad/src/lcdapi/lcdclient.ts @@ -2,7 +2,7 @@ import { assert, isNonNullObject } from "@cosmjs/utils"; import axios, { AxiosError, AxiosInstance } from "axios"; -import { CosmosSdkTx, StdTx } from "../types"; +import { StdTx, WrappedStdTx } from "../tx"; import { BlockResponse, BroadcastMode, @@ -284,7 +284,7 @@ export class LcdClient { } /** returns the amino-encoding of the transaction performed by the server */ - public async encodeTx(tx: CosmosSdkTx): Promise { + public async encodeTx(tx: WrappedStdTx): Promise { const responseData = await this.post("/txs/encode", tx); if (!responseData.tx) { throw new Error("Unexpected response data format"); diff --git a/packages/launchpad/src/sequence.spec.ts b/packages/launchpad/src/sequence.spec.ts index e5d8f4cd..24c8006a 100644 --- a/packages/launchpad/src/sequence.spec.ts +++ b/packages/launchpad/src/sequence.spec.ts @@ -1,7 +1,10 @@ +import { assert } from "@cosmjs/utils"; + import { findSequenceForSignedTx } from "./sequence"; import response1 from "./testdata/txresponse1.json"; import response2 from "./testdata/txresponse2.json"; import response3 from "./testdata/txresponse3.json"; +import { isWrappedStdTx } from "./tx"; // Those values must match ./testdata/txresponse*.json const chainId = "testing"; @@ -10,6 +13,10 @@ const accountNumber = 4; describe("sequence", () => { describe("findSequenceForSignedTx", () => { it("works", async () => { + assert(isWrappedStdTx(response1.tx)); + assert(isWrappedStdTx(response2.tx)); + assert(isWrappedStdTx(response3.tx)); + const current = 100; // what we get from GET /auth/accounts/{address} expect(await findSequenceForSignedTx(response1.tx, chainId, accountNumber, current)).toEqual(10); // We know response3.height > response1.height, so the sequence must be at least 10+1 @@ -19,6 +26,10 @@ describe("sequence", () => { }); it("returns undefined when sequence is not in range", async () => { + assert(isWrappedStdTx(response1.tx)); + assert(isWrappedStdTx(response2.tx)); + assert(isWrappedStdTx(response3.tx)); + expect(await findSequenceForSignedTx(response1.tx, chainId, accountNumber, 5)).toBeUndefined(); expect(await findSequenceForSignedTx(response1.tx, chainId, accountNumber, 20, 11)).toBeUndefined(); expect(await findSequenceForSignedTx(response1.tx, chainId, accountNumber, 20, 50)).toBeUndefined(); diff --git a/packages/launchpad/src/sequence.ts b/packages/launchpad/src/sequence.ts index 74091372..a11c1eb2 100644 --- a/packages/launchpad/src/sequence.ts +++ b/packages/launchpad/src/sequence.ts @@ -2,7 +2,7 @@ import { Secp256k1, Secp256k1Signature, Sha256 } from "@cosmjs/crypto"; import { makeSignDoc, serializeSignDoc } from "./encoding"; import { decodeSignature } from "./signature"; -import { CosmosSdkTx } from "./types"; +import { WrappedStdTx } from "./tx"; /** * Serach for sequence s with `min` <= `s` < `upperBound` to find the sequence that was used to sign the transaction @@ -16,7 +16,7 @@ import { CosmosSdkTx } from "./types"; * @returns the sequence if a match was found and undefined otherwise */ export async function findSequenceForSignedTx( - tx: CosmosSdkTx, + tx: WrappedStdTx, chainId: string, accountNumber: number, upperBound: number, diff --git a/packages/launchpad/src/signingcosmosclient.ts b/packages/launchpad/src/signingcosmosclient.ts index d1e0a8b5..0c1edd5c 100644 --- a/packages/launchpad/src/signingcosmosclient.ts +++ b/packages/launchpad/src/signingcosmosclient.ts @@ -6,7 +6,8 @@ import { buildFeeTable, FeeTable, GasLimits, GasPrice } from "./gas"; import { BroadcastMode } from "./lcdapi"; import { Msg, MsgSend } from "./msgs"; import { OfflineSigner } from "./signer"; -import { StdFee, StdTx } from "./types"; +import { StdTx } from "./tx"; +import { StdFee } from "./types"; /** * These fees are used by the higher level methods of SigningCosmosClient diff --git a/packages/launchpad/src/testutils.spec.ts b/packages/launchpad/src/testutils.spec.ts index 2093b56e..335880b1 100644 --- a/packages/launchpad/src/testutils.spec.ts +++ b/packages/launchpad/src/testutils.spec.ts @@ -2,7 +2,8 @@ import { Random } from "@cosmjs/crypto"; import { Bech32 } from "@cosmjs/encoding"; import { Msg } from "./msgs"; -import { StdFee, StdSignature, StdTx } from "./types"; +import { StdTx } from "./tx"; +import { StdFee, StdSignature } from "./types"; export function makeRandomAddress(): string { return Bech32.encode("cosmos", Random.getBytes(20)); diff --git a/packages/launchpad/src/tx.ts b/packages/launchpad/src/tx.ts new file mode 100644 index 00000000..53c0198c --- /dev/null +++ b/packages/launchpad/src/tx.ts @@ -0,0 +1,44 @@ +import { Msg } from "./msgs"; +import { StdFee, StdSignature } from "./types"; + +/** + * A Cosmos SDK StdTx + * + * @see https://docs.cosmos.network/master/modules/auth/03_types.html#stdtx + */ +export interface StdTx { + readonly msg: readonly Msg[]; + readonly fee: StdFee; + readonly signatures: readonly StdSignature[]; + readonly memo: string | undefined; +} + +export function isStdTx(txValue: unknown): txValue is StdTx { + const { memo, msg, fee, signatures } = txValue as StdTx; + return ( + typeof memo === "string" && Array.isArray(msg) && typeof fee === "object" && Array.isArray(signatures) + ); +} + +/** + * An Amino JSON wrapper around the Tx interface + */ +export interface WrappedTx { + readonly type: string; + readonly value: any; +} + +/** + * An Amino JSON wrapper around StdTx + */ +export interface WrappedStdTx extends WrappedTx { + readonly type: "cosmos-sdk/StdTx"; + readonly value: StdTx; +} + +export function isWrappedStdTx(wrapped: WrappedTx): wrapped is WrappedStdTx { + return (wrapped as WrappedStdTx).type === "cosmos-sdk/StdTx" && isStdTx(wrapped.value); +} + +/** @deprecated use WrappedStdTx */ +export type CosmosSdkTx = WrappedStdTx; diff --git a/packages/launchpad/src/types.ts b/packages/launchpad/src/types.ts index dc799014..01126078 100644 --- a/packages/launchpad/src/types.ts +++ b/packages/launchpad/src/types.ts @@ -1,30 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { Coin } from "./coins"; -import { Msg } from "./msgs"; - -/** - * A Cosmos SDK StdTx - * - * @see https://docs.cosmos.network/master/modules/auth/03_types.html#stdtx - */ -export interface StdTx { - readonly msg: readonly Msg[]; - readonly fee: StdFee; - readonly signatures: readonly StdSignature[]; - readonly memo: string | undefined; -} - -export function isStdTx(txValue: unknown): txValue is StdTx { - const { memo, msg, fee, signatures } = txValue as StdTx; - return ( - typeof memo === "string" && Array.isArray(msg) && typeof fee === "object" && Array.isArray(signatures) - ); -} - -export interface CosmosSdkTx { - readonly type: string; - readonly value: StdTx; -} export interface StdFee { readonly amount: readonly Coin[]; diff --git a/packages/launchpad/types/cosmosclient.d.ts b/packages/launchpad/types/cosmosclient.d.ts index dcdda89d..12bb6f2d 100644 --- a/packages/launchpad/types/cosmosclient.d.ts +++ b/packages/launchpad/types/cosmosclient.d.ts @@ -1,7 +1,8 @@ import { Coin } from "./coins"; import { AuthExtension, BroadcastMode, LcdClient } from "./lcdapi"; import { Log } from "./logs"; -import { CosmosSdkTx, PubKey, StdTx } from "./types"; +import { StdTx, WrappedStdTx } from "./tx"; +import { PubKey } from "./types"; export interface GetSequenceResult { readonly accountNumber: number; readonly sequence: number; @@ -78,7 +79,7 @@ export interface IndexedTx { readonly code: number; readonly rawLog: string; readonly logs: readonly Log[]; - readonly tx: CosmosSdkTx; + readonly tx: WrappedStdTx; /** The gas limit as set by the user */ readonly gasWanted?: number; /** The gas used by the execution */ @@ -127,7 +128,7 @@ export declare class CosmosClient { /** * Returns a 32 byte upper-case hex transaction hash (typically used as the transaction ID) */ - getIdentifier(tx: CosmosSdkTx): Promise; + getIdentifier(tx: WrappedStdTx): Promise; /** * Returns account number and sequence. * diff --git a/packages/launchpad/types/index.d.ts b/packages/launchpad/types/index.d.ts index c2205839..4a87457a 100644 --- a/packages/launchpad/types/index.d.ts +++ b/packages/launchpad/types/index.d.ts @@ -98,6 +98,7 @@ export { findSequenceForSignedTx } from "./sequence"; export { encodeSecp256k1Signature, decodeSignature } from "./signature"; export { AccountData, Algo, OfflineSigner, SignResponse } from "./signer"; export { CosmosFeeTable, SigningCosmosClient } from "./signingcosmosclient"; -export { isStdTx, pubkeyType, CosmosSdkTx, PubKey, StdFee, StdSignature, StdTx } from "./types"; +export { isStdTx, isWrappedStdTx, CosmosSdkTx, StdTx, WrappedStdTx, WrappedTx } from "./tx"; +export { pubkeyType, PubKey, StdFee, StdSignature } from "./types"; export { makeCosmoshubPath, executeKdf, KdfConfiguration } from "./wallet"; export { extractKdfConfiguration, Secp256k1Wallet } from "./secp256k1wallet"; diff --git a/packages/launchpad/types/lcdapi/base.d.ts b/packages/launchpad/types/lcdapi/base.d.ts index c8f58d7c..f35cfcd0 100644 --- a/packages/launchpad/types/lcdapi/base.d.ts +++ b/packages/launchpad/types/lcdapi/base.d.ts @@ -1,4 +1,4 @@ -import { CosmosSdkTx } from "../types"; +import { WrappedStdTx } from "../tx"; /** * The mode used to send transaction * @@ -93,7 +93,7 @@ export interface TxsResponse { readonly code?: number; readonly raw_log: string; readonly logs?: unknown[]; - readonly tx: CosmosSdkTx; + readonly tx: WrappedStdTx; /** The gas limit as set by the user */ readonly gas_wanted?: string; /** The gas used by the execution */ diff --git a/packages/launchpad/types/lcdapi/lcdclient.d.ts b/packages/launchpad/types/lcdapi/lcdclient.d.ts index b5cfd8ba..56682379 100644 --- a/packages/launchpad/types/lcdapi/lcdclient.d.ts +++ b/packages/launchpad/types/lcdapi/lcdclient.d.ts @@ -1,4 +1,4 @@ -import { CosmosSdkTx, StdTx } from "../types"; +import { StdTx, WrappedStdTx } from "../tx"; import { BlockResponse, BroadcastMode, @@ -151,7 +151,7 @@ export declare class LcdClient { txById(id: string): Promise; txsQuery(query: string): Promise; /** returns the amino-encoding of the transaction performed by the server */ - encodeTx(tx: CosmosSdkTx): Promise; + encodeTx(tx: WrappedStdTx): Promise; /** * Broadcasts a signed transaction to the transaction pool. * Depending on the client's broadcast mode, this might or might diff --git a/packages/launchpad/types/sequence.d.ts b/packages/launchpad/types/sequence.d.ts index 70d38469..3bd3430d 100644 --- a/packages/launchpad/types/sequence.d.ts +++ b/packages/launchpad/types/sequence.d.ts @@ -1,4 +1,4 @@ -import { CosmosSdkTx } from "./types"; +import { WrappedStdTx } from "./tx"; /** * Serach for sequence s with `min` <= `s` < `upperBound` to find the sequence that was used to sign the transaction * @@ -11,7 +11,7 @@ import { CosmosSdkTx } from "./types"; * @returns the sequence if a match was found and undefined otherwise */ export declare function findSequenceForSignedTx( - tx: CosmosSdkTx, + tx: WrappedStdTx, chainId: string, accountNumber: number, upperBound: number, diff --git a/packages/launchpad/types/tx.d.ts b/packages/launchpad/types/tx.d.ts new file mode 100644 index 00000000..8bf6134e --- /dev/null +++ b/packages/launchpad/types/tx.d.ts @@ -0,0 +1,31 @@ +import { Msg } from "./msgs"; +import { StdFee, StdSignature } from "./types"; +/** + * A Cosmos SDK StdTx + * + * @see https://docs.cosmos.network/master/modules/auth/03_types.html#stdtx + */ +export interface StdTx { + readonly msg: readonly Msg[]; + readonly fee: StdFee; + readonly signatures: readonly StdSignature[]; + readonly memo: string | undefined; +} +export declare function isStdTx(txValue: unknown): txValue is StdTx; +/** + * An Amino JSON wrapper around the Tx interface + */ +export interface WrappedTx { + readonly type: string; + readonly value: any; +} +/** + * An Amino JSON wrapper around StdTx + */ +export interface WrappedStdTx extends WrappedTx { + readonly type: "cosmos-sdk/StdTx"; + readonly value: StdTx; +} +export declare function isWrappedStdTx(wrapped: WrappedTx): wrapped is WrappedStdTx; +/** @deprecated use WrappedStdTx */ +export declare type CosmosSdkTx = WrappedStdTx; diff --git a/packages/launchpad/types/types.d.ts b/packages/launchpad/types/types.d.ts index 1a513b41..9c22056a 100644 --- a/packages/launchpad/types/types.d.ts +++ b/packages/launchpad/types/types.d.ts @@ -1,21 +1,4 @@ import { Coin } from "./coins"; -import { Msg } from "./msgs"; -/** - * A Cosmos SDK StdTx - * - * @see https://docs.cosmos.network/master/modules/auth/03_types.html#stdtx - */ -export interface StdTx { - readonly msg: readonly Msg[]; - readonly fee: StdFee; - readonly signatures: readonly StdSignature[]; - readonly memo: string | undefined; -} -export declare function isStdTx(txValue: unknown): txValue is StdTx; -export interface CosmosSdkTx { - readonly type: string; - readonly value: StdTx; -} export interface StdFee { readonly amount: readonly Coin[]; readonly gas: string;