Skip to content

Commit

Permalink
add method to get recent txns (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin authored Jan 9, 2024
1 parent ce2596b commit d6cf1f9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
21 changes: 21 additions & 0 deletions connect/src/whscan-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,24 @@ export async function getVaaByTxHashWithRetry<T extends PayloadLiteral | Payload

return deserialize(decodeAs, encoding.b64.decode(vaa.vaa));
}

export async function getTxsByAddress(
rpcUrl: string,
address: string,
): Promise<TransactionStatus[] | null> {
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;
}
11 changes: 11 additions & 0 deletions connect/src/wormhole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { retry } from "./tasks";
import {
TransactionStatus,
getTransactionStatusWithRetry,
getTxsByAddress,
getVaaByTxHashWithRetry,
getVaaBytesWithRetry,
getVaaWithRetry,
Expand Down Expand Up @@ -337,6 +338,16 @@ export class Wormhole<N extends Network> {
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<TransactionStatus[] | null> {
return getTxsByAddress(this.config.api, address);
}

/**
* Parse an address from its canonincal string format to a NativeAddress
*
Expand Down

0 comments on commit d6cf1f9

Please sign in to comment.