Skip to content

fix dapp verify-contract #287

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

Merged
merged 1 commit into from
Oct 19, 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
3 changes: 2 additions & 1 deletion src/dapp/libexec/dapp/dapp-create
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ address=$(set -x; seth send --create "$bin" "${type/constructor/${1##*/}}" "${@:

[[ $DAPP_VERIFY_CONTRACT ]] && {
echo >&2 "Verifying contract at $address"
path=$(sed 's|\/|/|g' "$DAPP_JSON" | sed "s/.*\"\(.*:${1}\)\".*/\1/g")
sleep 5
dapp verify-contract "$1" "$address" || true
dapp verify-contract "$path" "$address" || true
}

echo "$address"
62 changes: 36 additions & 26 deletions src/dapp/libexec/dapp/dapp-verify-contract
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,26 @@ file=$(jshon <<<"$meta" -e settings -e compilationTarget -k)
optimized=$(jshon <<<"$meta" -e settings -e optimizer -e enabled -u)
runs=$(jshon <<<"$meta" -e settings -e optimizer -e runs -u)

version=v"$version"
# Etherscan requires leading 'v' which isn't in the artifacts
version="v${version}"

# Get the list of supported solc versions and compare
# Etherscan uses the js solc, which is not guaranteed to match the C distribution signature
version_list=$(curl -fsS "https://raw.githubusercontent.com/ethereum/solc-bin/gh-pages/bin/list.txt")

# There have been a couple of instances where the solc js release used by
# Etherscan does not match the tag of the C distributions.
if [[ $version_list != *"$version"* ]]; then
regex="(.+commit+.)"
# Version incompatible with js release
echo "Compiler version $version is not compatible with etherscan"
if [[ $version =~ $regex ]]; then
version_proto=${BASH_REMATCH[1]}
version=$(echo "$version_list" | grep -o "${version_proto}\{8\}")
echo "Attempting ${version}"
fi
fi

if [[ "$optimized" = "true" ]]; then
optimized=1
else
Expand All @@ -47,7 +66,7 @@ fi

params=(
"module=contract" "action=verifysourcecode"
"contractname=$name" "contractaddress=$address}"
"contractname=$name" "contractaddress=$address"
"optimizationUsed=$optimized" "runs=$runs"
"apikey=$ETHERSCAN_API_KEY"
)
Expand All @@ -65,44 +84,35 @@ 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") -X POST)

status=$(jshon <<<"$response" -e status -u)
#message=$(jshon <<<"$response" -e message -u)
guid=$(jshon <<<"$response" -e result -u)
message=$(jshon <<<"$response" -e message -u)
count=$((count + 1))

[[ $guid = "Contract source code already verified" ]] && {
echo >&2 "$guid"
echo >&2 "Go to $ETHERSCAN_URL/$2#code"
exit 1
}
[[ $status = 1 ]] && break;
sleep 5
done

[[ $status = 0 ]] && {
echo >&2 "There was an error verifying this contract."
echo >&2 "Response: $guid"
echo >&2 "Response: $message"
exit 1
}

count=0
while [ $count -lt 5 ]; do
sleep 10
response=$(curl -fsS "$ETHERSCAN_API_URL" \
-d "module=contract&action=checkverifystatus&guid=$guid")
sleep 20
response=$(curl -fsS "$ETHERSCAN_API_URL" \
-d "module=contract&action=checkverifystatus&guid=$guid")

status=$(jshon <<<"$response" -e status -u)
# message=$(jshon <<<"$response" -e message -u)
result=$(jshon <<<"$response" -e result -u)

[[ $status = 1 ]] && {
echo >&2 "$result"
echo >&2 "Go to $ETHERSCAN_URL/$2#code"
exit 0
}
count=$((count + 1))
done
status=$(jshon <<<"$response" -e status -u)
result=$(jshon <<<"$response" -e result -u)

[[ $status = 1 ]] && {
echo >&2 "$result"
echo >&2 "Go to $ETHERSCAN_URL/$2#code"
exit 0
}