From d9a0acf06dedf3e19d47aa25cbfed08079a43952 Mon Sep 17 00:00:00 2001 From: filip Date: Mon, 24 Oct 2022 19:39:03 +0200 Subject: [PATCH] check if exists before removing --- contracts/scripts/clean.sh | 31 ++++++++++++++++++++----------- contracts/scripts/deploy.sh | 1 + 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/contracts/scripts/clean.sh b/contracts/scripts/clean.sh index 077017a1fb..56f9f1e69d 100755 --- a/contracts/scripts/clean.sh +++ b/contracts/scripts/clean.sh @@ -34,19 +34,28 @@ function get_address { function remove_contract_code { local code_hash=$(cat "$CONTRACTS_PATH"/addresses.json | jq --raw-output ".$1") - local tmp_output_file="tmp_remove_contract_code" - set +e - docker rm -f remove_contract_code - timeout -k 1m 1m bash -c "docker run --network host -e RUST_LOG=info \"${CLIAIN_IMAGE}\" --seed \"$AUTHORITY_SEED\" --node \"$NODE\" contract-remove-code --code-hash $code_hash 2>&1 | tee $tmp_output_file" - grep -q "CodeNotFound\|Received ContractCodeRemoved" $tmp_output_file - if [ $? -ne 0 ]; then - echo "** Exiting with error code 1. Process has been killed after 1m and 'CodeNotFound' error has not been found in the output" - exit 1 + + if [ "None" == "$(docker run --network host -e RUST_LOG=info "$CLIAIN_IMAGE" --seed "$AUTHORITY_SEED" --node "$NODE" contract-owner-info --code-hash "$code_hash")" ]; then + echo "Contract code does not exist on chain." else - echo "** Ignoring 'CodeNotFound' error or 'Received ContractCodeRemoved' message" + echo "Contract code exists, removing" + + local tmp_output_file="tmp_remove_contract_code" + set +e + docker rm -f remove_contract_code + timeout -k 1m 1m bash -c "docker run --network host -e RUST_LOG=info \"${CLIAIN_IMAGE}\" --seed \"$AUTHORITY_SEED\" --node \"$NODE\" contract-remove-code --code-hash $code_hash 2>&1 | tee $tmp_output_file" + grep -q "CodeNotFound\|Received ContractCodeRemoved" $tmp_output_file + if [ $? -ne 0 ]; then + echo "** Exiting with error code 1. Process has been killed after 1m and 'CodeNotFound' error has not been found in the output" + exit 1 + else + echo "** Ignoring 'CodeNotFound' error or 'Received ContractCodeRemoved' message" + fi + rm -f $tmp_output_file + set -e + + fi - rm -f $tmp_output_file - set -e } # --- GLOBAL CONSTANTS diff --git a/contracts/scripts/deploy.sh b/contracts/scripts/deploy.sh index 203cb5f06f..8fdc148c02 100755 --- a/contracts/scripts/deploy.sh +++ b/contracts/scripts/deploy.sh @@ -285,5 +285,6 @@ jq -n --arg early_bird_special "$EARLY_BIRD_SPECIAL" \ end=`date +%s.%N` echo "Time elapsed: $( echo "$end - $start" | bc -l )" +cat addresses.json exit $?