forked from open-web3-stack/parachain-launch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
forked.generated.sh
84 lines (70 loc) · 2.97 KB
/
forked.generated.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
# Parachin chains configurataion files
FORKED_CONFIG_FILE=${FORKED_CONFIG_FILE:-"config.parachain.agung.forked.yml"}
RPC_ENDPOINT=${RPC_ENDPOINT:-"https://rpcpc1-qa.agung.peaq.network"}
DOCKER_COMPOSE_FOLDER=${DOCKER_COMPOSE_FOLDER:-"yoyo"}
FORK_FOLDER=${FORK_FOLDER:="path-not-exist"}
RELAY_CHAIN_CONFIG_FILE=${RELAY_CHAIN_CONFIG_FILE:-"rococo-local.json"}
extract_parachain_spec() {
local input_file="$1"
local base=""
local id=""
local found=false
while IFS= read -r line; do
if [ "$found" = false ] && echo "$line" | grep -q "base:"; then
base=$(echo "$line" | awk -F ': ' '{print $2}' | sed 's/ *#.*//')
elif [ "$found" = false ] && echo "$line" | grep -q "id:"; then
id=$(echo "$line" | awk -F ': ' '{print $2}' | sed 's/ *#.*//')
found=true
fi
done < "$input_file"
if [ "$found" = true ] && [ -n "$base" ] && [ -n "$id" ]; then
local json_data="$base-$id.json"
echo "$json_data"
else
echo "Error: failed to extract 'base' and 'id' values"
exit 1
fi
}
real_path=$(realpath "$DOCKER_COMPOSE_FOLDER")
if [ "$real_path" = "/" ]; then
echo "Please reset the DOCKER_COMPOSE_FOLDER, $DOCKER_COMPOSE_FOLDER, variable in the script"
exit 1
fi
# Below variables are internal used, no need to change it
# These files are generated by the parachain-launch
# But below files are changed by the configuration
now_parachain_file_name=$(extract_parachain_spec "$FORKED_CONFIG_FILE")
host_relay_chain_config_file=${DOCKER_COMPOSE_FOLDER}/"${RELAY_CHAIN_CONFIG_FILE}"
polkadot_image=`cat ${FORKED_CONFIG_FILE} | grep image | grep polkadot | awk -F': ' '{print $2}' | awk '{print $1}'`
if command -p docker-compose >/dev/null 2>&1
then
docker_compose_cmd="docker-compose"
else
docker_compose_cmd="docker compose"
fi
# Stop the docker-compose and regenerate
(cd ${DOCKER_COMPOSE_FOLDER}; ${docker_compose_cmd} down -v) || true
rm -rf ${DOCKER_COMPOSE_FOLDER} || true
(./bin/parachain-launch generate --config="${FORKED_CONFIG_FILE}" --output=${DOCKER_COMPOSE_FOLDER})
# Copy file to the fork position
cp ${DOCKER_COMPOSE_FOLDER}/$now_parachain_file_name $FORK_FOLDER/parachain.plaintext.config
# Run the fork
( \
cd fork-off-substrate; \
env ALICE=1 \
SOURCE_PATH=${FORK_FOLDER} \
RPC_ENDPOINT=${RPC_ENDPOINT}\
sh forked.generated.sh; \
)
# Copy the forked file to the parachain-launch folder
cp $FORK_FOLDER/output/fork.json ${DOCKER_COMPOSE_FOLDER}/$now_parachain_file_name
new_genesis_code=$(cat $FORK_FOLDER/output/fork.json.genesis)
# Replace the rococo's parchain genesis file
sed -i "0,/\"genesis_head\": \".*\"/s//\"genesis_head\": \"$new_genesis_code\"/" ${host_relay_chain_config_file}.original.json
PWD=`pwd`
docker run --rm -v "${PWD}/${host_relay_chain_config_file}.original.json":/${RELAY_CHAIN_CONFIG_FILE} ${polkadot_image} build-spec --raw --chain=/${RELAY_CHAIN_CONFIG_FILE} --disable-default-bootnode > ${host_relay_chain_config_file}
( \
cd ${DOCKER_COMPOSE_FOLDER}; \
${docker_compose_cmd} up -d --build --remove-orphans; \
)