Skip to content

Commit 2401a12

Browse files
committed
wormholescan: update relays api method
this method was outdated and needed to be updated https://docs.wormholescan.io/#/wormholescan/find-relay-by-vaa-id
1 parent ab67523 commit 2401a12

File tree

2 files changed

+69
-44
lines changed

2 files changed

+69
-44
lines changed

connect/src/whscan-api.ts

+57-43
Original file line numberDiff line numberDiff line change
@@ -71,42 +71,51 @@ export interface TransactionStatus {
7171
};
7272
}
7373

74-
export interface RelayData {
75-
from: {
76-
chain: string;
77-
chainId: number;
78-
txHash: string;
79-
senderAddress: string;
80-
symbol: string;
81-
amountSent: number;
82-
amountToSwap: number;
83-
estimatedNativeAssetAmount: number;
84-
};
85-
vaa: string;
86-
status: string;
87-
fee: {
88-
amount: number;
89-
symbol: string;
90-
};
91-
error: any;
92-
to: {
93-
chain: string;
94-
chainId: number;
95-
recipientAddress: string;
96-
txHash: string;
97-
gasUsed: number;
98-
nativeAssetSymbol: string;
99-
nativeAssetReceived: number;
100-
};
101-
metrics: {
102-
receivedAt: string;
103-
completedAt: string;
104-
failedAt: any;
105-
attempts: number;
74+
export interface RelayStatus {
75+
completedAt: string;
76+
data: {
77+
delivery: {
78+
budget: string;
79+
execution: {
80+
detail: string;
81+
gasUsed: string;
82+
refundStatus: string;
83+
revertString: string;
84+
status: string;
85+
transactionHash: string;
86+
};
87+
maxRefund: string;
88+
relayGasUsed: number;
89+
targetChainDecimals: number;
90+
};
91+
fromTxHash: string;
92+
instructions: {
93+
encodedExecutionInfo: string;
94+
extraReceiverValue: {
95+
_hex: string;
96+
_isBigNumber: boolean;
97+
};
98+
refundAddress: string;
99+
refundChainId: number;
100+
refundDeliveryProvider: string;
101+
requestedReceiverValue: {
102+
_hex: string;
103+
_isBigNumber: boolean;
104+
};
105+
senderAddress: string;
106+
sourceDeliveryProvider: string;
107+
targetAddress: string;
108+
targetChainId: number;
109+
vaaKeys: string[];
110+
};
106111
maxAttempts: number;
107-
waitingForTxInMs: number;
108-
waitingForWalletInMs: number;
112+
toTxHash: string;
109113
};
114+
failedAt: string;
115+
id: string;
116+
receivedAt: string;
117+
relayer: string;
118+
status: string;
110119
}
111120

112121
export interface ApiVaa {
@@ -235,11 +244,17 @@ export async function getTransactionStatusWithRetry(
235244
);
236245
}
237246

238-
export async function getRelayStatus(rpcUrl: string, txid: TxHash): Promise<RelayData | null> {
239-
const url = `${rpcUrl}/v1/relays?txHash=${txid}`;
247+
export async function getRelayStatus(
248+
rpcUrl: string,
249+
whm: WormholeMessageId,
250+
): Promise<RelayStatus | null> {
251+
const { chain, emitter, sequence } = whm;
252+
const chainId = toChainId(chain);
253+
const emitterAddress = emitter.toUniversalAddress().toString();
254+
const url = `${rpcUrl}/api/v1/relays/${chainId}/${emitterAddress}/${sequence}`;
240255
try {
241-
const response = await axios.get<{ data: RelayData }>(url);
242-
if (response.data.data.to.txHash) return response.data.data;
256+
const response = await axios.get<RelayStatus>(url);
257+
return response.data || null;
243258
} catch (error) {
244259
if (!error) return null;
245260
if (typeof error === "object") {
@@ -250,16 +265,15 @@ export async function getRelayStatus(rpcUrl: string, txid: TxHash): Promise<Rela
250265
}
251266
throw error;
252267
}
253-
return null;
254268
}
255269

256270
export async function getRelayStatusWithRetry(
257271
rpcUrl: string,
258-
txid: TxHash,
272+
whm: WormholeMessageId,
259273
timeout: number,
260-
): Promise<RelayData | null> {
261-
const task = () => getRelayStatus(rpcUrl, txid);
262-
return retry<RelayData>(task, WHSCAN_RETRY_INTERVAL, timeout, "Wormholescan:GetRelayStatus");
274+
): Promise<RelayStatus | null> {
275+
const task = () => getRelayStatus(rpcUrl, whm);
276+
return retry<RelayStatus>(task, WHSCAN_RETRY_INTERVAL, timeout, "Wormholescan:GetRelayStatus");
263277
}
264278

265279
export async function getVaaByTxHash(rpcUrl: string, txid: string): Promise<ApiVaa | null> {

connect/src/wormhole.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ import { TokenTransfer } from "./protocols/tokenBridge/tokenTransfer.js";
3131
import type { RouteConstructor } from "./routes/index.js";
3232
import { RouteResolver } from "./routes/resolver.js";
3333
import { retry } from "./tasks.js";
34-
import type { TransactionStatus } from "./whscan-api.js";
34+
import type { RelayStatus, TransactionStatus } from "./whscan-api.js";
3535
import {
3636
getIsVaaEnqueued,
37+
getRelayStatus,
3738
getTransactionStatusWithRetry,
3839
getTxsByAddress,
3940
getVaaByTxHashWithRetry,
@@ -333,6 +334,16 @@ export class Wormhole<N extends Network> {
333334
return await getVaaWithRetry(this.config.api, id, decodeAs, timeout);
334335
}
335336

337+
/**
338+
* Gets the RelayStatus for a given WormholeMessageId
339+
*
340+
* @param wormholeMessageId The WormholeMessageId corresponding to the relay status to be fetched
341+
* @returns The RelayStatus if available otherwise null
342+
*/
343+
async getRelayStatus(wormholeMessageId: WormholeMessageId): Promise<RelayStatus | null> {
344+
return await getRelayStatus(this.config.api, wormholeMessageId);
345+
}
346+
336347
/**
337348
* Gets if the token bridge transfer VAA has been enqueued by the Governor.
338349
* @param id The WormholeMessageId corresponding to the token bridge transfer VAA to check

0 commit comments

Comments
 (0)