diff --git a/.dockerignore b/.dockerignore index e3a488ab34..3d54c2d59a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,3 +2,4 @@ target !target/release/aleph-node !bin/cliain/target/release/cliain + diff --git a/bin/cliain/.dockerignore b/bin/cliain/.dockerignore new file mode 100644 index 0000000000..acc89da10f --- /dev/null +++ b/bin/cliain/.dockerignore @@ -0,0 +1,4 @@ +**/target +target +docker/data +!target/release/cliain \ No newline at end of file diff --git a/bin/cliain/Dockerfile b/bin/cliain/Dockerfile index 72e12ab18e..052889b915 100644 --- a/bin/cliain/Dockerfile +++ b/bin/cliain/Dockerfile @@ -1,5 +1,13 @@ FROM ubuntu:jammy-20220531 +RUN apt update && \ + apt install wget -y && \ + apt clean && \ + rm -rf /var/lib/apt/lists/* + +RUN wget http://nz2.archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.16_amd64.deb +RUN dpkg -i libssl1.1_1.1.1f-1ubuntu2.16_amd64.deb + COPY target/release/cliain /usr/local/bin RUN chmod +x /usr/local/bin/cliain diff --git a/contracts/marketplace/lib.rs b/contracts/marketplace/lib.rs index 827c88bf96..7c85f6d876 100644 --- a/contracts/marketplace/lib.rs +++ b/contracts/marketplace/lib.rs @@ -235,6 +235,17 @@ pub mod marketplace { Ok(()) } + /// Terminates the contract + /// + /// Should only be called by the contract Owner + #[ink(message)] + pub fn terminate(&mut self) -> Result<(), Error> { + let caller = self.env().caller(); + let this = self.env().account_id(); + Self::ensure_role(Role::Owner(this))?; + self.env().terminate_contract(caller) + } + fn current_price(&self) -> Balance { let block = self.env().block_number(); let elapsed = block.saturating_sub(self.current_start_block.into()); diff --git a/contracts/scripts/clean.sh b/contracts/scripts/clean.sh new file mode 100755 index 0000000000..1bcdf01f3e --- /dev/null +++ b/contracts/scripts/clean.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +set -euo pipefail + +# --- FUNCTIONS + +function terminate_contract { + local contract_name=$1 + local contract_dir=$2 + local contract_address=$(get_address $contract_name) + + cd "$CONTRACTS_PATH"/"$contract_dir" + cargo contract call --url "$NODE" --contract $contract_address --message terminate --suri "$AUTHORITY_SEED" +} + +function get_address { + local contract_name=$1 + cat "$CONTRACTS_PATH"/addresses.json | jq --raw-output ".$contract_name" +} + +function remove_contract_code { + local code_hash=$(cat "$CONTRACTS_PATH"/addresses.json | jq --raw-output ".$1") + docker run --network host -e RUST_LOG=info "${CLIAIN_IMAGE}" --seed "$AUTHORITY_SEED" --node "$NODE" contract-remove-code --code-hash $code_hash +} + +# --- GLOBAL CONSTANTS + +CONTRACTS_PATH=$(pwd)/contracts +CLIAIN_IMAGE=public.ecr.aws/p6e8q1z1/cliain:latest + +# --- CLEAN BUTTON CONTRACT + +terminate_contract early_bird_special button +terminate_contract early_bird_special_marketplace marketplace +terminate_contract early_bird_special_ticket ticket_token +terminate_contract early_bird_special_token game_token + +echo "succesfully terminated early_bird_special" + +terminate_contract back_to_the_future button +terminate_contract back_to_the_future_ticket ticket_token +terminate_contract back_to_the_future_token game_token +terminate_contract back_to_the_future_marketplace marketplace + +echo "succesfully terminated back_to_the_future" + +terminate_contract the_pressiah_cometh button +terminate_contract the_pressiah_cometh_ticket ticket_token +terminate_contract the_pressiah_cometh_token game_token +terminate_contract the_pressiah_cometh_marketplace marketplace + +echo "succesfully terminated the_pressiah_cometh" + +remove_contract_code button_code_hash +remove_contract_code ticket_token_code_hash +remove_contract_code game_token_code_hash +remove_contract_code marketplace_code_hash + +echo "succesfully removed code hashes" + +# remove access control as last +terminate_contract access_control access_control +remove_contract_code access_control_code_hash + +echo "succesfully terminated and removed AccessControl" + +exit $? diff --git a/contracts/scripts/deploy.sh b/contracts/scripts/deploy.sh index fe34241dff..87148062aa 100755 --- a/contracts/scripts/deploy.sh +++ b/contracts/scripts/deploy.sh @@ -164,14 +164,12 @@ function link_bytecode() { sed -i 's/'"$placeholder"'/'"$replacement"'/' "target/ink/$contract.contract" } - # --- GLOBAL CONSTANTS NODE_IMAGE=public.ecr.aws/p6e8q1z1/aleph-node:latest CONTRACTS_PATH=$(pwd)/contracts - # --- COMPILE CONTRACTS cd "$CONTRACTS_PATH"/access_control @@ -194,8 +192,10 @@ cargo contract build --release cd "$CONTRACTS_PATH"/access_control -CONTRACT=$(cargo contract instantiate --url "$NODE" --constructor new --suri "$AUTHORITY_SEED") -ACCESS_CONTROL=$(echo "$CONTRACT" | grep Contract | tail -1 | cut -c 15-) +ACCESS_CONTROL_CODE_HASH=$(cargo contract upload --url "$NODE" --suri "$AUTHORITY_SEED") +ACCESS_CONTROL_CODE_HASH=$(echo "$ACCESS_CONTROL_CODE_HASH" | grep hash | tail -1 | cut -c 15-) +ACCESS_CONTROL=$(cargo contract instantiate --url "$NODE" --constructor new --suri "$AUTHORITY_SEED") +ACCESS_CONTROL=$(echo "$ACCESS_CONTROL" | grep Contract | tail -1 | cut -c 15-) ACCESS_CONTROL_PUBKEY=$(docker run --rm --entrypoint "/bin/sh" "${NODE_IMAGE}" -c "aleph-node key inspect $ACCESS_CONTROL" | grep hex | cut -c 23- | cut -c 3-) echo "access control contract address: $ACCESS_CONTROL" @@ -259,6 +259,12 @@ jq -n --arg early_bird_special "$EARLY_BIRD_SPECIAL" \ --arg the_pressiah_cometh_ticket "$THE_PRESSIAH_COMETH_TICKET" \ --arg the_pressiah_cometh_token "$THE_PRESSIAH_COMETH_TOKEN" \ --arg the_pressiah_cometh_marketplace "$THE_PRESSIAH_COMETH_MARKETPLACE" \ + --arg button_code_hash "$BUTTON_CODE_HASH" \ + --arg ticket_token_code_hash "$TICKET_TOKEN_CODE_HASH" \ + --arg game_token_code_hash "$GAME_TOKEN_CODE_HASH" \ + --arg marketplace_code_hash "$MARKETPLACE_CODE_HASH" \ + --arg access_control "$ACCESS_CONTROL" \ + --arg access_control_code_hash "$ACCESS_CONTROL_CODE_HASH" \ '{early_bird_special: $early_bird_special, early_bird_special_marketplace: $early_bird_special_marketplace, early_bird_special_ticket: $early_bird_special_ticket, @@ -270,7 +276,13 @@ jq -n --arg early_bird_special "$EARLY_BIRD_SPECIAL" \ the_pressiah_cometh: $the_pressiah_cometh, the_pressiah_cometh_ticket: $the_pressiah_cometh_ticket, the_pressiah_cometh_token: $the_pressiah_cometh_token, - the_pressiah_cometh_marketplace: $the_pressiah_cometh_marketplace}' > addresses.json + the_pressiah_cometh_marketplace: $the_pressiah_cometh_marketplace, + access_control: $access_control, + button_code_hash: $button_code_hash, + ticket_token_code_hash: $ticket_token_code_hash, + game_token_code_hash: $game_token_code_hash, + marketplace_code_hash: $marketplace_code_hash, + access_control_code_hash: $access_control_code_hash}' > addresses.json end=`date +%s.%N`