stargate: Return gas used

This commit is contained in:
willclarktech 2021-04-14 12:53:31 +02:00
parent b25171cfef
commit a98c310e83
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
2 changed files with 12 additions and 7 deletions

View File

@ -332,7 +332,8 @@ describe("StargateClient", () => {
const txResult = await client.broadcastTx(txRawBytes);
assertIsBroadcastTxSuccess(txResult);
const { rawLog, transactionHash } = txResult;
const { gasUsed, rawLog, transactionHash } = txResult;
expect(gasUsed).toBeGreaterThan(0);
expect(rawLog).toMatch(/{"key":"amount","value":"1234567ucosm"}/);
expect(transactionHash).toMatch(/^[0-9A-F]{64}$/);

View File

@ -1,11 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { toHex } from "@cosmjs/encoding";
import { Uint53 } from "@cosmjs/math";
import {
BroadcastTxSyncResponse,
Tendermint34Client,
toRfc3339WithNanoseconds,
} from "@cosmjs/tendermint-rpc";
import { Tendermint34Client, toRfc3339WithNanoseconds } from "@cosmjs/tendermint-rpc";
import { sleep } from "@cosmjs/utils";
import { Account, accountFromAny } from "./accounts";
@ -63,6 +59,8 @@ export interface IndexedTx {
readonly code: number;
readonly rawLog: string;
readonly tx: Uint8Array;
readonly gasUsed: number;
readonly gasWanted: number;
}
export interface SequenceResponse {
@ -83,6 +81,8 @@ export interface BroadcastTxSuccess {
readonly transactionHash: string;
readonly rawLog?: string;
readonly data?: readonly MsgData[];
readonly gasUsed: number;
readonly gasWanted: number;
}
export type BroadcastTxResponse = BroadcastTxSuccess | BroadcastTxFailure;
@ -303,6 +303,8 @@ export class StargateClient {
height: result.height,
rawLog: result.rawLog,
transactionHash: txId,
gasUsed: result.gasUsed,
gasWanted: result.gasWanted,
}
: pollForTx(txId);
};
@ -310,7 +312,7 @@ export class StargateClient {
return new Promise((resolve, reject) =>
this.forceGetTmClient()
.broadcastTxSync({ tx })
.then(({ hash }: BroadcastTxSyncResponse) => pollForTx(toHex(hash).toUpperCase()))
.then(({ hash }) => pollForTx(toHex(hash).toUpperCase()))
.then(resolve, reject)
.finally(() => clearTimeout(txPollTimeout)),
);
@ -325,6 +327,8 @@ export class StargateClient {
code: tx.result.code,
rawLog: tx.result.log || "",
tx: tx.tx,
gasUsed: tx.result.gasUsed,
gasWanted: tx.result.gasWanted,
};
});
}