Skip to content

Commit

Permalink
A0-1352: Add clean script (#624)
Browse files Browse the repository at this point in the history
* creating clean contract script

* clean script working

* newline add
  • Loading branch information
fbielejec committed Sep 20, 2022
1 parent 5ded8fc commit 70a7b0d
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 5 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
target
!target/release/aleph-node
!bin/cliain/target/release/cliain

4 changes: 4 additions & 0 deletions bin/cliain/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/target
target
docker/data
!target/release/cliain
8 changes: 8 additions & 0 deletions bin/cliain/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
11 changes: 11 additions & 0 deletions contracts/marketplace/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
67 changes: 67 additions & 0 deletions contracts/scripts/clean.sh
Original file line number Diff line number Diff line change
@@ -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 $?
22 changes: 17 additions & 5 deletions contracts/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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`
Expand Down

0 comments on commit 70a7b0d

Please sign in to comment.