Skip to content

Commit

Permalink
linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Cory authored and Will Cory committed Jun 29, 2023
1 parent 40994ef commit 186b1d1
Showing 1 changed file with 35 additions and 109 deletions.
144 changes: 35 additions & 109 deletions packages/sdk/src/cross-chain-messenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,7 @@ export class CrossChainMessenger {
*/
messageIndex = 0
): Promise<CrossChainMessage> {
const resolved = await this.toCrossChainMessage(
message,
messageIndex
)
const resolved = await this.toCrossChainMessage(message, messageIndex)

// Bedrock messages are already in the correct format.
const { version } = decodeVersionedNonce(resolved.messageNonce)
Expand Down Expand Up @@ -374,7 +371,9 @@ export class CrossChainMessenger {
}
}

private async getWithdrawalsFromMessage(message: MessageLike): Promise<ethers.utils.Result[]> {
private async getWithdrawalsFromMessage(
message: MessageLike
): Promise<ethers.utils.Result[]> {
const resolved = await this.toCrossChainMessage(message)
const receipt = await this.l2Provider.getTransactionReceipt(
resolved.transactionHash
Expand Down Expand Up @@ -407,10 +406,7 @@ export class CrossChainMessenger {
*/
messageIndex = 0
): Promise<LowLevelMessage> {
const resolved = await this.toCrossChainMessage(
message,
messageIndex
)
const resolved = await this.toCrossChainMessage(message, messageIndex)
if (resolved.direction === MessageDirection.L1_TO_L2) {
throw new Error(`can only convert L2 to L1 messages to low level`)
}
Expand All @@ -419,10 +415,7 @@ export class CrossChainMessenger {
const { version } = decodeVersionedNonce(resolved.messageNonce)
let updated: CrossChainMessage
if (version.eq(0)) {
updated = await this.toBedrockCrossChainMessage(
resolved,
messageIndex
)
updated = await this.toBedrockCrossChainMessage(resolved, messageIndex)
} else {
updated = resolved
}
Expand Down Expand Up @@ -672,10 +665,7 @@ export class CrossChainMessenger {
*/
messageIndex = 0
): Promise<MessageStatus> {
const resolved = await this.toCrossChainMessage(
message,
messageIndex
)
const resolved = await this.toCrossChainMessage(message, messageIndex)
const receipt = await this.getMessageReceipt(resolved, messageIndex)

if (resolved.direction === MessageDirection.L1_TO_L2) {
Expand Down Expand Up @@ -767,10 +757,7 @@ export class CrossChainMessenger {
*/
messageIndex = 0
): Promise<MessageReceipt> {
const resolved = await this.toCrossChainMessage(
message,
messageIndex
)
const resolved = await this.toCrossChainMessage(message, messageIndex)
// legacy withdrawals relayed prebedrock are v1
const messageHashV0 = hashCrossDomainMessagev0(
resolved.target,
Expand Down Expand Up @@ -880,18 +867,12 @@ export class CrossChainMessenger {
messageIndex = 0
): Promise<MessageReceipt> {
// Resolving once up-front is slightly more efficient.
const resolved = await this.toCrossChainMessage(
message,
messageIndex
)
const resolved = await this.toCrossChainMessage(message, messageIndex)

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)
if (receipt !== null) {
return receipt
} else {
Expand Down Expand Up @@ -929,18 +910,12 @@ export class CrossChainMessenger {
messageIndex = 0
): Promise<void> {
// Resolving once up-front is slightly more efficient.
const resolved = await this.toCrossChainMessage(
message,
messageIndex
)
const resolved = await this.toCrossChainMessage(message, messageIndex)

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)

// Handle special cases for L1 to L2 messages.
if (resolved.direction === MessageDirection.L1_TO_L2) {
Expand Down Expand Up @@ -1057,10 +1032,7 @@ export class CrossChainMessenger {
*/
messageIndex = 0
): Promise<number> {
const resolved = await this.toCrossChainMessage(
message,
messageIndex
)
const resolved = await this.toCrossChainMessage(message, messageIndex)
const status = await this.getMessageStatus(resolved, messageIndex)
if (resolved.direction === MessageDirection.L1_TO_L2) {
if (
Expand Down Expand Up @@ -1099,10 +1071,7 @@ export class CrossChainMessenger {
// If the message is still within the challenge period, then we need to estimate exactly
// the amount of time left until the challenge period expires. The challenge period starts
// when the state root is published.
const stateRoot = await this.getMessageStateRoot(
resolved,
messageIndex
)
const stateRoot = await this.getMessageStateRoot(resolved, messageIndex)
const challengePeriod = await this.getChallengePeriodSeconds()
const targetBlock = await this.l1Provider.getBlock(
stateRoot.batch.blockNumber
Expand Down Expand Up @@ -1135,13 +1104,13 @@ export class CrossChainMessenger {
const challengePeriod =
oracleVersion === '1.0.0'
? // The ABI in the SDK does not contain FINALIZATION_PERIOD_SECONDS
// in OptimismPortal, so making an explicit call instead.
BigNumber.from(
await this.contracts.l1.OptimismPortal.provider.call({
to: this.contracts.l1.OptimismPortal.address,
data: '0xf4daa291', // FINALIZATION_PERIOD_SECONDS
})
)
// in OptimismPortal, so making an explicit call instead.
BigNumber.from(
await this.contracts.l1.OptimismPortal.provider.call({
to: this.contracts.l1.OptimismPortal.address,
data: '0xf4daa291', // FINALIZATION_PERIOD_SECONDS
})
)
: await this.contracts.l1.L2OutputOracle.FINALIZATION_PERIOD_SECONDS()
return challengePeriod.toNumber()
}
Expand Down Expand Up @@ -1179,10 +1148,7 @@ export class CrossChainMessenger {
*/
messageIndex = 0
): Promise<BedrockOutputData | null> {
const resolved = await this.toCrossChainMessage(
message,
messageIndex
)
const resolved = await this.toCrossChainMessage(message, messageIndex)

// Outputs are only a thing for L2 to L1 messages.
if (resolved.direction === MessageDirection.L1_TO_L2) {
Expand Down Expand Up @@ -1238,10 +1204,7 @@ export class CrossChainMessenger {
*/
messageIndex = 0
): Promise<StateRoot | null> {
const resolved = await this.toCrossChainMessage(
message,
messageIndex
)
const resolved = await this.toCrossChainMessage(message, messageIndex)

// State roots are only a thing for L2 to L1 messages.
if (resolved.direction === MessageDirection.L1_TO_L2) {
Expand Down Expand Up @@ -1431,18 +1394,12 @@ export class CrossChainMessenger {
*/
messageIndex = 0
): Promise<CrossChainMessageProof> {
const resolved = await this.toCrossChainMessage(
message,
messageIndex
)
const resolved = await this.toCrossChainMessage(message, messageIndex)
if (resolved.direction === MessageDirection.L1_TO_L2) {
throw new Error(`can only generate proofs for L2 to L1 messages`)
}

const stateRoot = await this.getMessageStateRoot(
resolved,
messageIndex
)
const stateRoot = await this.getMessageStateRoot(resolved, messageIndex)
if (stateRoot === null) {
throw new Error(`state root for message not yet published`)
}
Expand Down Expand Up @@ -1500,26 +1457,17 @@ export class CrossChainMessenger {
*/
messageIndex = 0
): Promise<BedrockCrossChainMessageProof> {
const resolved = await this.toCrossChainMessage(
message,
messageIndex
)
const resolved = await this.toCrossChainMessage(message, messageIndex)
if (resolved.direction === MessageDirection.L1_TO_L2) {
throw new Error(`can only generate proofs for L2 to L1 messages`)
}

const output = await this.getMessageBedrockOutput(
resolved,
messageIndex
)
const output = await this.getMessageBedrockOutput(resolved, messageIndex)
if (output === null) {
throw new Error(`state root for message not yet published`)
}

const withdrawal = await this.toLowLevelMessage(
resolved,
messageIndex
)
const withdrawal = await this.toLowLevelMessage(resolved, messageIndex)
const hash = hashLowLevelMessage(withdrawal)
const messageSlot = hashMessageHash(hash)

Expand Down Expand Up @@ -1872,10 +1820,7 @@ export class CrossChainMessenger {
*/
messageIndex = 0
): Promise<TransactionRequest> => {
const resolved = await this.toCrossChainMessage(
message,
messageIndex
)
const resolved = await this.toCrossChainMessage(message, messageIndex)
if (resolved.direction === MessageDirection.L2_TO_L1) {
throw new Error(`cannot resend L2 to L1 message`)
}
Expand Down Expand Up @@ -1926,10 +1871,7 @@ export class CrossChainMessenger {
*/
messageIndex = 0
): Promise<TransactionRequest> => {
const resolved = await this.toCrossChainMessage(
message,
messageIndex
)
const resolved = await this.toCrossChainMessage(message, messageIndex)
if (resolved.direction === MessageDirection.L1_TO_L2) {
throw new Error('cannot finalize L1 to L2 message')
}
Expand All @@ -1940,14 +1882,8 @@ export class CrossChainMessenger {
)
}

const withdrawal = await this.toLowLevelMessage(
resolved,
messageIndex
)
const proof = await this.getBedrockMessageProof(
resolved,
messageIndex
)
const withdrawal = await this.toLowLevelMessage(resolved, messageIndex)
const proof = await this.getBedrockMessageProof(resolved, messageIndex)

const args = [
[
Expand Down Expand Up @@ -1995,19 +1931,13 @@ export class CrossChainMessenger {
*/
messageIndex = 0
): Promise<TransactionRequest> => {
const resolved = await this.toCrossChainMessage(
message,
messageIndex
)
const resolved = await this.toCrossChainMessage(message, messageIndex)
if (resolved.direction === MessageDirection.L1_TO_L2) {
throw new Error(`cannot finalize L1 to L2 message`)
}

if (this.bedrock) {
const withdrawal = await this.toLowLevelMessage(
resolved,
messageIndex
)
const withdrawal = await this.toLowLevelMessage(resolved, messageIndex)
return this.contracts.l1.OptimismPortal.populateTransaction.finalizeWithdrawalTransaction(
[
withdrawal.messageNonce,
Expand Down Expand Up @@ -2287,11 +2217,7 @@ export class CrossChainMessenger {
messageIndex = 0
): Promise<BigNumber> => {
return this.l1Provider.estimateGas(
await this.populateTransaction.proveMessage(
message,
opts,
messageIndex
)
await this.populateTransaction.proveMessage(message, opts, messageIndex)
)
},

Expand Down

0 comments on commit 186b1d1

Please sign in to comment.