From d6cf1f9ae9f59a3d9b029c96fbba2d306fe25835 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Tue, 9 Jan 2024 12:25:45 -0500 Subject: [PATCH] add method to get recent txns (#202) --- connect/src/whscan-api.ts | 21 +++++++++++++++++++++ connect/src/wormhole.ts | 11 +++++++++++ 2 files changed, 32 insertions(+) diff --git a/connect/src/whscan-api.ts b/connect/src/whscan-api.ts index e823611a4..b7a444970 100644 --- a/connect/src/whscan-api.ts +++ b/connect/src/whscan-api.ts @@ -293,3 +293,24 @@ export async function getVaaByTxHashWithRetry { + const url = `${rpcUrl}/api/v1/transactions?address=${address}`; + try { + const response = await axios.get<{ transactions: TransactionStatus[] }>(url); + if (response.data.transactions.length > 0) return response.data.transactions; + } catch (error) { + if (!error) return null; + if (typeof error === "object") { + // A 404 error means the VAA is not yet available + // since its not available yet, we return null signaling it can be tried again + if (axios.isAxiosError(error) && error.response?.status === 404) return null; + if ("status" in error && error.status === 404) return null; + } + throw error; + } + return null; +} diff --git a/connect/src/wormhole.ts b/connect/src/wormhole.ts index 3a6c86c86..7a30c7957 100644 --- a/connect/src/wormhole.ts +++ b/connect/src/wormhole.ts @@ -31,6 +31,7 @@ import { retry } from "./tasks"; import { TransactionStatus, getTransactionStatusWithRetry, + getTxsByAddress, getVaaByTxHashWithRetry, getVaaBytesWithRetry, getVaaWithRetry, @@ -337,6 +338,16 @@ export class Wormhole { return getTransactionStatusWithRetry(this.config.api, wormholeMessageId, timeout); } + /** + * Get recent transactions for an address + * + * @param address the string formatted address to get transactions for + * @returns the TransactionStatus + */ + async getTransactionsForAddress(address: string): Promise { + return getTxsByAddress(this.config.api, address); + } + /** * Parse an address from its canonincal string format to a NativeAddress *