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

Add Multi-File Etherscan Verification Option #630

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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: 2 additions & 0 deletions src/dapp/libexec/dapp/dapp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
###
### Deployment options:
### verify verify contract on etherscan
### verify-multiple multifile verification on etherscan
###
### Contract verifying options:
### async don't wait for confirmation
Expand Down Expand Up @@ -161,6 +162,7 @@ while [[ $1 ]]; do
export HEVM_RPC=yes;;

--verify) export DAPP_VERIFY_CONTRACT=yes;;
--verify-multiple) export DAPP_VERIFY_CONTRACT_MULTIPLE=yes;;

--async) export DAPP_ASYNC=yes;;

Expand Down
5 changes: 4 additions & 1 deletion src/dapp/libexec/dapp/dapp-mk-standard-json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ for root, dirnames, filenames in os.walk(src):
tmpljson["sources"]={}
for f in files:
tmpljson["sources"][f]={}
tmpljson["sources"][f]["urls"] = [f]
if os.getenv('DAPP_VERIFY_CONTRACT_MULTIPLE') == "yes":
tmpljson["sources"][f]["content"] = [f.read()]
else:
tmpljson["sources"][f]["urls"] = [f]

if os.getenv('DAPP_REMAPPINGS') is None or os.getenv('DAPP_REMAPPINGS') == "":
tmpljson["settings"].pop("remappings", None)
Expand Down
57 changes: 39 additions & 18 deletions src/dapp/libexec/dapp/dapp-verify-contract
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ set -e

[[ $ETHERSCAN_API_KEY ]] || {
cat >&2 <<.

You need an Etherscan Api Key to verify contracts.
Create one at https://etherscan.io/myapikey

Then export it with \`export ETHERSCAN_API_KEY=xxxxxxxx'

.
exit 1
}
Expand All @@ -36,12 +33,13 @@ esac

path=${1?contractname}
name=${path#*:}
contractName=$(basename "$path")
address=${2?contractaddress}

# combined-json has a sourceList field
if [[ $(jq .sourceList "$DAPP_JSON") == null ]]; then
contract=$(<"$DAPP_JSON" jq -r ".contracts[\"${path/:*/}\"][\"$name\"]")
else
else
contract=$(<"$DAPP_JSON" jq -r ".contracts[\"$path\"]")
fi
meta=$(jshon <<<"$contract" -e metadata -u)
Expand Down Expand Up @@ -88,33 +86,56 @@ else
optimized=0
fi

params=(
if [[ $DAPP_VERIFY_CONTRACT_MULTIPLE == yes ]]; then

# Standard Input JSON

inputJSON=$(dapp mk-standard-json)

params=(
"module=contract" "action=verifysourcecode"
"contractname=$name" "contractaddress=$address"
"optimizationUsed=$optimized" "runs=$runs"
"contractname=$contractName" "contractaddress=$address"
"sourcecode=$inputJSON" "codeformat=solidity-standard-json-input"
"apikey=$ETHERSCAN_API_KEY"
)
)

else

source=$(hevm flatten --source-file "$file" --json-file "$DAPP_JSON" --dapp-root "$DAPP_ROOT")
params=(
"module=contract" "action=verifysourcecode"
"contractname=$name" "contractaddress=$address"
"optimizationUsed=$optimized" "runs=$runs"
"apikey=$ETHERSCAN_API_KEY"
)

source=$(cat <<.
// Verified using https://dapp.tools
source=$(hevm flatten --source-file "$file" --json-file "$DAPP_JSON" --dapp-root "$DAPP_ROOT")

$source
source=$(cat <<.
//Verified using https://dapp.tools
"$source"
.
)
)

fi

query=$(printf "&%s" "${params[@]}")

count=0
while [ $count -lt 5 ]; do
sleep 10

response=$(curl -fsS "$ETHERSCAN_API_URL" -d "$query" \
--data-urlencode "compilerversion=$version" \
--data-urlencode "sourceCode@"<(echo "$source") \
--data-urlencode "constructorArguements=$constructorArguments" -X POST)
# NOTE: the Arguements typo is in etherscan's API
if [[ $DAPP_VERIFY_CONTRACT_MULTIPLE == yes ]]; then
response=$(curl -fsS "$ETHERSCAN_API_URL" -d "$query" \
--data-urlencode "compilerversion=$version" \
--data-urlencode "constructorArguements=$constructorArguments" -X POST)
# NOTE: the Arguements typo is in etherscan's API
else
response=$(curl -fsS "$ETHERSCAN_API_URL" -d "$query" \
--data-urlencode "compilerversion=$version" \
--data-urlencode "sourceCode@"<(echo "$source") \
--data-urlencode "constructorArguements=$constructorArguments" -X POST)
# NOTE: the Arguements typo is in etherscan's API
fi

status=$(jshon <<<"$response" -e status -u)
guid=$(jshon <<<"$response" -e result -u)
Expand Down