From 1c6bb1c96e6732bd7252336f5ed6e166d7cdc211 Mon Sep 17 00:00:00 2001 From: ducphamle2 Date: Fri, 16 Aug 2024 16:42:45 -0700 Subject: [PATCH] feat: add http timeout & allow more data return tx resp --- packages/tendermint-rpc/src/rpcclients/http.ts | 7 ++++++- .../tendermint-rpc/src/tendermint34/adaptor/responses.ts | 1 + .../tendermint-rpc/src/tendermint37/adaptor/responses.ts | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/tendermint-rpc/src/rpcclients/http.ts b/packages/tendermint-rpc/src/rpcclients/http.ts index 1d389504bd..0bc9849afe 100644 --- a/packages/tendermint-rpc/src/rpcclients/http.ts +++ b/packages/tendermint-rpc/src/rpcclients/http.ts @@ -40,9 +40,14 @@ export async function http( headers: Record | undefined, request?: any, ): Promise { + const timeout = Number( + //@ts-ignore + 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 +60,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 bc8d2051b3..2bbd3d1d0a 100644 --- a/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts +++ b/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts @@ -723,6 +723,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 8db6e3cb38..c694550259 100644 --- a/packages/tendermint-rpc/src/tendermint37/adaptor/responses.ts +++ b/packages/tendermint-rpc/src/tendermint37/adaptor/responses.ts @@ -724,6 +724,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)),