Skip to content

Commit

Permalink
dev: batching added
Browse files Browse the repository at this point in the history
  • Loading branch information
dewanshparashar committed Jan 21, 2025
1 parent 56472f6 commit 2c004c7
Showing 1 changed file with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import {
JsonRpcBatchProvider,
Network,
Networkish,
StaticJsonRpcProvider,
TransactionReceipt
} from '@ethersproject/providers'
import { BigNumber } from 'ethers'
import { BigNumber, version } from 'ethers'
import { ChainId } from '../types/ChainId'
import { ConnectionInfo } from 'ethers/lib/utils.js'
import { ConnectionInfo, defineReadOnly } from 'ethers/lib/utils.js'
import { isNetwork } from '../util/networks'

import { Logger } from '@ethersproject/logger'
const logger = new Logger(version)

interface Storage {
getItem(key: string): string | null
setItem(key: string, value: string): void
Expand Down Expand Up @@ -128,7 +132,31 @@ function addTxReceiptToCache(
)
}

export class EnhancedProvider extends StaticJsonRpcProvider {
export class EnhancedProvider extends JsonRpcBatchProvider {
async detectNetwork(): Promise<Network> {
let network = this.network
if (network == null) {
network = await super.detectNetwork()

if (!network) {
logger.throwError(
'no network detected',
Logger.errors.UNKNOWN_ERROR,
{}
)
}

// If still not set, set it
if (this._network == null) {
// A static network does not support "any"
defineReadOnly(this, '_network', network)

this.emit('network', network, null)
}
}
return network
}

private storage: Storage

constructor(
Expand Down

0 comments on commit 2c004c7

Please sign in to comment.