#!/bin/bash

# user specific
USER_PORT=${USER_PORT:-"30000"}
RELAY_IP=${RELAY_IP:-"127.0.0.1"}
PARACHAIN_IP=${PARACHAIN_IP:-"127.0.0.1"}

# generic build variables
SPECS_FOLDER=${SPECS_FOLDER:-"specs"}
BUILD_FOLDER=${BUILD_FOLDER:-"build"}
mkdir -p $BUILD_FOLDER
TMP_FOLDER=${TMP_FOLDER:-"$BUILD_FOLDER/tmp"}
mkdir -p $TMP_FOLDER

MOONBEAM_BINARY=${MOONBEAM_BINARY:-"target/release/moonbeam"}

# filename declarations
PARACHAIN_SPEC_TEMPLATE_FILENAME=${PARACHAIN_SPEC_TEMPLATE_FILENAME:-"parachain-specs-template.json"}
PARACHAIN_SPEC_PLAIN_FILENAME=${PARACHAIN_SPEC_PLAIN_FILENAME:-"parachain-specs-plain.json"}
PARACHAIN_SPEC_RAW_FILENAME=${PARACHAIN_SPEC_RAW_FILENAME:-"parachain-specs-raw.json"}
PARACHAIN_WASM_FILENAME=${PARACHAIN_WASM_FILENAME:-"parachain-runtime.wasm"}
PARACHAIN_GENESIS_FILENAME=${PARACHAIN_GENESIS_FILENAME:-"parachain-genesis.txt"}
ROCOCO_SPEC_TEMPLATE_FILENAME=${ROCOCO_SPEC_TEMPLATE_FILENAME:-"rococo-specs-template.json"}
ROCOCO_SPEC_PLAIN_FILENAME=${ROCOCO_SPEC_PLAIN_FILENAME:-"rococo-specs-plain.json"}
ROCOCO_SPEC_RAW_FILENAME=${ROCOCO_SPEC_RAW_FILENAME:-"rococo-specs-raw.json"}

# Generic network declarations
ROCOCO_LOCAL_RAW_SPEC=${ROCOCO_LOCAL_RAW_SPEC:-"$BUILD_FOLDER/rococo-specs-raw.json"}
COMMON_NODE_KEYS=(
  0000000000000000000000000000000000000000000000000000000000000000
  1111111111111111111111111111111111111111111111111111111111111111
  2222222222222222222222222222222222222222222222222222222222222222
  3333333333333333333333333333333333333333333333333333333333333333
  4444444444444444444444444444444444444444444444444444444444444444
  5555555555555555555555555555555555555555555555555555555555555555
  6666666666666666666666666666666666666666666666666666666666666666
)
COMMON_LOCAL_IDS=(
  12D3KooWDpJ7As7BWAwRMfu1VU2WCqNjvq387JEYKDBj4kx6nXTN
  12D3KooWPqT2nMDSiXUSx5D7fasaxhxKigVhcqfkKqrLghCq9jxz
  12D3KooWLdJAwPtyQ5RFnr9wGXsQzpf3P2SeqFbYkqbfVehLu4Ns
  12D3KooWBRFW3HkJCLKSWb4yG6iWRBpgNjbM4FFvNsL5T5JKTqrd
  12D3KooWQJzxKtEUvbt9BZ1uJyAMw2WSEQSShp4my4c3iikhW8Cf
  12D3KooWPBFzpNemfrwjMSTSENKAC6cDHxE2RXojcMJRwMtitDms
)
PARACHAIN_NODE_KEYS=(
  0000000000000000000000000000100000000000000000000000000000000000
  0000000000000000000000000000111111111111111111111111111111111111
  0000000000000000000000000000122222222222222222222222222222222222
  0000000000000000000000000000133333333333333333333333333333333333
  0000000000000000000000000000144444444444444444444444444444444444
  0000000000000000000000000000155555555555555555555555555555555555
  0000000000000000000000000000166666666666666666666666666666666666
  0000000000000000000000000000177777777777777777777777777777777777
  0000000000000000000000000000188888888888888888888888888888888888
  0000000000000000000000000000199999999999999999999999999999999999
)
PARACHAIN_LOCAL_IDS=(
  12D3KooWJ8BACzWs2x7yt1UozRrZrtcgUhpJrBbYrYqAQBa1ZXFN
  12D3KooWAZsNtba8pPJMYdbUUr9KFLQbFioPZKbpdNnbouSk6tto
  12D3KooWK5yfHLPADzZEKKzyqHjf3y5bi6jP6egNZL7aYp4us52E
  12D3KooWHtc11BNuNo9CbHb7MQS7NDue1qRjgnHbyyY8bo3Fu2L3
  12D3KooWDoaPdMd86ZPRTR9tmdw1qcdkdzLLWAXZSg5r4qWcyvZF
  12D3KooWHXyX7DHVr8nRHfbu7ct6Zyy4NEhciAzG6XqHRFC3zHEs
  12D3KooWAUHzje7vqkwBUTkiK8LMrMi52qgfyb8ouVpefo3tSXnk
  12D3KooWRjUyXkjqbmZ5XUiwrSz4fPrP3Q4wkhq7b2FZD8cRmDkm
  12D3KooWJ2sbvqxSA8D3VYa33XhhkmuZt58nxdWMKo2z3Mf3mafa
  12D3KooWNdXzpEDHHt6gnWx6RXc8J8YFZMhjQ154GDGHQBDNZZ9V
)
WELL_KNOWN_USERS=(
  "alice"
  "bob"
  "charlie"
  "dave"
  "eve"
  "ferdie"
)

# Alice is SUDO
ROCOCO_SUDO_SEED=${ROCOCO_SUDO_SEED:-"0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a"}
ROCOCO_SUDO_ADDR=${ROCOCO_SUDO_ADDR:-"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"}

# Alphanet declarations
ALPHANET_BUILD_FOLDER=${ALPHANET_BUILD_FOLDER:-"$BUILD_FOLDER/alphanet"}
mkdir -p $ALPHANET_BUILD_FOLDER
ALPHANET_TMP_FOLDER=${ALPHANET_TMP_FOLDER:-"$TMP_FOLDER/alphanet"}
mkdir -p $ALPHANET_TMP_FOLDER
ALPHANET_SPEC_FOLDER=${ALPHANET_SPEC_FOLDER:-"$SPECS_FOLDER/alphanet"}
ALPHANET_PARACHAIN_EMBEDDED_SPEC=${ALPHANET_PARACHAIN_EMBEDDED_SPEC:-"$ALPHANET_SPEC_FOLDER/parachain-embedded-specs-v8.json"}
ALPHANET_PARACHAIN_SPEC_TEMPLATE=${ALPHANET_PARACHAIN_SPEC_TEMPLATE:-"$ALPHANET_SPEC_FOLDER/$PARACHAIN_SPEC_TEMPLATE_FILENAME"}
ALPHANET_PARACHAIN_SPEC_PLAIN=${ALPHANET_PARACHAIN_SPEC_PLAIN:-"$ALPHANET_BUILD_FOLDER/$PARACHAIN_SPEC_PLAIN_FILENAME"}
ALPHANET_PARACHAIN_SPEC_RAW=${ALPHANET_PARACHAIN_SPEC_RAW:-"$ALPHANET_BUILD_FOLDER/$PARACHAIN_SPEC_RAW_FILENAME"}
ALPHANET_PARACHAIN_SPEC_TMP=${ALPHANET_PARACHAIN_SPEC_TMP:-"$ALPHANET_TMP_FOLDER/parachain-tmp-spec.json"}
ALPHANET_ROCOCO_EMBEDDED_SPEC=${ALPHANET_ROCOCO_EMBEDDED_SPEC:-"$ALPHANET_SPEC_FOLDER/rococo-embedded-specs-v8.json"}
ALPHANET_ROCOCO_SPEC_TEMPLATE=${ALPHANET_ROCOCO_SPEC_TEMPLATE:-"$ALPHANET_SPEC_FOLDER/$ROCOCO_SPEC_TEMPLATE_FILENAME"}
ALPHANET_ROCOCO_SPEC_PLAIN=${ALPHANET_ROCOCO_SPEC_PLAIN:-"$ALPHANET_BUILD_FOLDER/$ROCOCO_SPEC_PLAIN_FILENAME"}
ALPHANET_ROCOCO_SPEC_RAW=${ALPHANET_ROCOCO_SPEC_RAW:-"$ALPHANET_BUILD_FOLDER/$ROCOCO_SPEC_RAW_FILENAME"}
ALPHANET_ROCOCO_SPEC_TMP=${ALPHANET_ROCOCO_SPEC_TMP:-"$ALPHANET_TMP_FOLDER/rococo-tmp-spec.json"}
ALPHANET_WASM=${ALPHANET_WASM:-"$ALPHANET_BUILD_FOLDER/$PARACHAIN_WASM_FILENAME"}
ALPHANET_GENESIS=${ALPHANET_GENESIS:-"$ALPHANET_BUILD_FOLDER/$PARACHAIN_GENESIS_FILENAME"}
ALPHANET_PARACHAIN_ID=${ALPHANET_PARACHAIN_ID:-"1000"}
ALPHANET_STAKERS=($(jq -r '.genesis.runtime.parachainStaking.candidates[] | .[0]' ${ALPHANET_PARACHAIN_SPEC_TEMPLATE}))
