Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new options added #51

Merged
merged 1 commit into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/node_modules
test/
18 changes: 11 additions & 7 deletions bin/sol-verifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ const constructParams = require('./../utils/constructParams');

program
.version(require('../package.json').version, '-v, --version')
.option('-k, --key <etherscan-api-key>', 'Add Etherscan API Key (recommended but optional)')
.option('-c, --contract <path-to-solidity-contract-file>', 'Add Contract File Path (required)')
.option('-a, --address <contract-address>', 'Add Address of Deployed Contract (required)')
.option('-n, --network <network>', 'Add Ethereum Network on Which Contract is deployed (if applicable)')
.option('-N, --contractName <contract-name>', 'Add Contract Name if Passed File Contains More Than One Contract (if applicable)') // eslint-disable-line max-len
.option('-p, --constructParams [param1, param2,...]', 'Add Constructor Parameter Values Same as in Deployment (if applicable)') // eslint-disable-line max-len
.option('-r, --runs <runs>', 'Add Optimizer Runs (optional, default 200)')
.option('-k, --key <etherscan-api-key>', 'Etherscan API Key (recommended but optional)')
.option('-c, --contract <path-to-solidity-contract-file>', 'Contract File Path (required)')
.option('-a, --address <contract-address>', 'Address of Deployed Contract (required)')
.option('-n, --network <network>', 'Ethereum Network on Which Contract is deployed (if applicable)')
.option('-N, --contractName <contract-name>', 'Contract Name if Passed File Contains More Than One Contract (if applicable)') // eslint-disable-line max-len
.option('-p, --constructParams [param1, param2,...]', 'Constructor Parameter Values Same as in Deployment (if applicable)') // eslint-disable-line max-len
.option('-r, --runs <runs>', 'Optimizer Runs (optional, default 200)')
.option('-e, --evmVersion <evm-version>', 'See valid options: https://solidity.readthedocs.io/en/latest/using-the-compiler.html#target-options (optional, default compiler-default)') // eslint-disable-line max-len
.option('-l, --licenseType <license-type>', 'Valid codes 1-12, see https://etherscan.io/contract-license-types (optional, default 1=No License)') // eslint-disable-line max-len
.option('-o, --optimize', 'Add This Flag to Optimize The Contract (optional)')
.parse(process.argv);

Expand Down Expand Up @@ -61,6 +63,8 @@ program
contractName : program.contractName,
cvalues : program.constructParams,
runs : program.runs,
evmVersion : program.evmVersion,
licenseType : program.licenseType,
optimizationFlag: program.optimize,
};
try{
Expand Down
23 changes: 10 additions & 13 deletions lib/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ const hasFallback = require('./../utils/hasFallback');

module.exports.verify = async (data, cli = false) => {
try{
const { key, path, contractAddress, network, contractName, cvalues, runs, optimizationFlag } = data;

const { key, path, contractAddress, network, contractName, cvalues, evmVersion } = data;
let { runs, licenseType, optimizationFlag } = data;
if(Object.keys(map.urls).indexOf(network) > -1){
let oFlag = 0;
let name;
let abiEncodedParams;
let parsedData;
let optimizerRuns = 200;
const contractSource = await straightener.straighten(path);
const ast = parser.parse(contractSource);
const nodes = ast.children;
Expand Down Expand Up @@ -71,25 +69,24 @@ module.exports.verify = async (data, cli = false) => {
}else
throw new Error('Constructor Found!!! Please Provide --constructParams Option');
}
else
abiEncodedParams = '';

if(runs)
optimizerRuns = runs;

if(optimizationFlag)
oFlag = 1;
runs = runs ? runs : 200;
licenseType = licenseType ? licenseType : 1;
optimizationFlag = optimizationFlag ? 1 : 0;

const data = {
apikey: key,
module: 'contract',
action: 'verifysourcecode',
contractaddress: contractAddress,
sourceCode: contractSource,
codeformat: 'solidity-single-file',
contractname: name,
compilerversion: compiler,
optimizationUsed: oFlag,
runs: optimizerRuns,
optimizationUsed: optimizationFlag,
runs: runs,
evmVersion: evmVersion,
licenseType: licenseType,
constructorArguements: abiEncodedParams,
};

Expand Down
4 changes: 3 additions & 1 deletion test/sol-verifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('sol-verifier', () => {
});
});

describe('Compiling & Verifying Sample.sol by enabling optimization & runs as 2000', () => {
describe('Compiling & Verifying Sample.sol with all explicit options', () => {
let contractAddress;
let contractName;
let network;
Expand All @@ -122,6 +122,8 @@ describe('sol-verifier', () => {
contractAddress: contractAddress,
network : network,
runs : 2000,
evmVersion: 'byzantium',
licenseType: 3,
optimizationFlag: true, // Optimization Enabled
};
const response = await Verifier.verifyContract(sampleData);
Expand Down