Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk): Add event filter params to sdk as options #6332

5 changes: 5 additions & 0 deletions .changeset/violet-pants-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/sdk': minor
---

Added to and from block filters to several methods in CrossChainMessenger
61 changes: 50 additions & 11 deletions packages/sdk/src/cross-chain-messenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
TransactionReceipt,
TransactionResponse,
TransactionRequest,
Block,
} from '@ethersproject/abstract-provider'
import { Signer } from '@ethersproject/abstract-signer'
import {
Expand Down Expand Up @@ -659,10 +660,17 @@ export class CrossChainMessenger {
/**
* The index of the withdrawal if multiple are made with multicall
*/
messageIndex = 0
messageIndex = 0,
roninjin10 marked this conversation as resolved.
Show resolved Hide resolved
fromBlockOrBlockHash?: BlockTag,
toBlockOrBlockHash?: BlockTag
): Promise<MessageStatus> {
const resolved = await this.toCrossChainMessage(message, messageIndex)
const receipt = await this.getMessageReceipt(resolved, messageIndex)
const receipt = await this.getMessageReceipt(
resolved,
messageIndex,
fromBlockOrBlockHash,
toBlockOrBlockHash
)

if (resolved.direction === MessageDirection.L1_TO_L2) {
if (receipt === null) {
Expand Down Expand Up @@ -751,7 +759,9 @@ export class CrossChainMessenger {
/**
* The index of the withdrawal if multiple are made with multicall
*/
messageIndex = 0
messageIndex = 0,
fromBlockOrBlockHash?: BlockTag,
toBlockOrHash?: BlockTag
): Promise<MessageReceipt> {
const resolved = await this.toCrossChainMessage(message, messageIndex)
// legacy withdrawals relayed prebedrock are v1
Expand Down Expand Up @@ -783,10 +793,14 @@ export class CrossChainMessenger {
// this is safe because we can guarantee only one of these filters max will return something
const relayedMessageEvents = [
...(await messenger.queryFilter(
messenger.filters.RelayedMessage(messageHashV0)
messenger.filters.RelayedMessage(messageHashV0),
fromBlockOrBlockHash,
toBlockOrHash
)),
...(await messenger.queryFilter(
messenger.filters.RelayedMessage(messageHashV1)
messenger.filters.RelayedMessage(messageHashV1),
fromBlockOrBlockHash,
toBlockOrHash
)),
]

Expand All @@ -806,10 +820,14 @@ export class CrossChainMessenger {
// FailedRelayedMessage events instead.
const failedRelayedMessageEvents = [
...(await messenger.queryFilter(
messenger.filters.FailedRelayedMessage(messageHashV0)
messenger.filters.FailedRelayedMessage(messageHashV0),
fromBlockOrBlockHash,
toBlockOrHash
)),
...(await messenger.queryFilter(
messenger.filters.FailedRelayedMessage(messageHashV1)
messenger.filters.FailedRelayedMessage(messageHashV1),
fromBlockOrBlockHash,
toBlockOrHash
)),
]

Expand Down Expand Up @@ -852,6 +870,8 @@ export class CrossChainMessenger {
public async waitForMessageReceipt(
message: MessageLike,
opts: {
fromBlockOrBlockHash?: BlockTag
toBlockOrHash?: BlockTag
confirmations?: number
pollIntervalMs?: number
timeoutMs?: number
Expand All @@ -868,7 +888,12 @@ export class CrossChainMessenger {
let totalTimeMs = 0
while (totalTimeMs < (opts.timeoutMs || Infinity)) {
const tick = Date.now()
const receipt = await this.getMessageReceipt(resolved, messageIndex)
const receipt = await this.getMessageReceipt(
resolved,
messageIndex,
opts.fromBlockOrBlockHash,
opts.toBlockOrHash
)
if (receipt !== null) {
return receipt
} else {
Expand Down Expand Up @@ -896,6 +921,8 @@ export class CrossChainMessenger {
message: MessageLike,
status: MessageStatus,
opts: {
fromBlockOrBlockHash?: BlockTag
toBlockOrBlockHash?: BlockTag
pollIntervalMs?: number
timeoutMs?: number
} = {},
Expand All @@ -911,7 +938,12 @@ export class CrossChainMessenger {
let totalTimeMs = 0
while (totalTimeMs < (opts.timeoutMs || Infinity)) {
const tick = Date.now()
const currentStatus = await this.getMessageStatus(resolved, messageIndex)
const currentStatus = await this.getMessageStatus(
resolved,
messageIndex,
opts.fromBlockOrBlockHash,
opts.toBlockOrBlockHash
)

// Handle special cases for L1 to L2 messages.
if (resolved.direction === MessageDirection.L1_TO_L2) {
Expand Down Expand Up @@ -1026,10 +1058,17 @@ export class CrossChainMessenger {
/**
* The index of the withdrawal if multiple are made with multicall
*/
messageIndex = 0
messageIndex = 0,
roninjin10 marked this conversation as resolved.
Show resolved Hide resolved
fromBlockOrBlockHash?: BlockTag,
toBlockOrBlockHash?: BlockTag
): Promise<number> {
const resolved = await this.toCrossChainMessage(message, messageIndex)
const status = await this.getMessageStatus(resolved, messageIndex)
const status = await this.getMessageStatus(
resolved,
messageIndex,
fromBlockOrBlockHash,
toBlockOrBlockHash
)
if (resolved.direction === MessageDirection.L1_TO_L2) {
if (
status === MessageStatus.RELAYED ||
Expand Down