dop-stick
Version:
Source control tooling for versionable-upgradeable smart contracts
82 lines • 3.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContractVerifier = void 0;
const logger_1 = require("./logsAndMetrics/core/logger");
const etherscan_1 = require("./verification/etherscan");
const terminal_1 = require("./logsAndMetrics/core/terminal");
class ContractVerifier {
constructor(config) {
var _a, _b;
this.config = config;
this.services = [];
// Initialize verification services
if ((_b = (_a = config.verification) === null || _a === void 0 ? void 0 : _a.etherscan) === null || _b === void 0 ? void 0 : _b.apiKey) {
this.services.push(new etherscan_1.EtherscanVerifier(config.verification.etherscan.apiKey));
}
}
async verify(data) {
const service = this.getVerificationService(data.network.chainId);
if (!service) {
throw new Error('No verification service available for this network');
}
try {
// Prepare verification input
const input = await this.prepareVerificationInput(data);
// Submit verification request
terminal_1.Terminal.writeLine('Submitting contract for verification...');
const verificationId = await service.verify(input);
// Wait for verification result
await this.checkVerificationStatus(verificationId, service);
}
catch (error) {
logger_1.Logger.error('Contract verification failed:', error);
throw error;
}
}
getVerificationService(chainId) {
return this.services.find(service => service.getSupportedNetworks().includes(chainId));
}
async prepareVerificationInput(data) {
var _a, _b;
// Read source code from artifacts
const sourceCode = await this.getSourceCode(data.address);
return {
address: data.address,
constructorArgs: Object.values(data.constructorArgs),
contractName: ((_b = (_a = this.config.contracts) === null || _a === void 0 ? void 0 : _a.diamond) === null || _b === void 0 ? void 0 : _b.name) || 'Diamond',
sourceCode,
compiler: {
version: data.compilerVersion || '0.8.0',
optimization: data.optimizationUsed,
runs: data.runs,
},
network: {
chainId: data.network.chainId,
name: data.network.name,
},
};
}
async checkVerificationStatus(verificationId, service, maxAttempts = 10) {
for (let attempt = 0; attempt < maxAttempts; attempt++) {
const status = await service.checkStatus(verificationId);
switch (status) {
case 'success':
terminal_1.Terminal.writeLine('Contract verified successfully!');
return;
case 'failed':
throw new Error('Contract verification failed');
case 'pending':
terminal_1.Terminal.writeLine('Verification pending... waiting 5 seconds');
await new Promise(resolve => setTimeout(resolve, 5000));
break;
}
}
throw new Error('Verification timed out');
}
async getSourceCode(address) {
// TODO: Implement source code retrieval from artifacts
throw new Error('Source code retrieval not implemented');
}
}
exports.ContractVerifier = ContractVerifier;
//# sourceMappingURL=contractVerifier.js.map