2022-04-02 06:30:40 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
usage="Usage:
|
|
|
|
$(basename "$0") [-h] [-n network] <.wasm file> <code id> -- Verify that the deployed on-chain bytecode matches the local object file
|
|
|
|
|
|
|
|
where:
|
|
|
|
-h show this help text
|
|
|
|
-n set the network (mainnet, testnet, devnet. defaults to \$NETWORK if set)"
|
|
|
|
|
2024-01-29 13:38:47 -08:00
|
|
|
network=${NETWORK:-""}
|
2022-04-02 06:30:40 -07:00
|
|
|
while getopts ':hn:' option; do
|
|
|
|
case "$option" in
|
|
|
|
h) echo "$usage"
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
n) network=$OPTARG
|
|
|
|
;;
|
|
|
|
:) printf "missing argument for -%s\n" "$OPTARG" >&2
|
|
|
|
echo "$usage" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
\?) printf "illegal option: -%s\n" "$OPTARG" >&2
|
|
|
|
echo "$usage" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND - 1))
|
|
|
|
|
|
|
|
|
|
|
|
case "$network" in
|
2024-01-29 13:38:47 -08:00
|
|
|
mainnet) url="https://terra-classic-lcd.publicnode.com";;
|
2022-04-02 06:30:40 -07:00
|
|
|
testnet) url="https://bombay-lcd.terra.dev";;
|
|
|
|
devnet) url="http://localhost:1317";;
|
|
|
|
*) printf "Network not set. Specify with -n\n" >&2
|
|
|
|
echo "$usage" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
[ $# -ne 2 ] && { echo "$usage" >&2; exit 1; }
|
|
|
|
obj_file=$1
|
|
|
|
code_id=$2
|
|
|
|
|
|
|
|
|
2024-01-29 17:05:23 -08:00
|
|
|
hash1=`curl "$url"/cosmwasm/wasm/v1/code/"$code_id" --silent | jq '.code_info.data_hash' -r | tr '[:upper:]' '[:lower:]'`
|
2022-04-02 06:30:40 -07:00
|
|
|
hash2=`sha256sum $obj_file | cut -f1 -d' '`
|
|
|
|
|
|
|
|
echo "Deployed bytecode hash (on $network):"
|
|
|
|
echo $hash1
|
|
|
|
echo "$obj_file hash:"
|
|
|
|
echo $hash2
|
|
|
|
|
|
|
|
if [ "$hash1" == "$hash2" ]; then
|
|
|
|
printf "\033[0;32mSuccessfully verified\033[0m\n";
|
|
|
|
exit 0;
|
|
|
|
else
|
|
|
|
printf "\033[0;31mFailed to verify\033[0m\n";
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|