@eth-optimism/watcher
Advanced tools
Comparing version 0.0.1-alpha.6 to 0.0.1-alpha.7
@@ -17,7 +17,7 @@ "use strict"; | ||
} | ||
async getL1TransactionReceipt(l2ToL1MsgHash) { | ||
return this._getLXTransactionReceipt(true, l2ToL1MsgHash); | ||
async getL1TransactionReceipt(l2ToL1MsgHash, pollForPending = true) { | ||
return this._getLXTransactionReceipt(true, l2ToL1MsgHash, pollForPending); | ||
} | ||
async getL2TransactionReceipt(l1ToL2MsgHash) { | ||
return this._getLXTransactionReceipt(false, l1ToL2MsgHash); | ||
async getL2TransactionReceipt(l1ToL2MsgHash, pollForPending = true) { | ||
return this._getLXTransactionReceipt(false, l1ToL2MsgHash, pollForPending); | ||
} | ||
@@ -37,3 +37,3 @@ async _getMessageHashesFromTx(isL1, txHash) { | ||
} | ||
async _getLXTransactionReceipt(isL1, msgHash) { | ||
async _getLXTransactionReceipt(isL1, msgHash, pollForPending) { | ||
const layer = isL1 ? this.l1 : this.l2; | ||
@@ -55,2 +55,5 @@ const blockNumber = await layer.provider.getBlockNumber(); | ||
} | ||
if (!pollForPending) { | ||
return Promise.resolve(undefined); | ||
} | ||
return new Promise(async (resolve, reject) => { | ||
@@ -57,0 +60,0 @@ layer.provider.on(filter, async (log) => { |
{ | ||
"name": "@eth-optimism/watcher", | ||
"version": "0.0.1-alpha.6", | ||
"version": "0.0.1-alpha.7", | ||
"description": "Watcher for cross domain messages", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
# @eth-optimism/watcher | ||
#### Watcher | ||
Our `Watcher` allows you to retrieve all transaction hashes related to cross domain messages such as deposits and withdrawals. In order to use, first send a transaction which sends a cross domain message, for example a deposit from L1 into L2. After sending the deposit transaction and storing the transaction hash, use `getMessageHashesFromL1Tx(l1TxHash)` to get an array of the message hashes of all of the L1->L2 messages that were sent inside of that L1 tx (This will usually just be a single element array, but it can return multiple if one L1 transaction triggers multiple deposits). `getMessageHashesFromL2Tx(l2TxHash)` does the same for L2->L1 messages. `getL2TransactionReceipt(messageHash)` takes in an L1->L2 message hash and then after 2-5 minutes, returns the receipt of the L2 tx that the message ends up getting relayed in. `getL1TransactionReceipt(messageHash)` does the same for L2->L1 messages, except the delay is 7 days. | ||
Our `Watcher` allows you to retrieve all transaction hashes related to cross domain messages such as deposits and withdrawals. | ||
In order to use, first send a transaction which sends a cross domain message, for example a deposit from L1 into L2. After sending the deposit transaction and storing the transaction hash, use `getMessageHashesFromL1Tx(l1TxHash)` to get an array of the message hashes of all of the L1->L2 messages that were sent inside of that L1 tx (This will usually just be a single element array, but it can return multiple if one L1 transaction triggers multiple deposits). `getMessageHashesFromL2Tx(l2TxHash)` does the same for L2->L1 messages. | ||
`getL2TransactionReceipt(messageHash)` takes in an L1->L2 message hash and then after 2-5 minutes, returns the receipt of the L2 tx that the message ends up getting relayed in. `getL1TransactionReceipt(messageHash)` does the same for L2->L1 messages, except the delay is 7 days. There is an optional parameter `pollForPending` on `getL1TransactionReceipt` and `getL2TransactionReceipt` that is set to `true` by default. If you would like to disable polling and rather just search if the message has already been relayed or return `undefined` otherwise, then you can use `getL1TransactionReceipt(messageHash, false)`. | ||
```typescript | ||
import { Watcher } from '@eth-optimism/ovm-toolchain/' | ||
import { Watcher } from '@eth-optimism/watcher/' | ||
import { JsonRpcProvider } from 'ethers/providers' | ||
@@ -9,0 +13,0 @@ |
7567
97
28