Fix type of leafIndex returned by getDispatchedMessages (#1239)

Co-authored-by: Yorke Rhodes <yorke@hyperlane.xyz>
nambrot/loop-with-sleep
J M Rossy 2 years ago committed by GitHub
parent 520f509a2e
commit 4b323473f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      typescript/sdk/src/core/HyperlaneCore.ts
  2. 1
      typescript/sdk/src/core/events.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<ethers.ContractReceipt[]> {
const messages = this.getDispatchedMessages(sourceTx);
return Promise.all(messages.map((msg) => this.waitForProcessReceipt(msg)));
}
}

@ -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';

Loading…
Cancel
Save