Add format guarantee to PostTxResult.transactionHash

This commit is contained in:
Simon Warta 2020-02-11 16:41:02 +01:00
parent 90e76b7a41
commit 4c7124d12c
3 changed files with 9 additions and 1 deletions

View File

@ -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}$/);
});
});

View File

@ -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 || "",

View File

@ -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 {