Let encodeTx return type EncodeTxResponse unprocessed
This commit is contained in:
parent
64673c6f21
commit
2728f25c36
@ -199,8 +199,8 @@ export class CosmWasmClient {
|
||||
*/
|
||||
public async getIdentifier(tx: CosmosSdkTx): Promise<string> {
|
||||
// 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();
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -181,8 +181,8 @@ export class CosmosClient {
|
||||
*/
|
||||
public async getIdentifier(tx: CosmosSdkTx): Promise<string> {
|
||||
// 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();
|
||||
}
|
||||
|
||||
|
||||
@ -24,6 +24,7 @@ export {
|
||||
AuthAccountsResponse,
|
||||
BlockResponse,
|
||||
BroadcastMode,
|
||||
EncodeTxResponse,
|
||||
PostTxsResponse,
|
||||
NodeInfoResponse,
|
||||
RestClient,
|
||||
|
||||
@ -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,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -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<Uint8Array> {
|
||||
public async encodeTx(tx: CosmosSdkTx): Promise<EncodeTxResponse> {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
1
packages/sdk38/types/index.d.ts
vendored
1
packages/sdk38/types/index.d.ts
vendored
@ -22,6 +22,7 @@ export {
|
||||
AuthAccountsResponse,
|
||||
BlockResponse,
|
||||
BroadcastMode,
|
||||
EncodeTxResponse,
|
||||
PostTxsResponse,
|
||||
NodeInfoResponse,
|
||||
RestClient,
|
||||
|
||||
7
packages/sdk38/types/restclient.d.ts
vendored
7
packages/sdk38/types/restclient.d.ts
vendored
@ -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<TxsResponse>;
|
||||
txsQuery(query: string): Promise<SearchTxsResponse>;
|
||||
/** returns the amino-encoding of the transaction performed by the server */
|
||||
encodeTx(tx: CosmosSdkTx): Promise<Uint8Array>;
|
||||
encodeTx(tx: CosmosSdkTx): Promise<EncodeTxResponse>;
|
||||
/**
|
||||
* Broadcasts a signed transaction to into the transaction pool.
|
||||
* Depending on the RestClient's broadcast mode, this might or might
|
||||
|
||||
Loading…
Reference in New Issue
Block a user