From c1e4159047b5f8c94f849b1018a6c8b83d392c51 Mon Sep 17 00:00:00 2001 From: ducphamle2 Date: Fri, 16 Aug 2024 17:07:08 -0700 Subject: [PATCH 1/2] add http timeout & more data decode tx resp --- packages/tendermint-rpc/src/rpcclients/http.ts | 6 +++++- .../tendermint-rpc/src/tendermint34/adaptor/responses.ts | 1 + .../tendermint-rpc/src/tendermint37/adaptor/responses.ts | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/tendermint-rpc/src/rpcclients/http.ts b/packages/tendermint-rpc/src/rpcclients/http.ts index 1d389504bd..48576b2182 100644 --- a/packages/tendermint-rpc/src/rpcclients/http.ts +++ b/packages/tendermint-rpc/src/rpcclients/http.ts @@ -40,9 +40,13 @@ export async function http( headers: Record | undefined, request?: any, ): Promise { + const timeout = Number( + process.env.HTTP_TIMEOUT || 30000, + ); if (typeof fetch === "function" && !isExperimental(fetch)) { const settings = { method: method, + signal: timeout, body: request ? JSON.stringify(request) : undefined, headers: { // eslint-disable-next-line @typescript-eslint/naming-convention @@ -55,7 +59,7 @@ export async function http( .then((res: any) => res.json()); } else { return axios - .request({ url: url, method: method, data: request, headers: headers }) + .request({ url: url, method: method, data: request, headers: headers, timeout }) .then((res) => res.data); } } diff --git a/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts b/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts index 48acab2aab..0614917a26 100644 --- a/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts +++ b/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts @@ -712,6 +712,7 @@ interface RpcTxResponse { function decodeTxResponse(data: RpcTxResponse): responses.TxResponse { return { + ...data, tx: fromBase64(assertNotEmpty(data.tx)), result: decodeTxData(assertObject(data.tx_result)), height: apiToSmallInt(assertNotEmpty(data.height)), diff --git a/packages/tendermint-rpc/src/tendermint37/adaptor/responses.ts b/packages/tendermint-rpc/src/tendermint37/adaptor/responses.ts index 3b1f10e3a4..12013615df 100644 --- a/packages/tendermint-rpc/src/tendermint37/adaptor/responses.ts +++ b/packages/tendermint-rpc/src/tendermint37/adaptor/responses.ts @@ -713,6 +713,7 @@ interface RpcTxResponse { function decodeTxResponse(data: RpcTxResponse): responses.TxResponse { return { + ...data, tx: fromBase64(assertNotEmpty(data.tx)), result: decodeTxData(assertObject(data.tx_result)), height: apiToSmallInt(assertNotEmpty(data.height)), From 8eda273141d86368c66aadad008aa8adf60f879e Mon Sep 17 00:00:00 2001 From: ducphamle2 Date: Fri, 16 Aug 2024 17:14:49 -0700 Subject: [PATCH 2/2] feat: also return more data from tx in searchTx --- packages/stargate/src/stargateclient.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/stargate/src/stargateclient.ts b/packages/stargate/src/stargateclient.ts index d5d6c6b334..12c6a6dd53 100644 --- a/packages/stargate/src/stargateclient.ts +++ b/packages/stargate/src/stargateclient.ts @@ -503,6 +503,7 @@ export class StargateClient { return results.txs.map((tx): IndexedTx => { const txMsgData = TxMsgData.decode(tx.result.data ?? new Uint8Array()); return { + ...tx, height: tx.height, txIndex: tx.index, hash: toHex(tx.hash).toUpperCase(),