generate-chain-spec.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bash
  2. set -e
  3. DATA_PATH=$PWD/../data
  4. cd ../joystream
  5. # The docker image tag to use for joystream/node
  6. RUNTIME=${RUNTIME:=$(scripts/runtime-code-shasum.sh)}
  7. # Source of funds for all new accounts that are created in the tests.
  8. TREASURY_INITIAL_BALANCE=${TREASURY_INITIAL_BALANCE:="100000000"}
  9. TREASURY_ACCOUNT_URI=${TREASURY_ACCOUNT_URI:="//Bob"}
  10. TREASURY_ACCOUNT=$(docker run --rm joystream/node:${RUNTIME} key inspect ${TREASURY_ACCOUNT_URI} --output-type json | jq .ss58Address -r)
  11. >&2 echo "treasury account from suri: ${TREASURY_ACCOUNT}"
  12. # Default initial balances
  13. echo "{
  14. \"balances\":[
  15. [\"$TREASURY_ACCOUNT\", $TREASURY_INITIAL_BALANCE]
  16. ],
  17. \"vesting\":[]
  18. }" > ${DATA_PATH}/initial-balances.json
  19. # Override initial balances from external source
  20. if [[ $INITIAL_BALANCES == http* ]];
  21. then
  22. >&2 echo "fetching ${INITIAL_BALANCES}"
  23. wget -O ${DATA_PATH}/initial-balances.json ${INITIAL_BALANCES}
  24. else
  25. if [ ! -z "$INITIAL_BALANCES" ]; then
  26. if jq -e . >/dev/null 2>&1 <<<"$INITIAL_BALANCES"; then
  27. >&2 echo "Detected some valid JSON in INITIAL_BALANCES"
  28. echo $INITIAL_BALANCES > ${DATA_PATH}/initial-balances.json
  29. else
  30. >&2 echo "Failed to parse INITIAL_BALANCES as JSON, or got false/null"
  31. fi
  32. fi
  33. fi
  34. # Create a chain spec file
  35. docker run --rm -v ${DATA_PATH}:/spec --entrypoint ./chain-spec-builder joystream/node:${RUNTIME} \
  36. new \
  37. --fund-accounts \
  38. --authorities //Alice \
  39. --deployment dev \
  40. --chain-spec-path /spec/chain-spec.json \
  41. --initial-balances-path /spec/initial-balances.json
  42. # Convert the chain spec file to a raw chainspec file
  43. docker run --rm -v ${DATA_PATH}:/spec joystream/node:${RUNTIME} build-spec \
  44. --raw --disable-default-bootnode \
  45. --chain /spec/chain-spec.json > ${DATA_PATH}/chain-spec-raw.json