Skip to content

Commit fd96ef0

Browse files
authored
Merge pull request #103 from hyperweb-io/fix-get-tx
fix tx response msg
2 parents cd2022e + 3e598c9 commit fd96ef0

File tree

1 file changed

+82
-83
lines changed
  • networks/cosmos/src/query

1 file changed

+82
-83
lines changed

networks/cosmos/src/query/rpc.ts

+82-83
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { broadcast, createQueryRpc, getPrefix, sleep } from '@interchainjs/utils
3232
import { isBaseAccount } from '../utils';
3333
import { QueryAccountRequest, QueryAccountResponse } from '@interchainjs/cosmos-types/cosmos/auth/v1beta1/query';
3434
import { SimulateRequest, SimulateResponse } from '@interchainjs/cosmos-types/cosmos/tx/v1beta1/service';
35+
import { TxMsgData } from '@interchainjs/cosmos-types/cosmos/base/abci/v1beta1/abci';
3536

3637
/**
3738
* client for cosmos rpc
@@ -173,8 +174,7 @@ export class RpcClient implements QueryClient {
173174
const json = await data.json();
174175
const tx: TxResponse = json['result'];
175176
if (!tx) return null;
176-
const txRaw = TxRaw.decode(fromBase64(tx.tx));
177-
const txBody = TxBody.decode(txRaw.bodyBytes);
177+
const txMsgData = TxMsgData.decode(fromBase64(tx.tx_result.data) ?? new Uint8Array());
178178
return {
179179
height: tx.height,
180180
txIndex: tx.index,
@@ -183,7 +183,7 @@ export class RpcClient implements QueryClient {
183183
events: tx.tx_result.events,
184184
rawLog: tx.tx_result.log,
185185
tx: fromBase64(tx.tx),
186-
msgResponses: txBody.messages,
186+
msgResponses: txMsgData.msgResponses,
187187
gasUsed: BigInt(tx.tx_result.gas_used),
188188
gasWanted: BigInt(tx.tx_result.gas_wanted),
189189
data: tx.tx_result.data,
@@ -229,93 +229,92 @@ export class RpcClient implements QueryClient {
229229
);
230230

231231
switch (mode) {
232-
case 'broadcast_tx_async':
233-
const { hash: hash1, ...rest1 } = resp as AsyncCometBroadcastResponse;
234-
return {
235-
hash: hash1,
236-
add_tx: rest1,
237-
origin: resp
238-
};
239-
case 'broadcast_tx_sync':
240-
const { hash: hash2, ...rest2 } = resp as SyncCometBroadcastResponse;
241-
return {
242-
hash: hash2,
243-
check_tx: rest2,
244-
origin: resp
245-
};
246-
case 'broadcast_tx_commit':
247-
if (useLegacyBroadcastTxCommit) {
248-
const {
249-
check_tx,
250-
deliver_tx,
251-
height,
252-
hash: hash3,
253-
} = resp as CommitCometBroadcastResponse;
254-
232+
case 'broadcast_tx_async':
233+
const { hash: hash1, ...rest1 } = resp as AsyncCometBroadcastResponse;
234+
return {
235+
hash: hash1,
236+
add_tx: rest1,
237+
origin: resp
238+
};
239+
case 'broadcast_tx_sync':
240+
const { hash: hash2, ...rest2 } = resp as SyncCometBroadcastResponse;
255241
return {
256-
hash: hash3,
257-
check_tx,
258-
deliver_tx: { height, ...deliver_tx },
259-
origin: {hash: hash3, height, ...deliver_tx }
242+
hash: hash2,
243+
check_tx: rest2,
244+
origin: resp
260245
};
261-
} else {
262-
let timedOut = false;
263-
const txPollTimeout = setTimeout(() => {
264-
timedOut = true;
265-
}, timeoutMs);
246+
case 'broadcast_tx_commit':
247+
if (useLegacyBroadcastTxCommit) {
248+
const {
249+
check_tx,
250+
deliver_tx,
251+
height,
252+
hash: hash3,
253+
} = resp as CommitCometBroadcastResponse;
266254

267-
const pollForTx = async (
268-
txId: string
269-
): Promise<BroadcastResponse> => {
270-
if (timedOut) {
271-
throw new TimeoutError(
272-
`Transaction with ID ${txId} was submitted but was not yet found on the chain. You might want to check later. There was a wait of ${
273-
timeoutMs / 1000
274-
} seconds.`,
275-
txId
276-
);
277-
}
278-
await sleep(pollIntervalMs);
279-
const result = await this.getTx(txId);
255+
return {
256+
hash: hash3,
257+
check_tx,
258+
deliver_tx: { height, ...deliver_tx },
259+
origin: { hash: hash3, height, ...deliver_tx }
260+
};
261+
} else {
262+
let timedOut = false;
263+
const txPollTimeout = setTimeout(() => {
264+
timedOut = true;
265+
}, timeoutMs);
280266

281-
return result
282-
? {
283-
hash: resp.hash,
284-
deliver_tx: {
285-
code: result.code,
286-
height: result.height.toString(),
287-
txIndex: result.txIndex,
288-
events: result.events,
289-
rawLog: result.rawLog,
290-
msgResponses: result.msgResponses,
291-
gas_used: result.gasUsed.toString(),
292-
gas_wanted: result.gasWanted.toString(),
293-
data: result.data,
294-
log: result.log,
295-
info: result.info,
296-
},
297-
origin: result
267+
const pollForTx = async (
268+
txId: string
269+
): Promise<BroadcastResponse> => {
270+
if (timedOut) {
271+
throw new TimeoutError(
272+
`Transaction with ID ${txId} was submitted but was not yet found on the chain. You might want to check later. There was a wait of ${timeoutMs / 1000
273+
} seconds.`,
274+
txId
275+
);
298276
}
299-
: pollForTx(txId);
300-
};
277+
await sleep(pollIntervalMs);
278+
const result = await this.getTx(txId);
301279

302-
const transactionId = resp.hash.toUpperCase();
280+
return result
281+
? {
282+
hash: resp.hash,
283+
deliver_tx: {
284+
code: result.code,
285+
height: result.height.toString(),
286+
txIndex: result.txIndex,
287+
events: result.events,
288+
rawLog: result.rawLog,
289+
msgResponses: result.msgResponses,
290+
gas_used: result.gasUsed.toString(),
291+
gas_wanted: result.gasWanted.toString(),
292+
data: result.data,
293+
log: result.log,
294+
info: result.info,
295+
},
296+
origin: result
297+
}
298+
: pollForTx(txId);
299+
};
303300

304-
return new Promise((resolve, reject) =>
305-
pollForTx(transactionId).then(
306-
(value) => {
307-
clearTimeout(txPollTimeout);
308-
resolve(value);
309-
},
310-
(error) => {
311-
clearTimeout(txPollTimeout);
312-
reject(error);
313-
}
314-
)
315-
);
316-
}
317-
default:
318-
throw new Error(`Wrong method: ${mode}`);
301+
const transactionId = resp.hash.toUpperCase();
302+
303+
return new Promise((resolve, reject) =>
304+
pollForTx(transactionId).then(
305+
(value) => {
306+
clearTimeout(txPollTimeout);
307+
resolve(value);
308+
},
309+
(error) => {
310+
clearTimeout(txPollTimeout);
311+
reject(error);
312+
}
313+
)
314+
);
315+
}
316+
default:
317+
throw new Error(`Wrong method: ${mode}`);
319318
}
320319
}
321320
}

0 commit comments

Comments
 (0)