preparation script get data from ghosties file and create rust template code

Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
Uncle Stinky 2024-10-12 13:36:17 +03:00
parent 7a4a50d588
commit 50ed40b9be
Signed by: st1nky
GPG Key ID: 016064BD97603B40

View File

@ -1,48 +1,46 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
if [ "$#" -ne 1 ]; then current_path=$(pwd)
echo "Please provide the number of initial validators!" current_script=$(realpath "$0")
exit 1 script_folder=$(dirname "$current_script")
fi project_folder=("$script_folder/..")
generate_account_id() { num_ghosties=$(grep "Local identity" $project_folder/service/ghosties | wc -l)
./target/release/ghostkey inspect ${3:-} ${4:-} "$SECRET//$1//$2" | grep "Account ID" | awk '{ print $3 }' echo "let endowed_accounts = vec!["
} for num in $(seq 2 $num_ghosties); do
account_id=$(grep -m $num "wallet" $project_folder/service/ghosties | tail -n 1 | awk '{ print $6 }')
generate_address() { public_key=$(ghost key inspect $account_id --public | grep "SS58 Address" | awk '{ print $3 }')
./target/release/ghostkey inspect ${3:-} ${4:-} "$SECRET//$1//$2" | grep "SS58 Address" | awk '{ print $3 }' echo -e "\t// $public_key"
} echo -e "\thex![\"${account_id:2}\"].into();"
generate_public_key() {
./target/release/ghostkey inspect ${3:-} ${4:-} "$SECRET//$1//$2" | grep "Public key (hex)" | awk '{ print $4 }'
}
generate_address_and_account_id() {
ACCOUNT=$(generate_account_id $1 $2 $3)
ADDRESS=$(generate_address $1 $2 $3)
if ${4:-false}; then
INTO="unchecked_into"
else
INTO="into"
fi
printf "//$ADDRESS\nhex![\"${ACCOUNT#'0x'}\"].$INTO(),"
}
V_NUM=$1
AUTHORITIES=""
for i in $(seq 1 $V_NUM); do
AUTHORITIES+="(\n"
AUTHORITIES+="$(generate_address_and_account_id $i stash)\n"
AUTHORITIES+="$(generate_address_and_account_id $i controller)\n"
AUTHORITIES+="$(generate_address_and_account_id $i babe '--scheme sr25519' true)\n"
AUTHORITIES+="$(generate_address_and_account_id $i grandpa '--scheme ed25519' true)\n"
AUTHORITIES+="$(generate_address_and_account_id $i authority_discovery '--scheme sr25519' true)\n"
AUTHORITIES+="$(generate_address_and_account_id $i slow_clap '--scheme sr25519' true)\n"
AUTHORITIES+="),\n"
done done
echo "];"
echo -e "\n"
printf "$AUTHORITIES" print_session_key() {
echo -e "\t\t// $1"
echo -e "\t\thex![\"$2\"].$3(),"
}
echo "let initial_authorities: Vec<("
echo -e "\tAccountId,"
echo -e "\tAccountId,"
echo -e "\tBabeId,"
echo -e "\tGrandpaId,"
echo -e "\tAuthorityDiscoveryId,"
echo -e "\tSlowClapId,"
echo ")> = vec!["
for num in $(seq 2 $num_ghosties); do
echo -e "\t("
for key_word in $(echo stash stash babe gran audi slow); do
account_id=$(grep -m $num $key_word $project_folder/service/ghosties | tail -n 1 | awk '{ print $7 }')
public_key=$(ghost key inspect $account_id --public | grep "SS58 Address" | awk '{ print $3 }')
postfix="unchecked_into"
if [ $key_word = "stash" ]; then
postfix="into"
fi
print_session_key $public_key $account_id $postfix
done
echo -e "\t),"
done
echo "];"