diff --git a/packages/cosmwasm/src/cosmwasmclient.ts b/packages/cosmwasm/src/cosmwasmclient.ts index e8a17b4d..3ab253d7 100644 --- a/packages/cosmwasm/src/cosmwasmclient.ts +++ b/packages/cosmwasm/src/cosmwasmclient.ts @@ -199,8 +199,8 @@ export class CosmWasmClient { */ public async getIdentifier(tx: CosmosSdkTx): Promise { // We consult the REST API because we don't have a local amino encoder - const bytes = await this.restClient.encodeTx(tx); - const hash = new Sha256(bytes).digest(); + const response = await this.restClient.encodeTx(tx); + const hash = new Sha256(fromBase64(response.tx)).digest(); return toHex(hash).toUpperCase(); } diff --git a/packages/cosmwasm/src/restclient.spec.ts b/packages/cosmwasm/src/restclient.spec.ts index 8d6d48c6..955565d3 100644 --- a/packages/cosmwasm/src/restclient.spec.ts +++ b/packages/cosmwasm/src/restclient.spec.ts @@ -31,7 +31,6 @@ import { } from "./msgs"; import { RestClient } from "./restclient"; import { SigningCosmWasmClient } from "./signingcosmwasmclient"; -import cosmoshub from "./testdata/cosmoshub.json"; import { alice, bech32AddressMatcher, @@ -747,14 +746,6 @@ describe("RestClient", () => { }); }); - describe("encodeTx", () => { - it("works for cosmoshub example", async () => { - pendingWithoutWasmd(); - const client = new RestClient(wasmd.endpoint); - expect(await client.encodeTx(cosmoshub.tx)).toEqual(fromBase64(cosmoshub.tx_data)); - }); - }); - describe("postTx", () => { it("can send tokens", async () => { pendingWithoutWasmd(); diff --git a/packages/sdk38/src/cosmosclient.ts b/packages/sdk38/src/cosmosclient.ts index 5b43dc97..fc6fd5b5 100644 --- a/packages/sdk38/src/cosmosclient.ts +++ b/packages/sdk38/src/cosmosclient.ts @@ -181,8 +181,8 @@ export class CosmosClient { */ public async getIdentifier(tx: CosmosSdkTx): Promise { // We consult the REST API because we don't have a local amino encoder - const bytes = await this.restClient.encodeTx(tx); - const hash = new Sha256(bytes).digest(); + const response = await this.restClient.encodeTx(tx); + const hash = new Sha256(fromBase64(response.tx)).digest(); return toHex(hash).toUpperCase(); } diff --git a/packages/sdk38/src/index.ts b/packages/sdk38/src/index.ts index 50ca53e3..332b6398 100644 --- a/packages/sdk38/src/index.ts +++ b/packages/sdk38/src/index.ts @@ -24,6 +24,7 @@ export { AuthAccountsResponse, BlockResponse, BroadcastMode, + EncodeTxResponse, PostTxsResponse, NodeInfoResponse, RestClient, diff --git a/packages/sdk38/src/restclient.spec.ts b/packages/sdk38/src/restclient.spec.ts index bdaea11a..f2544e1e 100644 --- a/packages/sdk38/src/restclient.spec.ts +++ b/packages/sdk38/src/restclient.spec.ts @@ -1,5 +1,4 @@ /* eslint-disable @typescript-eslint/camelcase */ -import { fromBase64 } from "@cosmjs/encoding"; import { assert, sleep } from "@cosmjs/utils"; import { ReadonlyDate } from "readonly-date"; @@ -523,7 +522,12 @@ describe("RestClient", () => { it("works for cosmoshub example", async () => { pendingWithoutWasmd(); const client = new RestClient(wasmd.endpoint); - expect(await client.encodeTx(cosmoshub.tx)).toEqual(fromBase64(cosmoshub.tx_data)); + const response = await client.encodeTx(cosmoshub.tx); + expect(response).toEqual( + jasmine.objectContaining({ + tx: cosmoshub.tx_data, + }), + ); }); }); diff --git a/packages/sdk38/src/restclient.ts b/packages/sdk38/src/restclient.ts index 7404c807..0cf8e62a 100644 --- a/packages/sdk38/src/restclient.ts +++ b/packages/sdk38/src/restclient.ts @@ -1,4 +1,3 @@ -import { fromBase64 } from "@cosmjs/encoding"; import { isNonNullObject } from "@cosmjs/utils"; import axios, { AxiosError, AxiosInstance } from "axios"; @@ -147,8 +146,9 @@ export interface PostTxsResponse { readonly gas_used?: string; } -interface EncodeTxResponse { - // base64-encoded amino-binary encoded representation +/** A reponse from the /txs/encode endpoint */ +export interface EncodeTxResponse { + /** base64-encoded amino-binary encoded representation */ readonly tx: string; } @@ -289,12 +289,12 @@ export class RestClient { } /** returns the amino-encoding of the transaction performed by the server */ - public async encodeTx(tx: CosmosSdkTx): Promise { + public async encodeTx(tx: CosmosSdkTx): Promise { const responseData = await this.post("/txs/encode", tx); if (!responseData.tx) { throw new Error("Unexpected response data format"); } - return fromBase64((responseData as EncodeTxResponse).tx); + return responseData as EncodeTxResponse; } /** diff --git a/packages/sdk38/types/index.d.ts b/packages/sdk38/types/index.d.ts index 7a9de872..26f37186 100644 --- a/packages/sdk38/types/index.d.ts +++ b/packages/sdk38/types/index.d.ts @@ -22,6 +22,7 @@ export { AuthAccountsResponse, BlockResponse, BroadcastMode, + EncodeTxResponse, PostTxsResponse, NodeInfoResponse, RestClient, diff --git a/packages/sdk38/types/restclient.d.ts b/packages/sdk38/types/restclient.d.ts index d27863db..830457cb 100644 --- a/packages/sdk38/types/restclient.d.ts +++ b/packages/sdk38/types/restclient.d.ts @@ -125,6 +125,11 @@ export interface PostTxsResponse { /** The gas used by the execution */ readonly gas_used?: string; } +/** A reponse from the /txs/encode endpoint */ +export interface EncodeTxResponse { + /** base64-encoded amino-binary encoded representation */ + readonly tx: string; +} /** * The mode used to send transaction * @@ -162,7 +167,7 @@ export declare class RestClient { 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: CosmosSdkTx): Promise; /** * Broadcasts a signed transaction to into the transaction pool. * Depending on the RestClient's broadcast mode, this might or might