Add CosmWasmClient.getIdentifier
This commit is contained in:
parent
3c59a68b3a
commit
331702638b
@ -3,6 +3,7 @@ import { makeSignBytes, marshalTx } from "./encoding";
|
||||
import { findAttribute } from "./logs";
|
||||
import { Secp256k1Pen } from "./pen";
|
||||
import { RestClient } from "./restclient";
|
||||
import cosmoshub from "./testdata/cosmoshub.json";
|
||||
import { getRandomizedHackatom, makeRandomAddress } from "./testutils.spec";
|
||||
import { Coin, MsgSend, StdFee } from "./types";
|
||||
|
||||
@ -59,6 +60,14 @@ describe("CosmWasmClient", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("getIdentifier", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutCosmos();
|
||||
const client = CosmWasmClient.makeReadOnly(httpUrl);
|
||||
expect(await client.getIdentifier(cosmoshub.tx)).toEqual(cosmoshub.id);
|
||||
});
|
||||
});
|
||||
|
||||
describe("postTx", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutCosmos();
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { Sha256 } from "@iov/crypto";
|
||||
import { Encoding } from "@iov/encoding";
|
||||
|
||||
import { makeSignBytes, marshalTx } from "./encoding";
|
||||
@ -5,6 +6,7 @@ import { findAttribute, Log, parseLogs } from "./logs";
|
||||
import { RestClient } from "./restclient";
|
||||
import {
|
||||
Coin,
|
||||
CosmosSdkTx,
|
||||
MsgExecuteContract,
|
||||
MsgInstantiateContract,
|
||||
MsgStoreCode,
|
||||
@ -106,6 +108,16 @@ export class CosmWasmClient {
|
||||
return response.node_info.network;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a 32 byte upper-case hex transaction hash (typically used as the transaction ID)
|
||||
*/
|
||||
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();
|
||||
return Encoding.toHex(hash).toUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns account number and sequence.
|
||||
*
|
||||
|
||||
6
packages/sdk/types/cosmwasmclient.d.ts
vendored
6
packages/sdk/types/cosmwasmclient.d.ts
vendored
@ -1,5 +1,5 @@
|
||||
import { Log } from "./logs";
|
||||
import { Coin, StdSignature } from "./types";
|
||||
import { Coin, CosmosSdkTx, StdSignature } from "./types";
|
||||
export interface SigningCallback {
|
||||
(signBytes: Uint8Array): Promise<StdSignature>;
|
||||
}
|
||||
@ -25,6 +25,10 @@ export declare class CosmWasmClient {
|
||||
private get signCallback();
|
||||
private constructor();
|
||||
chainId(): Promise<string>;
|
||||
/**
|
||||
* Returns a 32 byte upper-case hex transaction hash (typically used as the transaction ID)
|
||||
*/
|
||||
getIdentifier(tx: CosmosSdkTx): Promise<string>;
|
||||
/**
|
||||
* Returns account number and sequence.
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user