Add txIndex to DeliverTxResponse and IndexedTx

This commit is contained in:
Simon Warta 2023-03-06 14:14:13 +01:00
parent 2c1f779dbd
commit a5a8a06e9b
5 changed files with 24 additions and 2 deletions

View File

@ -45,8 +45,11 @@ and this project adheres to
- @cosmjs/cosmwasm-stargate: Add constructors `CosmWasmClient.create` and
`SigningCosmWasmClient.createWithSigner` to construct with a given Tendermint
client ([#1376]).
- @cosmjs/stargate: Add `txIndex` to `DeliverTxResponse` and `IndexedTx`
([#1361]).
[#1308]: https://github.com/cosmos/cosmjs/pull/1308
[#1361]: https://github.com/cosmos/cosmjs/issues/1361
[#1376]: https://github.com/cosmos/cosmjs/pull/1376
## [0.29.5] - 2022-12-07

View File

@ -35,6 +35,7 @@ interface TestTxSend {
readonly recipient: string;
readonly hash: string;
readonly height: number;
readonly txIndex: number;
readonly tx: Uint8Array;
}
@ -126,6 +127,7 @@ describe("CosmWasmClient.getTx and .searchTx", () => {
recipient: unsuccessfulRecipient,
hash: unsuccessfulResult.broadcastResponse.transactionHash,
height: unsuccessfulResult.broadcastResponse.height,
txIndex: unsuccessfulResult.broadcastResponse.txIndex,
tx: unsuccessfulResult.tx,
};
}
@ -143,6 +145,7 @@ describe("CosmWasmClient.getTx and .searchTx", () => {
recipient: successfulRecipient,
hash: successfulResult.broadcastResponse.transactionHash,
height: successfulResult.broadcastResponse.height,
txIndex: successfulResult.broadcastResponse.txIndex,
tx: successfulResult.tx,
};
}
@ -160,6 +163,7 @@ describe("CosmWasmClient.getTx and .searchTx", () => {
expect(result).toEqual(
jasmine.objectContaining({
height: sendSuccessful.height,
txIndex: sendSuccessful.txIndex,
hash: sendSuccessful.hash,
code: 0,
tx: sendSuccessful.tx,
@ -175,6 +179,7 @@ describe("CosmWasmClient.getTx and .searchTx", () => {
expect(result).toEqual(
jasmine.objectContaining({
height: sendUnsuccessful.height,
txIndex: sendUnsuccessful.txIndex,
hash: sendUnsuccessful.hash,
code: 5,
tx: sendUnsuccessful.tx,
@ -201,6 +206,7 @@ describe("CosmWasmClient.getTx and .searchTx", () => {
expect(result).toContain(
jasmine.objectContaining({
height: sendSuccessful.height,
txIndex: sendSuccessful.txIndex,
hash: sendSuccessful.hash,
code: 0,
tx: sendSuccessful.tx,
@ -217,6 +223,7 @@ describe("CosmWasmClient.getTx and .searchTx", () => {
expect(result).toContain(
jasmine.objectContaining({
height: sendUnsuccessful.height,
txIndex: sendUnsuccessful.txIndex,
hash: sendUnsuccessful.hash,
code: 5,
tx: sendUnsuccessful.tx,
@ -248,6 +255,7 @@ describe("CosmWasmClient.getTx and .searchTx", () => {
expect(results[results.length - 1]).toEqual(
jasmine.objectContaining({
height: sendSuccessful.height,
txIndex: sendSuccessful.txIndex,
hash: sendSuccessful.hash,
tx: sendSuccessful.tx,
}),

View File

@ -301,6 +301,7 @@ export class CosmWasmClient {
? {
code: result.code,
height: result.height,
txIndex: result.txIndex,
rawLog: result.rawLog,
transactionHash: txId,
events: result.events,
@ -481,6 +482,7 @@ export class CosmWasmClient {
return results.txs.map((tx) => {
return {
height: tx.height,
txIndex: tx.index,
hash: toHex(tx.hash).toUpperCase(),
code: tx.result.code,
events: tx.result.events.map(fromTendermintEvent),

View File

@ -16,6 +16,7 @@ import { ReadonlyDate } from "readonly-date";
import {
assertIsDeliverTxSuccess,
BroadcastTxError,
DeliverTxResponse,
isDeliverTxFailure,
isDeliverTxSuccess,
PrivateStargateClient,
@ -36,9 +37,10 @@ import {
validator,
} from "./testutils.spec";
const resultFailure = {
const resultFailure: DeliverTxResponse = {
code: 5,
height: 219901,
txIndex: 0,
rawLog:
"failed to execute message; message index: 0: 1855527000ufct is smaller than 20000000000000000000000ufct: insufficient funds",
transactionHash: "FDC4FB701AABD465935F7D04AE490D1EF5F2BD4B227601C4E98B57EB077D9B7D",
@ -46,9 +48,10 @@ const resultFailure = {
gasUsed: 54396,
gasWanted: 200000,
};
const resultSuccess = {
const resultSuccess: DeliverTxResponse = {
code: 0,
height: 219894,
txIndex: 0,
rawLog:
'[{"events":[{"type":"message","attributes":[{"key":"action","value":"send"},{"key":"sender","value":"firma1trqyle9m2nvyafc2n25frkpwed2504y6avgfzr"},{"key":"module","value":"bank"}]},{"type":"transfer","attributes":[{"key":"recipient","value":"firma12er8ls2sf5zess3jgjxz59xat9xtf8hz0hk6n4"},{"key":"sender","value":"firma1trqyle9m2nvyafc2n25frkpwed2504y6avgfzr"},{"key":"amount","value":"2000000ufct"}]}]}]',
transactionHash: "C0B416CA868C55C2B8C1BBB8F3CFA233854F13A5CB15D3E9599F50CAF7B3D161",

View File

@ -66,6 +66,8 @@ export interface Block {
/** A transaction that is indexed as part of the transaction history */
export interface IndexedTx {
readonly height: number;
/** The position of the transaction within the block. This is a 0-based index. */
readonly txIndex: number;
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly hash: string;
/** Transaction execution error code. 0 on success. */
@ -109,6 +111,8 @@ export interface SequenceResponse {
*/
export interface DeliverTxResponse {
readonly height: number;
/** The position of the transaction within the block. This is a 0-based index. */
readonly txIndex: number;
/** Error code. The transaction suceeded iff code is 0. */
readonly code: number;
readonly transactionHash: string;
@ -456,6 +460,7 @@ export class StargateClient {
? {
code: result.code,
height: result.height,
txIndex: result.txIndex,
events: result.events,
rawLog: result.rawLog,
transactionHash: txId,
@ -491,6 +496,7 @@ export class StargateClient {
return results.txs.map((tx) => {
return {
height: tx.height,
txIndex: tx.index,
hash: toHex(tx.hash).toUpperCase(),
code: tx.result.code,
events: tx.result.events.map(fromTendermintEvent),