truffle-plugin-verify
Advanced tools
Comparing version 0.1.0-alpha1 to 0.1.0-alpha2
{ | ||
"name": "truffle-plugin-verify", | ||
"version": "0.1.0-alpha1", | ||
"version": "0.1.0-alpha2", | ||
"description": "", | ||
@@ -20,2 +20,3 @@ "repository": "https://github.com/rkalis/ethroulette", | ||
"dependencies": { | ||
"await-sleep": "0.0.1", | ||
"axios": "^0.18.0", | ||
@@ -22,0 +23,0 @@ "querystring": "^0.2.0" |
@@ -45,8 +45,4 @@ # truffle-plugin-verify | ||
This will return a `guid` which can be checked to see if the verification succeeded. This will be automated in a future release. | ||
This can take some time, and will eventually either return `Pass - Verified` or `Fail - Unable to verify`. | ||
``` | ||
https://api.etherscan.io/api?module=contract&action=checkverifystatus&apikey=MY_API_KEY&guid=MY_GUID | ||
``` | ||
## Limitations & Roadmap | ||
@@ -62,3 +58,2 @@ This plugin is in a very early version, so there is still a lot missing. Below is a non-exhaustive list of features that are currently missing from the plugin, that will be added in a later release. | ||
* The plugin assumes it can find build artifacts under the `build/contracts/` directory (i.e. no support for custom paths) | ||
* The plugin has no support to automatically check the verification status back from Etherscan | ||
* The plugin can only verify one smart contract at a time, instead of automatically verifying all deployed contracts | ||
@@ -65,0 +60,0 @@ |
const axios = require('axios') | ||
const querystring = require('querystring') | ||
const sleep = require('await-sleep') | ||
@@ -9,2 +10,42 @@ const API_URLS = { | ||
const VerificationStatus = { | ||
FAILED: 'Fail - Unable to verify', | ||
SUCCESS: 'Pass - Verified', | ||
PENDING: 'Pending in queue' | ||
} | ||
const sendVerifyRequest = async (apiUrl, apiKey, networkId, artifact) => { | ||
return await axios.post( | ||
apiUrl, | ||
querystring.stringify({ | ||
apikey: apiKey, | ||
module: 'contract', | ||
action: 'verifysourcecode', | ||
// TODO: detect deployed networks | ||
contractaddress: artifact.networks[`${networkId}`].address, | ||
// TODO: Flatten multi-level contracts | ||
sourceCode: artifact.source, | ||
contractname: artifact.contractName, | ||
compilerversion: `v${artifact.compiler.version.replace('.Emscripten.clang', '')}`, | ||
optimizationUsed: 0, | ||
runs: 200, | ||
// constructorArguements: '$('#constructorArguements').val()' | ||
}) | ||
) | ||
} | ||
const verificationStatus = async (apiUrl, apiKey, guid) => { | ||
while (true) { | ||
await sleep(1000) | ||
const verificationResult = await axios.get( | ||
`${apiUrl}?module=contract&action=checkverifystatus&apikey=${apiKey}&guid=${guid}` | ||
) | ||
if (verificationResult.data.result !== VerificationStatus.PENDING) { | ||
return verificationResult.data.result | ||
} | ||
} | ||
} | ||
module.exports = async (config) => { | ||
@@ -17,28 +58,12 @@ const networkId = (config.networks[config.network] || {}).network_id || 4 | ||
const artifact = require(artifactPath) | ||
const compilerVersion = `v${artifact.compiler.version.replace('.Emscripten.clang', '')}` | ||
try { | ||
const res = await axios.post( | ||
apiUrl, | ||
querystring.stringify({ | ||
apikey: apiKey, | ||
module: 'contract', | ||
action: 'verifysourcecode', | ||
// TODO: detect deployed networks | ||
contractaddress: artifact.networks[`${networkId}`].address, | ||
// TODO: Flatten multi-level contracts | ||
sourceCode: artifact.source, | ||
contractname: artifact.contractName, | ||
compilerversion: compilerVersion, | ||
optimizationUsed: 0, | ||
runs: 200, | ||
// constructorArguements: '$('#constructorArguements').val()' | ||
}) | ||
) | ||
// TODO: Auto-checking status & better error handling | ||
const res = await sendVerifyRequest(apiUrl, apiKey, networkId, artifact) | ||
// TODO: Better error handling | ||
if (res.data && res.data.status === '1') { | ||
const guid = res.data.result | ||
console.log(`You can check your verification status with this guid: ${guid}`) | ||
const status = await verificationStatus(apiUrl, apiKey, res.data.result) | ||
console.log(status) | ||
} else { | ||
console.log(`Something went wrong\n${JSON.stringify(res.data)}`) | ||
console.log(res.data.result) | ||
} | ||
@@ -45,0 +70,0 @@ } catch (e) { |
6132
67
3
61
+ Addedawait-sleep@0.0.1
+ Addedawait-sleep@0.0.1(transitive)