Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
0b4453f7
Unverified
Commit
0b4453f7
authored
Feb 09, 2022
by
Kelvin Fichter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(core-utils): remove Watcher and injectL2Context
parent
d3d70291
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
6 additions
and
261 deletions
+6
-261
moody-singers-hunt.md
.changeset/moody-singers-hunt.md
+5
-0
package.json
packages/core-utils/package.json
+1
-3
index.ts
packages/core-utils/src/optimism/index.ts
+0
-2
l2context.ts
packages/core-utils/src/optimism/l2context.ts
+0
-85
watcher.ts
packages/core-utils/src/optimism/watcher.ts
+0
-171
No files found.
.changeset/moody-singers-hunt.md
0 → 100644
View file @
0b4453f7
---
'
@eth-optimism/core-utils'
:
minor
---
Deletes the Watcher and injectL2Context functions. Use the SDK instead.
packages/core-utils/package.json
View file @
0b4453f7
...
...
@@ -37,12 +37,10 @@
"@ethersproject/providers"
:
"^5.5.3"
,
"@ethersproject/web"
:
"^5.5.1"
,
"chai"
:
"^4.3.4"
,
"ethers"
:
"^5.5.4"
,
"lodash"
:
"^4.17.21"
"ethers"
:
"^5.5.4"
},
"devDependencies"
:
{
"@types/chai"
:
"^4.2.18"
,
"@types/lodash"
:
"^4.14.168"
,
"@types/mocha"
:
"^8.2.2"
,
"@typescript-eslint/eslint-plugin"
:
"^4.26.0"
,
"@typescript-eslint/parser"
:
"^4.26.0"
,
...
...
packages/core-utils/src/optimism/index.ts
View file @
0b4453f7
...
...
@@ -5,6 +5,4 @@
export
*
from
'
./alias
'
export
*
from
'
./batch-encoding
'
export
*
from
'
./fees
'
export
*
from
'
./l2context
'
export
*
from
'
./rollup-types
'
export
*
from
'
./watcher
'
packages/core-utils/src/optimism/l2context.ts
deleted
100644 → 0
View file @
d3d70291
import
cloneDeep
from
'
lodash/cloneDeep
'
import
{
providers
,
BigNumber
}
from
'
ethers
'
const
parseNumber
=
(
n
:
string
|
number
):
number
=>
{
if
(
typeof
n
===
'
string
'
&&
n
.
startsWith
(
'
0x
'
))
{
return
parseInt
(
n
,
16
)
}
if
(
typeof
n
===
'
number
'
)
{
return
n
}
return
parseInt
(
n
,
10
)
}
/**
* Helper for adding additional L2 context to transactions
*/
export
const
injectL2Context
=
(
l1Provider
:
providers
.
JsonRpcProvider
)
=>
{
const
provider
=
cloneDeep
(
l1Provider
)
// Pass through the state root
const
blockFormat
=
provider
.
formatter
.
block
.
bind
(
provider
.
formatter
)
provider
.
formatter
.
block
=
(
block
)
=>
{
const
b
=
blockFormat
(
block
)
b
.
stateRoot
=
block
.
stateRoot
return
b
}
// Pass through the state root and additional tx data
const
blockWithTransactions
=
provider
.
formatter
.
blockWithTransactions
.
bind
(
provider
.
formatter
)
provider
.
formatter
.
blockWithTransactions
=
(
block
)
=>
{
const
b
=
blockWithTransactions
(
block
)
b
.
stateRoot
=
block
.
stateRoot
for
(
let
i
=
0
;
i
<
b
.
transactions
.
length
;
i
++
)
{
b
.
transactions
[
i
].
l1BlockNumber
=
block
.
transactions
[
i
].
l1BlockNumber
if
(
b
.
transactions
[
i
].
l1BlockNumber
!=
null
)
{
b
.
transactions
[
i
].
l1BlockNumber
=
parseNumber
(
b
.
transactions
[
i
].
l1BlockNumber
)
}
b
.
transactions
[
i
].
l1Timestamp
=
block
.
transactions
[
i
].
l1Timestamp
if
(
b
.
transactions
[
i
].
l1Timestamp
!=
null
)
{
b
.
transactions
[
i
].
l1Timestamp
=
parseNumber
(
b
.
transactions
[
i
].
l1Timestamp
)
}
b
.
transactions
[
i
].
l1TxOrigin
=
block
.
transactions
[
i
].
l1TxOrigin
b
.
transactions
[
i
].
queueOrigin
=
block
.
transactions
[
i
].
queueOrigin
b
.
transactions
[
i
].
rawTransaction
=
block
.
transactions
[
i
].
rawTransaction
}
return
b
}
// Handle additional tx data
const
formatTxResponse
=
provider
.
formatter
.
transactionResponse
.
bind
(
provider
.
formatter
)
provider
.
formatter
.
transactionResponse
=
(
transaction
)
=>
{
const
tx
=
formatTxResponse
(
transaction
)
as
any
tx
.
txType
=
transaction
.
txType
tx
.
queueOrigin
=
transaction
.
queueOrigin
tx
.
rawTransaction
=
transaction
.
rawTransaction
tx
.
l1BlockNumber
=
transaction
.
l1BlockNumber
if
(
tx
.
l1BlockNumber
!=
null
)
{
tx
.
l1BlockNumber
=
parseInt
(
tx
.
l1BlockNumber
,
16
)
}
tx
.
l1TxOrigin
=
transaction
.
l1TxOrigin
return
tx
}
const
formatReceiptResponse
=
provider
.
formatter
.
receipt
.
bind
(
provider
.
formatter
)
provider
.
formatter
.
receipt
=
(
receipt
)
=>
{
const
r
=
formatReceiptResponse
(
receipt
)
r
.
l1GasPrice
=
BigNumber
.
from
(
receipt
.
l1GasPrice
)
r
.
l1GasUsed
=
BigNumber
.
from
(
receipt
.
l1GasUsed
)
r
.
l1Fee
=
BigNumber
.
from
(
receipt
.
l1Fee
)
r
.
l1FeeScalar
=
parseFloat
(
receipt
.
l1FeeScalar
)
return
r
}
return
provider
}
packages/core-utils/src/optimism/watcher.ts
deleted
100644 → 0
View file @
d3d70291
/* External Imports */
import
{
ethers
}
from
'
ethers
'
import
{
Provider
,
TransactionReceipt
}
from
'
@ethersproject/abstract-provider
'
const
RELAYED_MESSAGE
=
ethers
.
utils
.
id
(
`RelayedMessage(bytes32)`
)
const
FAILED_RELAYED_MESSAGE
=
ethers
.
utils
.
id
(
`FailedRelayedMessage(bytes32)`
)
export
interface
Layer
{
provider
:
Provider
messengerAddress
:
string
blocksToFetch
?:
number
}
export
interface
WatcherOptions
{
l1
:
Layer
l2
:
Layer
pollInterval
?:
number
blocksToFetch
?:
number
pollForPending
?:
boolean
}
export
class
Watcher
{
public
l1
:
Layer
public
l2
:
Layer
public
pollInterval
=
3000
public
blocksToFetch
=
1500
public
pollForPending
=
true
constructor
(
opts
:
WatcherOptions
)
{
this
.
l1
=
opts
.
l1
this
.
l2
=
opts
.
l2
if
(
typeof
opts
.
pollInterval
===
'
number
'
)
{
this
.
pollInterval
=
opts
.
pollInterval
}
if
(
typeof
opts
.
blocksToFetch
===
'
number
'
)
{
this
.
blocksToFetch
=
opts
.
blocksToFetch
}
if
(
typeof
opts
.
pollForPending
===
'
boolean
'
)
{
this
.
pollForPending
=
opts
.
pollForPending
}
}
public
async
getMessageHashesFromL1Tx
(
l1TxHash
:
string
):
Promise
<
string
[]
>
{
return
this
.
getMessageHashesFromTx
(
this
.
l1
,
l1TxHash
)
}
public
async
getMessageHashesFromL2Tx
(
l2TxHash
:
string
):
Promise
<
string
[]
>
{
return
this
.
getMessageHashesFromTx
(
this
.
l2
,
l2TxHash
)
}
public
async
getL1TransactionReceipt
(
l2ToL1MsgHash
:
string
,
pollForPending
?
):
Promise
<
TransactionReceipt
>
{
return
this
.
getTransactionReceipt
(
this
.
l1
,
l2ToL1MsgHash
,
pollForPending
)
}
public
async
getL2TransactionReceipt
(
l1ToL2MsgHash
:
string
,
pollForPending
?
):
Promise
<
TransactionReceipt
>
{
return
this
.
getTransactionReceipt
(
this
.
l2
,
l1ToL2MsgHash
,
pollForPending
)
}
public
async
getMessageHashesFromTx
(
layer
:
Layer
,
txHash
:
string
):
Promise
<
string
[]
>
{
const
receipt
=
await
layer
.
provider
.
getTransactionReceipt
(
txHash
)
if
(
!
receipt
)
{
return
[]
}
const
msgHashes
=
[]
const
sentMessageEventId
=
ethers
.
utils
.
id
(
'
SentMessage(address,address,bytes,uint256,uint256)
'
)
const
l2CrossDomainMessengerRelayAbi
=
[
'
function relayMessage(address _target,address _sender,bytes memory _message,uint256 _messageNonce)
'
,
]
const
l2CrossDomainMessengerRelayinterface
=
new
ethers
.
utils
.
Interface
(
l2CrossDomainMessengerRelayAbi
)
for
(
const
log
of
receipt
.
logs
)
{
if
(
log
.
address
===
layer
.
messengerAddress
&&
log
.
topics
[
0
]
===
sentMessageEventId
)
{
const
[
sender
,
message
,
messageNonce
]
=
ethers
.
utils
.
defaultAbiCoder
.
decode
(
[
'
address
'
,
'
bytes
'
,
'
uint256
'
],
log
.
data
)
const
[
target
]
=
ethers
.
utils
.
defaultAbiCoder
.
decode
(
[
'
address
'
],
log
.
topics
[
1
]
)
const
encodedMessage
=
l2CrossDomainMessengerRelayinterface
.
encodeFunctionData
(
'
relayMessage
'
,
[
target
,
sender
,
message
,
messageNonce
]
)
msgHashes
.
push
(
ethers
.
utils
.
solidityKeccak256
([
'
bytes
'
],
[
encodedMessage
])
)
}
}
return
msgHashes
}
public
async
getTransactionReceipt
(
layer
:
Layer
,
msgHash
:
string
,
pollForPending
?
):
Promise
<
TransactionReceipt
>
{
if
(
typeof
pollForPending
!==
'
boolean
'
)
{
pollForPending
=
this
.
pollForPending
}
let
matches
:
ethers
.
providers
.
Log
[]
=
[]
let
blocksToFetch
=
layer
.
blocksToFetch
if
(
typeof
blocksToFetch
!==
'
number
'
)
{
blocksToFetch
=
this
.
blocksToFetch
}
// scan for transaction with specified message
while
(
matches
.
length
===
0
)
{
const
blockNumber
=
await
layer
.
provider
.
getBlockNumber
()
const
startingBlock
=
Math
.
max
(
blockNumber
-
blocksToFetch
,
0
)
const
successFilter
:
ethers
.
providers
.
Filter
=
{
address
:
layer
.
messengerAddress
,
topics
:
[
RELAYED_MESSAGE
],
fromBlock
:
startingBlock
,
}
const
failureFilter
:
ethers
.
providers
.
Filter
=
{
address
:
layer
.
messengerAddress
,
topics
:
[
FAILED_RELAYED_MESSAGE
],
fromBlock
:
startingBlock
,
}
const
successLogs
=
await
layer
.
provider
.
getLogs
(
successFilter
)
const
failureLogs
=
await
layer
.
provider
.
getLogs
(
failureFilter
)
const
logs
=
successLogs
.
concat
(
failureLogs
)
matches
=
logs
.
filter
(
(
log
:
ethers
.
providers
.
Log
)
=>
log
.
topics
[
1
]
===
msgHash
)
// exit loop after first iteration if not polling
if
(
!
pollForPending
)
{
break
}
// pause awhile before trying again
await
new
Promise
((
r
)
=>
setTimeout
(
r
,
this
.
pollInterval
))
}
// Message was relayed in the past
if
(
matches
.
length
>
0
)
{
if
(
matches
.
length
>
1
)
{
throw
Error
(
'
Found multiple transactions relaying the same message hash.
'
)
}
return
layer
.
provider
.
getTransactionReceipt
(
matches
[
0
].
transactionHash
)
}
else
{
return
Promise
.
resolve
(
undefined
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment