Add format guarantee to PostTxResult.transactionHash
This commit is contained in:
parent
90e76b7a41
commit
4c7124d12c
@ -102,9 +102,10 @@ describe("CosmWasmClient", () => {
|
||||
memo: memo,
|
||||
signatures: [signature],
|
||||
};
|
||||
const { logs } = await client.postTx(marshalTx(signedTx));
|
||||
const { logs, transactionHash } = await client.postTx(marshalTx(signedTx));
|
||||
const amountAttr = findAttribute(logs, "transfer", "amount");
|
||||
expect(amountAttr.value).toEqual("1234567ucosm");
|
||||
expect(transactionHash).toMatch(/^[0-9A-F]{64}$/);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -59,6 +59,7 @@ export interface GetNonceResult {
|
||||
export interface PostTxResult {
|
||||
readonly logs: readonly Log[];
|
||||
readonly rawLog: string;
|
||||
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-exmpty upper-case hex */
|
||||
readonly transactionHash: string;
|
||||
}
|
||||
|
||||
@ -123,6 +124,11 @@ export class CosmWasmClient {
|
||||
if (result.code) {
|
||||
throw new Error(`Error when posting tx. Code: ${result.code}; Raw log: ${result.raw_log}`);
|
||||
}
|
||||
|
||||
if (!result.txhash.match(/^([0-9A-F][0-9A-F])+$/)) {
|
||||
throw new Error("Received ill-formatted txhash. Must be non-empty upper-case hex");
|
||||
}
|
||||
|
||||
return {
|
||||
logs: parseLogs(result.logs) || [],
|
||||
rawLog: result.raw_log || "",
|
||||
|
||||
1
packages/sdk/types/cosmwasmclient.d.ts
vendored
1
packages/sdk/types/cosmwasmclient.d.ts
vendored
@ -10,6 +10,7 @@ export interface GetNonceResult {
|
||||
export interface PostTxResult {
|
||||
readonly logs: readonly Log[];
|
||||
readonly rawLog: string;
|
||||
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-exmpty upper-case hex */
|
||||
readonly transactionHash: string;
|
||||
}
|
||||
export interface ExecuteResult {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user