embark-etherscan-verifier/index.js

76 lines
2.8 KiB
JavaScript
Raw Normal View History

2019-01-16 19:11:44 +00:00
/*global require, module*/
const FlattenerVerifier = require('./lib/FlattenerVerifier');
2019-01-16 20:20:16 +00:00
2019-01-16 19:11:44 +00:00
module.exports = (embark) => {
function createVerifier() {
return new FlattenerVerifier({
optimize: embark.config.embarkConfig.options.solc.optimize,
optimizeRuns: embark.config.embarkConfig.options.solc['optimize-runs'],
contractsFiles: embark.config.contractsFiles,
solcVersion: embark.config.embarkConfig.versions.solc,
getWeb3DeployObject: (contract, cb) => {
embark.events.request('deploy:contract:object', contract, cb);
},
getAllContracts: (cb) => {
embark.events.request('contracts:all', cb);
},
getContractByName: (contractName, cb) => {
embark.events.request("contracts:contract", contractName, (contract) => {
cb(null, contract);
});
},
getNetworkId: (cb) => {
embark.events.request("blockchain:networkId", (networkId) => {
cb(null, networkId);
});
}
});
}
2019-01-16 20:20:16 +00:00
embark.registerConsoleCommand({
description: "Flattens all or some of your contracts so that they can be verified on Etherscan\n\t\tYou can specify which contract to flatten by using their contract name. For multiple contracts, separate them using a comma",
2019-01-16 19:11:44 +00:00
matches: (cmd) => {
2019-01-17 16:30:36 +00:00
const [commandName] = cmd.split(' ');
2019-01-16 19:11:44 +00:00
return commandName === 'flatten';
},
usage: "flatten or flatten [contracts]",
2019-01-16 19:11:44 +00:00
process: (cmd, callback) => {
const [, contractNames] = cmd.split(' ');
if (contractNames) {
embark.logger.info('Flattening ' + contractNames);
2019-01-16 19:11:44 +00:00
} else {
embark.logger.info('Flattening all contracts');
2019-01-16 19:11:44 +00:00
}
createVerifier().flatten(contractNames, callback);
2019-01-16 19:11:44 +00:00
}
});
2019-01-17 20:09:09 +00:00
2019-01-18 15:50:04 +00:00
const etherscanKeyDocsLink = 'https://etherscancom.freshdesk.com/support/solutions/articles/35000022163-i-need-an-api-key';
2019-01-17 20:09:09 +00:00
embark.registerConsoleCommand({
description: `Verifies a contract on Etherscan using you contract configuration\n\t\tRequires an Etherscan API key.\n\t\tSee: ${etherscanKeyDocsLink}`,
2019-01-17 20:09:09 +00:00
matches: (cmd) => {
const [commandName] = cmd.split(' ');
return commandName === 'verify';
},
usage: "verify [apiKey] [contractName]",
2019-01-17 20:09:09 +00:00
process: (cmd, callback) => {
2019-01-18 20:19:49 +00:00
const [, apiKey, contractName] = cmd.split(' ');
2019-01-17 20:09:09 +00:00
2019-01-18 15:50:04 +00:00
if (!apiKey || !contractName) {
embark.logger.error('Missing argument. Please provide your Etherscan API key and the contract name'.red);
embark.logger.error(`You can get an API key using this tutorial: ${etherscanKeyDocsLink}`.cyan);
return callback();
}
if (!embark.config.embarkConfig.versions.solc) {
return callback(null, 'solc version not present in embarkjs.json. Please add it to versions.solc'.red);
}
createVerifier().verify(apiKey, contractName, callback);
2019-01-17 20:09:09 +00:00
}
});
2019-01-16 19:11:44 +00:00
};