This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Exported discovery cli * Added changest * Did some renaming * Updated changelog * Moved cli commands' implementations to separate files * Added changeset * Updated changeset
- Loading branch information
1 parent
7fa5e3c
commit bb28144
Showing
7 changed files
with
134 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { assert, Logger } from '@l2beat/backend-tools' | ||
import { providers } from 'ethers' | ||
|
||
import { | ||
DiscoveryCliConfig, | ||
DiscoveryModuleConfig, | ||
getDiscoveryCliConfig, | ||
} from '../config/config.discovery' | ||
import { ConfigReader } from '../discovery/config/ConfigReader' | ||
import { dryRunDiscovery, runDiscovery } from '../discovery/runDiscovery' | ||
import { ChainId } from '../utils/ChainId' | ||
import { EtherscanLikeClient } from '../utils/EtherscanLikeClient' | ||
import { HttpClient } from '../utils/HttpClient' | ||
|
||
export async function discoverCommand( | ||
config: DiscoveryCliConfig, | ||
logger: Logger, | ||
): Promise<void> { | ||
if (!config.discovery) { | ||
return | ||
} | ||
const discoverConfig = config.discovery | ||
const chainConfig = config.chain | ||
|
||
assert( | ||
chainConfig.chainId === discoverConfig.chainId, | ||
'Chain config does not match discovery config! Update "discovery.config" file or config.json of your project', | ||
) | ||
|
||
const http = new HttpClient() | ||
const provider = new providers.StaticJsonRpcProvider(chainConfig.rpcUrl) | ||
const etherscanClient = EtherscanLikeClient.createForDiscovery( | ||
http, | ||
chainConfig.etherscanUrl, | ||
chainConfig.etherscanApiKey, | ||
chainConfig.etherscanUnsupported, | ||
) | ||
const configReader = new ConfigReader() | ||
|
||
if (discoverConfig.dryRun) { | ||
logger = logger.for('DryRun') | ||
logger.info('Starting') | ||
|
||
await dryRunDiscovery( | ||
provider, | ||
etherscanClient, | ||
config.chain.multicall, | ||
configReader, | ||
discoverConfig, | ||
) | ||
return | ||
} | ||
|
||
logger = logger.for('Discovery') | ||
logger.info('Starting discovery...\n') | ||
logger.info(`Project: ${discoverConfig.project}`) | ||
logger.info(`Chain: ${ChainId.getName(discoverConfig.chainId)}\n`) | ||
await runDiscovery( | ||
provider, | ||
etherscanClient, | ||
config.chain.multicall, | ||
configReader, | ||
discoverConfig, | ||
) | ||
} | ||
|
||
/** | ||
* Expose the discover command as a method exported by the package. | ||
*/ | ||
export function discover( | ||
config: DiscoveryModuleConfig, | ||
logger: Logger = Logger.DEBUG, | ||
): Promise<void> { | ||
const cliConfig = getDiscoveryCliConfig({ | ||
mode: 'discover', | ||
project: config.project, | ||
chain: config.chainId, | ||
dryRun: config.dryRun === true, | ||
dev: config.dev === true, | ||
sourcesFolder: config.sourcesFolder, | ||
discoveryFilename: config.discoveryFilename, | ||
blockNumber: config.blockNumber, | ||
}) | ||
|
||
return discoverCommand(cliConfig, logger) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Logger } from '@l2beat/backend-tools' | ||
|
||
import { DiscoveryCliConfig } from '../config/config.discovery' | ||
import { ConfigReader } from '../discovery/config/ConfigReader' | ||
import { runInversion } from '../inversion/runInversion' | ||
|
||
export async function invertCommand( | ||
config: DiscoveryCliConfig, | ||
logger: Logger, | ||
): Promise<void> { | ||
if (!config.invert) { | ||
return | ||
} | ||
|
||
const { project, useMermaidMarkup, chainId } = config.invert | ||
|
||
const configReader = new ConfigReader() | ||
|
||
logger = logger.for('Inversion') | ||
logger.info('Starting') | ||
|
||
await runInversion(project, configReader, useMermaidMarkup, chainId) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters