From 4b323473f3d8a6489c15950fc1c4cf8048ea662c Mon Sep 17 00:00:00 2001 From: J M Rossy Date: Tue, 8 Nov 2022 14:11:06 -0500 Subject: [PATCH] Fix type of leafIndex returned by getDispatchedMessages (#1239) Co-authored-by: Yorke Rhodes --- typescript/sdk/src/core/HyperlaneCore.ts | 31 ++++++++++++------------ typescript/sdk/src/core/events.ts | 1 + 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/typescript/sdk/src/core/HyperlaneCore.ts b/typescript/sdk/src/core/HyperlaneCore.ts index cfa66e6f9..bbabae86c 100644 --- a/typescript/sdk/src/core/HyperlaneCore.ts +++ b/typescript/sdk/src/core/HyperlaneCore.ts @@ -1,4 +1,4 @@ -import { ethers } from 'ethers'; +import { BigNumber, ethers } from 'ethers'; import { Inbox, Outbox, Outbox__factory } from '@hyperlane-xyz/core'; import { types, utils } from '@hyperlane-xyz/utils'; @@ -157,23 +157,23 @@ export class HyperlaneCore< getDispatchedMessages(sourceTx: ethers.ContractReceipt): DispatchedMessage[] { const outbox = Outbox__factory.createInterface(); - const describedLogs = sourceTx.logs.map((log) => { - try { - return outbox.parseLog(log); - } catch (e) { - return undefined; - } - }); - const dispatchLogs = describedLogs.filter( - (log) => log && log.name === 'Dispatch', - ) as ethers.utils.LogDescription[]; - if (dispatchLogs.length === 0) { - throw new Error('Dispatch logs not found'); - } + const dispatchLogs = sourceTx.logs + .map((log) => { + try { + return outbox.parseLog(log); + } catch (e) { + return undefined; + } + }) + .filter( + (log): log is ethers.utils.LogDescription => + !!log && log.name === 'Dispatch', + ); return dispatchLogs.map((log) => { const message = log.args['message']; + const leafIndex = BigNumber.from(log.args['leafIndex']).toNumber(); const parsed = utils.parseMessage(message); - return { leafIndex: log.args['leafIndex'], message, parsed }; + return { leafIndex, message, parsed }; }); } @@ -181,7 +181,6 @@ export class HyperlaneCore< sourceTx: ethers.ContractReceipt, ): Promise { const messages = this.getDispatchedMessages(sourceTx); - return Promise.all(messages.map((msg) => this.waitForProcessReceipt(msg))); } } diff --git a/typescript/sdk/src/core/events.ts b/typescript/sdk/src/core/events.ts index a5a893fcd..180e7030c 100644 --- a/typescript/sdk/src/core/events.ts +++ b/typescript/sdk/src/core/events.ts @@ -1,3 +1,4 @@ +// TODO get these exported from core package's index.ts import type { ProcessEvent } from '@hyperlane-xyz/core/dist/contracts/Inbox'; import type { DispatchEvent } from '@hyperlane-xyz/core/dist/contracts/Outbox';