dop-stick
Version:
Source control tooling for versionable-upgradeable smart contracts
120 lines • 5.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.infoCommand = void 0;
const index_1 = require("../../index");
const logger_1 = require("../../utils/logsAndMetrics/core/logger");
const config_1 = require("../utils/config");
const introAdapter_1 = require("../../utils/logsAndMetrics/adapters/introAdapter");
const compilerService_1 = require("../../utils/compiler/compilerService");
/**
* Command to retrieve detailed information about a diamond contract.
*
* Usage:
* ```bash
* dopstick info [diamondAddress] [rpcUrl] [options]
* ```
*
* Arguments:
* - `diamondAddress`: The address of the diamond contract (optional if specified in env)
* - `rpcUrl`: The RPC URL to connect to the network (optional if specified in env)
*
* Options:
* - `--json`: Output only JSON format of the facets information
* - `--report`: Output only human-readable report
* - `--docs`: Generate detailed documentation for the diamond
* - `--no-cache`: Disable caching during info generation
* - `--no-compile`: Skip contract compilation
*
* Environment Variables:
* - `DIAMOND_ADDRESS`: Default diamond address if not provided as argument
* - `RPC_URL`: Default RPC URL if not provided as argument
*
* Example:
* ```bash
* dopstick info 0x123... https://eth-mainnet.g.alchemy.com/v2/YOUR-API-KEY --json
* ```
*/
exports.infoCommand = {
register: (program) => {
program
.command('info')
.description('Get detailed information about a diamond contract')
.argument('[diamondAddress]', 'The address of the diamond contract (optional if in env)')
.argument('[rpcUrl]', 'The RPC URL (optional if in env)')
.option('--json', 'Output only JSON format')
.option('--report', 'Output only human-readable report')
.option('--docs', 'Generate detailed documentation')
.option('--no-cache', 'Disable caching during info generation')
.option('--no-compile', 'Skip contract compilation')
.action(async (diamondAddress, rpcUrl, options) => {
try {
const intro = new introAdapter_1.IntroAdapter();
await intro.playIntro("");
const dopStickConfig = (0, config_1.loadConfig)({ requireUpgrades: false });
if (options.compile === false) {
dopStickConfig.compiler = {
...dopStickConfig.compiler,
skip: true
};
logger_1.Logger.info('Compilation skipped via CLI option');
}
else {
await compilerService_1.CompilerService.ensureCompiled(dopStickConfig.compiler);
}
logger_1.Logger.debug('Configuration:', {
dopStickConfig,
providerConfig: { diamondAddress, rpcUrl },
useCache: !options.noCache,
environment: {
DEBUG: process.env.DEBUG,
RPC_URL: process.env.RPC_URL,
DIAMOND_ADDRESS: process.env.DIAMOND_ADDRESS
}
});
const diamond = new index_1.DiamondInfo({ diamondAddress, rpcUrl }, {
...dopStickConfig,
cache: {
...dopStickConfig === null || dopStickConfig === void 0 ? void 0 : dopStickConfig.cache,
enabled: options.cache
}
}, true);
if (options.docs) {
await diamond.generateDocumentation();
}
else {
const facetsInfo = await diamond.getDetailedFacetsInfo();
if (options.json) {
console.log(JSON.stringify(facetsInfo, null, 2));
}
else if (options.report) {
const report = await diamond.getFacetsReport();
console.log(report);
}
else {
console.log('\nStructured Data:');
console.log(JSON.stringify(facetsInfo, null, 2));
console.log('\nHuman Readable Report:');
const report = await diamond.getFacetsReport();
console.log(report);
}
}
process.exit(0);
}
catch (error) {
if (error instanceof Error) {
logger_1.Logger.error('Failed to get diamond info:', error.message);
logger_1.Logger.debug('Error details:', {
name: error.name,
message: error.message,
stack: error.stack
});
}
else {
logger_1.Logger.error('Failed to get diamond info:', String(error));
}
process.exit(1);
}
});
}
};
//# sourceMappingURL=info.js.map