Skip to content
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

A0-1352: Add clean script #624

Merged
merged 3 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Maybe end the file with a newline, it's polite.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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
68 changes: 68 additions & 0 deletions contracts/scripts/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

set -euo pipefail

# --- FUNCTIONS

function terminate_contract {
local contract_name=$1
local contract_dir=$2
Marcin-Radecki marked this conversation as resolved.
Show resolved Hide resolved
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-)
Marcin-Radecki marked this conversation as resolved.
Show resolved Hide resolved
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