Commit 2e929aa9 authored by Mark Tyneway's avatar Mark Tyneway

core-utils: parse L1 timestamp in injectContext

Also parse the L1 timestamp in `injectContext`.
This value is useful but was not previously parsed
and added to the ethers provider
parent e87f2b3b
---
'@eth-optimism/core-utils': patch
---
Parse the L1 timestamp in `injectContext`
import cloneDeep from 'lodash/cloneDeep'
import { providers } 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
*/
......@@ -25,9 +35,14 @@ export const injectL2Context = (l1Provider: providers.JsonRpcProvider) => {
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 = parseInt(
b.transactions[i].l1BlockNumber,
16
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment