Commit dee74ef5 authored by Annie Ke's avatar Annie Ke Committed by GitHub

[cleanup] batch submitter unused code + types to core-utils (#614)

* remove unused utils files

* remove duplicate spec file

* remove unused imports

* move batch-submitter types to core-utils

* add changeset
parent bebeef14
---
"@eth-optimism/batch-submitter": patch
"@eth-optimism/core-utils": patch
---
migrate batch submitter types to core-utils
...@@ -2,21 +2,9 @@ ...@@ -2,21 +2,9 @@
import { Contract, Signer, utils, providers } from 'ethers' import { Contract, Signer, utils, providers } from 'ethers'
import { TransactionReceipt } from '@ethersproject/abstract-provider' import { TransactionReceipt } from '@ethersproject/abstract-provider'
import * as ynatm from '@eth-optimism/ynatm' import * as ynatm from '@eth-optimism/ynatm'
import { Logger, Metrics } from '@eth-optimism/core-utils' import { RollupInfo, Logger, Metrics } from '@eth-optimism/core-utils'
import { getContractFactory } from 'old-contracts' import { getContractFactory } from 'old-contracts'
export interface RollupInfo {
mode: 'sequencer' | 'verifier'
syncing: boolean
ethContext: {
blockNumber: number
timestamp: number
}
rollupContext: {
index: number
queueIndex: number
}
}
export interface Range { export interface Range {
start: number start: number
end: number end: number
......
...@@ -4,16 +4,16 @@ import { Contract, Signer, providers } from 'ethers' ...@@ -4,16 +4,16 @@ import { Contract, Signer, providers } from 'ethers'
import { TransactionReceipt } from '@ethersproject/abstract-provider' import { TransactionReceipt } from '@ethersproject/abstract-provider'
import { getContractFactory } from 'old-contracts' import { getContractFactory } from 'old-contracts'
import { import {
L2Block,
RollupInfo,
Logger, Logger,
Bytes32, Bytes32,
remove0x, remove0x,
toRpcHexString,
Metrics, Metrics,
} from '@eth-optimism/core-utils' } from '@eth-optimism/core-utils'
/* Internal Imports */ /* Internal Imports */
import { L2Block } from '..' import { Range, BatchSubmitter, BLOCK_OFFSET } from '.'
import { RollupInfo, Range, BatchSubmitter, BLOCK_OFFSET } from '.'
export class StateBatchSubmitter extends BatchSubmitter { export class StateBatchSubmitter extends BatchSubmitter {
// TODO: Change this so that we calculate start = scc.totalElements() and end = ctc.totalElements()! // TODO: Change this so that we calculate start = scc.totalElements() and end = ctc.totalElements()!
......
/* External Imports */ /* External Imports */
import { Promise as bPromise } from 'bluebird' import { Promise as bPromise } from 'bluebird'
import { Signer, ethers, Contract, providers } from 'ethers' import { Signer, ethers, Contract, providers } from 'ethers'
import { import { TransactionReceipt } from '@ethersproject/abstract-provider'
TransactionResponse,
TransactionReceipt,
} from '@ethersproject/abstract-provider'
import { getContractInterface, getContractFactory } from 'old-contracts' import { getContractInterface, getContractFactory } from 'old-contracts'
import { getContractInterface as getNewContractInterface } from '@eth-optimism/contracts' import { getContractInterface as getNewContractInterface } from '@eth-optimism/contracts'
import { Logger, Metrics, ctcCoder } from '@eth-optimism/core-utils' import {
L2Block,
RollupInfo,
BatchElement,
Batch,
QueueOrigin,
Logger,
Metrics,
} from '@eth-optimism/core-utils'
/* Internal Imports */ /* Internal Imports */
import { import {
...@@ -17,8 +22,7 @@ import { ...@@ -17,8 +22,7 @@ import {
AppendSequencerBatchParams, AppendSequencerBatchParams,
} from '../transaction-chain-contract' } from '../transaction-chain-contract'
import { L2Block, BatchElement, Batch, QueueOrigin } from '..' import { Range, BatchSubmitter, BLOCK_OFFSET } from '.'
import { RollupInfo, Range, BatchSubmitter, BLOCK_OFFSET } from '.'
export interface AutoFixBatchOptions { export interface AutoFixBatchOptions {
fixDoublePlayedDeposits: boolean fixDoublePlayedDeposits: boolean
......
export * from './batch-submitter' export * from './batch-submitter'
export * from './transaction-chain-contract' export * from './transaction-chain-contract'
export * from './types'
export * from './utils'
/* External Imports */
import { BigNumber } from 'ethers'
export const getLen = (pos: { start; end }) => (pos.end - pos.start) * 2
export const encodeHex = (val: any, len: number) =>
remove0x(BigNumber.from(val).toHexString()).padStart(len, '0')
export const toVerifiedBytes = (val: string, len: number) => {
val = remove0x(val)
if (val.length !== len) {
throw new Error('Invalid length!')
}
return val
}
export const remove0x = (str: string): string => {
if (str.startsWith('0x')) {
return str.slice(2)
} else {
return str
}
}
...@@ -22,19 +22,18 @@ import { ...@@ -22,19 +22,18 @@ import {
} from '../helpers' } from '../helpers'
import { import {
CanonicalTransactionChainContract, CanonicalTransactionChainContract,
QueueOrigin,
TransactionBatchSubmitter as RealTransactionBatchSubmitter, TransactionBatchSubmitter as RealTransactionBatchSubmitter,
StateBatchSubmitter, StateBatchSubmitter,
TX_BATCH_SUBMITTER_LOG_TAG, TX_BATCH_SUBMITTER_LOG_TAG,
STATE_BATCH_SUBMITTER_LOG_TAG, STATE_BATCH_SUBMITTER_LOG_TAG,
Batch,
BatchSubmitter, BatchSubmitter,
} from '../../src' } from '../../src'
import { import {
QueueOrigin,
Batch,
Signature, Signature,
TxType, TxType,
ctcCoder,
remove0x, remove0x,
Logger, Logger,
Metrics, Metrics,
......
...@@ -4,9 +4,7 @@ import { ...@@ -4,9 +4,7 @@ import {
BlockWithTransactions, BlockWithTransactions,
TransactionResponse, TransactionResponse,
} from '@ethersproject/abstract-provider' } from '@ethersproject/abstract-provider'
import { L2Transaction, L2Block, RollupInfo } from '@eth-optimism/core-utils'
/* Internal Imports */
import { L2Transaction, L2Block, RollupInfo } from '../../src'
/** /**
* Unformatted Transaction & Blocks. This exists because Geth currently * Unformatted Transaction & Blocks. This exists because Geth currently
......
export * from './dummy' export * from './dummy'
export * from './constants' export * from './constants'
export * from './resolver' export * from './resolver'
export * from './utils'
/* External Imports */
import { BigNumber } from 'ethers'
/**
* Converts a string or buffer to a '0x'-prefixed hex string.
* @param buf String or buffer to convert.
* @returns '0x'-prefixed string.
*/
export const toHexString = (buf: Buffer | string): string => {
return '0x' + fromHexString(buf).toString('hex')
}
/**
* Converts a '0x'-prefixed string to a buffer.
* @param str '0x'-prefixed string to convert.
* @returns Hex buffer.
*/
export const fromHexString = (str: string | Buffer): Buffer => {
if (typeof str === 'string' && str.startsWith('0x')) {
return Buffer.from(str.slice(2), 'hex')
}
return Buffer.from(str)
}
export const toHexString32 = (
input: Buffer | string | number,
padRight = false
): string => {
if (typeof input === 'number') {
input = BigNumber.from(input).toHexString()
}
input = toHexString(input).slice(2)
return '0x' + (padRight ? input.padEnd(64, '0') : input.padStart(64, '0'))
}
export const getHexSlice = (
input: Buffer | string,
start: number,
length: number
): string => {
return toHexString(fromHexString(input).slice(start, start + length))
}
/**
* Generates a hex string of repeated bytes.
* @param byte Byte to repeat.
* @param len Number of times to repeat the byte.
* @return '0x'-prefixed hex string filled with the provided byte.
*/
export const makeHexString = (byte: string, len: number): string => {
return '0x' + byte.repeat(len)
}
/**
* Genereates an address with a repeated byte.
* @param byte Byte to repeat in the address.
* @return Address filled with the repeated byte.
*/
export const makeAddress = (byte: string): string => {
return makeHexString(byte, 20)
}
/**
* Removes '0x' from a hex string.
* @param str Hex string to remove '0x' from.
* @returns String without the '0x' prefix.
*/
export const remove0x = (str: string): string => {
if (str.startsWith('0x')) {
return str.slice(2)
} else {
return str
}
}
export const getEthTime = async (provider: any): Promise<number> => {
return (await provider.getBlock('latest')).timestamp
}
export const setEthTime = async (
provider: any,
time: number
): Promise<void> => {
await provider.send('evm_setNextBlockTimestamp', [time])
}
export const increaseEthTime = async (
provider: any,
amount: number
): Promise<void> => {
await setEthTime(provider, (await getEthTime(provider)) + amount)
await provider.send('evm_mine', [])
}
export const getBlockTime = async (
provider: any,
block: number
): Promise<number> => {
await provider.send('evm_mine', [])
return (await provider.getBlock(block)).timestamp
}
export const getNextBlockNumber = async (provider: any): Promise<number> => {
return (await provider.getBlock('latest')).number + 1
}
export * from './buffer-utils'
export * from './byte-utils'
export * from './eth-time'
...@@ -4,6 +4,19 @@ import { ...@@ -4,6 +4,19 @@ import {
TransactionResponse, TransactionResponse,
} from '@ethersproject/abstract-provider' } from '@ethersproject/abstract-provider'
export interface RollupInfo {
mode: 'sequencer' | 'verifier'
syncing: boolean
ethContext: {
blockNumber: number
timestamp: number
}
rollupContext: {
index: number
queueIndex: number
}
}
export enum QueueOrigin { export enum QueueOrigin {
Sequencer = 'sequencer', Sequencer = 'sequencer',
L1ToL2 = 'l1', L1ToL2 = 'l1',
......
...@@ -4,3 +4,4 @@ export * from './watcher' ...@@ -4,3 +4,4 @@ export * from './watcher'
export * from './base-service' export * from './base-service'
export * from './l2context' export * from './l2context'
export * from './events' export * from './events'
export * from './batches'
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