Skip to content

Commit

Permalink
chore: rename to ParentToChild
Browse files Browse the repository at this point in the history
  • Loading branch information
douglance committed Oct 2, 2023
1 parent b2d8824 commit 1b00e27
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 61 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export {
L2ContractTransaction,
} from './lib/message/L2Transaction'
export {
ChildToParentChainMessage as L2ToL1Message,
ChildToParentChainMessageWriter as L2ToL1MessageWriter,
ChildToParentChainMessageReader as L2ToL1MessageReader,
ChildToParentMessage as L2ToL1Message,
ChildToParentMessageWriter as L2ToL1MessageWriter,
ChildToParentMessageReader as L2ToL1MessageReader,
} from './lib/message/L2ToL1Message'
export {
L1ContractTransaction,
Expand Down
77 changes: 36 additions & 41 deletions src/lib/message/L2ToL1Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,93 +29,88 @@ import {
import * as classic from './L2ToL1MessageClassic'
import * as nitro from './L2ToL1MessageNitro'
import {
L2ToL1TransactionEvent as ClassicChildToParentChainTransactionEvent,
L2ToL1TxEvent as NitroChildToParentChainTransactionEvent,
L2ToL1TransactionEvent as ClassicChildToParentTransactionEvent,
L2ToL1TxEvent as NitroChildToParentTransactionEvent,
} from '../abi/ArbSys'
import { isDefined } from '../utils/lib'
import { EventArgs } from '../dataEntities/event'
import { L2ToL1MessageStatus as ChildToParentChainMessageStatus } from '../dataEntities/message'
import { L2ToL1MessageStatus as ChildToParentMessageStatus } from '../dataEntities/message'
import { getChainNetwork } from '../dataEntities/networks'
import { ArbSdkError } from '../dataEntities/errors'

export type ChildToParentChainTransactionEvent =
| EventArgs<ClassicChildToParentChainTransactionEvent>
| EventArgs<NitroChildToParentChainTransactionEvent>
export type ChildToParentTransactionEvent =
| EventArgs<ClassicChildToParentTransactionEvent>
| EventArgs<NitroChildToParentTransactionEvent>

/**
* Conditional type for Signer or Provider. If T is of type Provider
* then ChildToParentChainMessageReaderOrWriter<T> will be of type ChildToParentChainMessageReader.
* If T is of type Signer then ChildToParentChainMessageReaderOrWriter<T> will be of
* type ChildToParentChainMessageWriter.
* then ChildToParentMessageReaderOrWriter<T> will be of type ChildToParentMessageReader.
* If T is of type Signer then ChildToParentMessageReaderOrWriter<T> will be of
* type ChildToParentMessageWriter.
*/
export type ChildToParentChainMessageReaderOrWriter<
T extends SignerOrProvider
> = T extends Provider
? ChildToParentChainMessageReader
: ChildToParentChainMessageWriter
export type ChildToParentMessageReaderOrWriter<T extends SignerOrProvider> =
T extends Provider ? ChildToParentMessageReader : ChildToParentMessageWriter

/**
* Base functionality for Chain->ParentChain messages
*/
export class ChildToParentChainMessage {
export class ChildToParentMessage {
protected isClassic(
e: ChildToParentChainTransactionEvent
): e is EventArgs<ClassicChildToParentChainTransactionEvent> {
e: ChildToParentTransactionEvent
): e is EventArgs<ClassicChildToParentTransactionEvent> {
return isDefined(
(e as EventArgs<ClassicChildToParentChainTransactionEvent>).indexInBatch
(e as EventArgs<ClassicChildToParentTransactionEvent>).indexInBatch
)
}

/**
* Instantiates a new `ChildToParentChainMessageWriter` or `ChildToParentChainMessageReader` object.
* Instantiates a new `ChildToParentMessageWriter` or `ChildToParentMessageReader` object.
*
* @param {SignerOrProvider} ParentChainSignerOrProvider Signer or provider to be used for executing or reading the Chain-to-ParentChain message.
* @param {ChildToParentChainTransactionEvent} event The event containing the data of the Chain-to-ParentChain message.
* @param {ChildToParentTransactionEvent} event The event containing the data of the Chain-to-ParentChain message.
* @param {Provider} [ParentChainProvider] Optional. Used to override the Provider which is attached to `ParentChainSignerOrProvider` in case you need more control. This will be a required parameter in a future major version update.
*/
public static fromEvent<T extends SignerOrProvider>(
ParentChainSignerOrProvider: T,
event: ChildToParentChainTransactionEvent,
event: ChildToParentTransactionEvent,
ParentChainProvider?: Provider
): ChildToParentChainMessageReaderOrWriter<T>
): ChildToParentMessageReaderOrWriter<T>
static fromEvent<T extends SignerOrProvider>(
ParentChainSignerOrProvider: T,
event: ChildToParentChainTransactionEvent,
event: ChildToParentTransactionEvent,
ParentChainProvider?: Provider
): ChildToParentChainMessageReader | ChildToParentChainMessageWriter {
): ChildToParentMessageReader | ChildToParentMessageWriter {
return SignerProviderUtils.isSigner(ParentChainSignerOrProvider)
? new ChildToParentChainMessageWriter(
? new ChildToParentMessageWriter(
ParentChainSignerOrProvider,
event,
ParentChainProvider
)
: new ChildToParentChainMessageReader(ParentChainSignerOrProvider, event)
: new ChildToParentMessageReader(ParentChainSignerOrProvider, event)
}

/**
* Get event logs for ChildToParentChain transactions.
* Get event logs for ChildToParent transactions.
* @param ChainProvider
* @param filter Block range filter
* @param position The batchnumber indexed field was removed in nitro and a position indexed field was added.
* For pre-nitro events the value passed in here will be used to find events with the same batchnumber.
* For post nitro events it will be used to find events with the same position.
* @param destination The ParentChain destination of the ChildToParentChain message
* @param destination The ParentChain destination of the ChildToParent message
* @param hash The uniqueId indexed field was removed in nitro and a hash indexed field was added.
* For pre-nitro events the value passed in here will be used to find events with the same uniqueId.
* For post nitro events it will be used to find events with the same hash.
* @param indexInBatch The index in the batch, only valid for pre-nitro events. This parameter is ignored post-nitro
* @returns Any classic and nitro events that match the provided filters.
*/
public static async getChildToParentChainEvents(
public static async getChildToParentEvents(
ChainProvider: Provider,
filter: { fromBlock: BlockTag; toBlock: BlockTag },
position?: BigNumber,
destination?: string,
hash?: BigNumber,
indexInBatch?: BigNumber
): Promise<
(ChildToParentChainTransactionEvent & { transactionHash: string })[]
> {
): Promise<(ChildToParentTransactionEvent & { transactionHash: string })[]> {
const ChainNetwork = await getChainNetwork(ChainProvider)

const inClassicRange = (blockTag: BlockTag, nitroGenBlock: number) => {
Expand Down Expand Up @@ -202,13 +197,13 @@ export class ChildToParentChainMessage {
/**
* Provides read-only access for Chain-to-ParentChain-messages
*/
export class ChildToParentChainMessageReader extends ChildToParentChainMessage {
export class ChildToParentMessageReader extends ChildToParentMessage {
private readonly classicReader?: classic.L2ToL1MessageReaderClassic
private readonly nitroReader?: nitro.L2ToL1MessageReaderNitro

constructor(
protected readonly ParentChainProvider: Provider,
event: ChildToParentChainTransactionEvent
event: ChildToParentTransactionEvent
) {
super()
if (this.isClassic(event)) {
Expand Down Expand Up @@ -240,8 +235,8 @@ export class ChildToParentChainMessageReader extends ChildToParentChainMessage {
*/
public async status(
ChainProvider: Provider
): Promise<ChildToParentChainMessageStatus> {
// can we create an ChildToParentChainmessage here, we need to - the constructor is what we need
): Promise<ChildToParentMessageStatus> {
// can we create an ChildToParentmessage here, we need to - the constructor is what we need
if (this.nitroReader) return await this.nitroReader.status(ChainProvider)
else return await this.classicReader!.status(ChainProvider)
}
Expand Down Expand Up @@ -284,20 +279,20 @@ export class ChildToParentChainMessageReader extends ChildToParentChainMessage {
/**
* Provides read and write access for Chain-to-ParentChain-messages
*/
export class ChildToParentChainMessageWriter extends ChildToParentChainMessageReader {
export class ChildToParentMessageWriter extends ChildToParentMessageReader {
private readonly classicWriter?: classic.L2ToL1MessageWriterClassic
private readonly nitroWriter?: nitro.L2ToL1MessageWriterNitro

/**
* Instantiates a new `ChildToParentChainMessageWriter` object.
* Instantiates a new `ChildToParentMessageWriter` object.
*
* @param {Signer} ParentChainSigner The signer to be used for executing the Chain-to-ParentChain message.
* @param {ChildToParentChainTransactionEvent} event The event containing the data of the Chain-to-ParentChain message.
* @param {ChildToParentTransactionEvent} event The event containing the data of the Chain-to-ParentChain message.
* @param {Provider} [ParentChainProvider] Optional. Used to override the Provider which is attached to `ParentChainSigner` in case you need more control. This will be a required parameter in a future major version update.
*/
constructor(
ParentChainSigner: Signer,
event: ChildToParentChainTransactionEvent,
event: ChildToParentTransactionEvent,
ParentChainProvider?: Provider
) {
super(ParentChainProvider ?? ParentChainSigner.provider!, event)
Expand All @@ -319,7 +314,7 @@ export class ChildToParentChainMessageWriter extends ChildToParentChainMessageRe
}

/**
* Executes the ChildToParentChainMessage on ParentChain.
* Executes the ChildToParentMessage on ParentChain.
* Will throw an error if the outbox entry has not been created, which happens when the
* corresponding assertion is confirmed.
* @returns
Expand Down
10 changes: 5 additions & 5 deletions src/lib/message/L2Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import {
SignerOrProvider,
} from '../dataEntities/signerOrProvider'
import {
ChildToParentChainMessageReader as L2ToL1MessageReader,
ChildToParentChainMessageReaderOrWriter as L2ToL1MessageReaderOrWriter,
ChildToParentChainMessage as L2ToL1Message,
ChildToParentChainMessageWriter as L2ToL1MessageWriter,
ChildToParentChainTransactionEvent as L2ToL1TransactionEvent,
ChildToParentMessageReader as L2ToL1MessageReader,
ChildToParentMessageReaderOrWriter as L2ToL1MessageReaderOrWriter,
ChildToParentMessage as L2ToL1Message,
ChildToParentMessageWriter as L2ToL1MessageWriter,
ChildToParentTransactionEvent as L2ToL1TransactionEvent,
} from './L2ToL1Message'
import { ArbSys__factory } from '../abi/factories/ArbSys__factory'
import { ArbRetryableTx__factory } from '../abi/factories/ArbRetryableTx__factory'
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/eth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
prettyLog,
skipIfMainnet,
} from './testHelpers'
import { ChildToParentChainMessage as L2ToL1Message } from '../../src/lib/message/L2ToL1Message'
import { ChildToParentMessage as L2ToL1Message } from '../../src/lib/message/L2ToL1Message'
import { L2ToL1MessageStatus } from '../../src/lib/dataEntities/message'
import { L2TransactionReceipt } from '../../src/lib/message/L2Transaction'
import { ParentToChildMessageStatus as L1ToL2MessageStatus } from '../../src/lib/message/L1ToL2Message'
Expand Down Expand Up @@ -231,7 +231,7 @@ describe('Ether', async () => {
'eth withdraw getWithdrawalsInL2Transaction query came back empty'
).to.exist

const withdrawEvents = await L2ToL1Message.getChildToParentChainEvents(
const withdrawEvents = await L2ToL1Message.getChildToParentEvents(
l2Signer.provider!,
{ fromBlock: withdrawEthRec.blockNumber, toBlock: 'latest' },
undefined,
Expand Down
20 changes: 10 additions & 10 deletions tests/unit/l2toL1MessageEvents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@

import { Logger, LogLevel } from '@ethersproject/logger'
Logger.setLogLevel(LogLevel.ERROR)
import { L2ToL1Message as ChildToParentChainMessage } from '../../src'
import { L2ToL1Message as ChildToParentMessage } from '../../src'
import { getChainNetwork as getL2Network } from '../../src/lib/dataEntities/networks'
import { providers } from 'ethers'
import { anything, deepEqual, instance, mock, verify, when } from 'ts-mockito'

describe('ChildToParentChainMessage events', () => {
// ChildToParentChainTransaction
describe('ChildToParentMessage events', () => {
// ChildToParentTransaction
const classicTopic =
'0x5baaa87db386365b5c161be377bc3d8e317e8d98d71a3ca7ed7d555340c8f767'
// ChildToParentChainTx
// ChildToParentTx
const nitroTopic =
'0x3e7aafa77dbf186b7fd488006beff893744caa3c4f6f299e8a709fa2087374fc'

Expand Down Expand Up @@ -59,7 +59,7 @@ describe('ChildToParentChainMessage events', () => {
const fromBlock = 0
const toBlock = 1000

await ChildToParentChainMessage.getChildToParentChainEvents(l2Provider, {
await ChildToParentMessage.getChildToParentEvents(l2Provider, {
fromBlock: fromBlock,
toBlock: toBlock,
})
Expand All @@ -82,7 +82,7 @@ describe('ChildToParentChainMessage events', () => {
const fromBlock = l2Network.nitroGenesisBlock
const toBlock = l2Network.nitroGenesisBlock + 500

await ChildToParentChainMessage.getChildToParentChainEvents(l2Provider, {
await ChildToParentMessage.getChildToParentEvents(l2Provider, {
fromBlock: fromBlock,
toBlock: toBlock,
})
Expand All @@ -105,7 +105,7 @@ describe('ChildToParentChainMessage events', () => {
const fromBlock = 0
const toBlock = l2Network.nitroGenesisBlock + 500

await ChildToParentChainMessage.getChildToParentChainEvents(l2Provider, {
await ChildToParentMessage.getChildToParentEvents(l2Provider, {
fromBlock: fromBlock,
toBlock: toBlock,
})
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('ChildToParentChainMessage events', () => {
const fromBlock = 'earliest'
const toBlock = 'latest'

await ChildToParentChainMessage.getChildToParentChainEvents(l2Provider, {
await ChildToParentMessage.getChildToParentEvents(l2Provider, {
fromBlock: fromBlock,
toBlock: toBlock,
})
Expand Down Expand Up @@ -171,7 +171,7 @@ describe('ChildToParentChainMessage events', () => {
const fromBlock = l2Network.nitroGenesisBlock + 2
const toBlock = 'latest'

await ChildToParentChainMessage.getChildToParentChainEvents(l2Provider, {
await ChildToParentMessage.getChildToParentEvents(l2Provider, {
fromBlock: fromBlock,
toBlock: toBlock,
})
Expand All @@ -194,7 +194,7 @@ describe('ChildToParentChainMessage events', () => {
const fromBlock = 'earliest'
const toBlock = 'latest'

await ChildToParentChainMessage.getChildToParentChainEvents(l2Provider, {
await ChildToParentMessage.getChildToParentEvents(l2Provider, {
fromBlock: fromBlock,
toBlock: toBlock,
})
Expand Down

0 comments on commit 1b00e27

Please sign in to comment.