diff --git a/stack-orchestrator/compose/docker-compose-create-gentx.yml b/stack-orchestrator/compose/docker-compose-create-gentx.yml index 5a1a22f..bf126aa 100644 --- a/stack-orchestrator/compose/docker-compose-create-gentx.yml +++ b/stack-orchestrator/compose/docker-compose-create-gentx.yml @@ -2,23 +2,16 @@ services: laconicd: restart: unless-stopped image: cerc/laconicd:local - command: ["bash", "-c", "/opt/run-laconicd.sh"] + command: ["bash", "-c", "/opt/create-gentx.sh"] environment: CERC_MONIKER: ${CERC_MONIKER:-TestnetNode} CERC_CHAIN_ID: ${CERC_CHAIN_ID:-laconic_9000-1} - CERC_PEERS: ${CERC_PEERS} - MIN_GAS_PRICE: ${MIN_GAS_PRICE:-0.001} - CERC_LOGLEVEL: ${CERC_LOGLEVEL:-info} + DENOM: ${DENOM} + KEY_NAME: ${KEY_NAME:-mykey} + PVT_KEY: ${PVT_KEY} volumes: - laconicd-data:/root/.laconicd - - ../config/laconicd/run-laconicd.sh:/opt/run-laconicd.sh - ports: - - "6060" - - "26657" - - "26656" - - "9473" - - "9090" - - "1317" + - ../config/laconicd/create-gentx.sh:/opt/create-gentx.sh healthcheck: test: ["CMD", "nc", "-vz", "127.0.0.1", "26657"] interval: 30s diff --git a/stack-orchestrator/config/laconicd/create-gentx.sh b/stack-orchestrator/config/laconicd/create-gentx.sh index 860d3a0..fe00dc1 100755 --- a/stack-orchestrator/config/laconicd/create-gentx.sh +++ b/stack-orchestrator/config/laconicd/create-gentx.sh @@ -4,56 +4,52 @@ if [[ -n "$CERC_SCRIPT_DEBUG" ]]; then set -x fi +if [ -z "$DENOM" ]; then + echo "DENOM environment variable not set, exiting..." + exit 1 +fi + set -e -input_genesis_file=/root/.laconicd/tmp/genesis.json -if [ ! -f ${input_genesis_file} ]; then - echo "Genesis file not provided, exiting..." - exit 1 -fi - -if [ -z "$CERC_PEERS" ]; then - echo "Persistent peers not provided, exiting..." - exit 1 -fi - echo "Env:" echo "Moniker: $CERC_MONIKER" echo "Chain Id: $CERC_CHAIN_ID" -echo "Persistent peers: $CERC_PEERS" -echo "Min gas price: $MIN_GAS_PRICE" -echo "Log level: $CERC_LOGLEVEL" +echo "Denom: $DENOM" +echo "Key name: $KEY_NAME" +echo "PVT Key: $PVT_KEY" NODE_HOME=/root/.laconicd -# TODO: Add command to import key +KEYRING=test + # Set chain id in config laconicd config set client chain-id $CERC_CHAIN_ID --home $NODE_HOME -# Check if node data dir already exists -if [ -z "$(ls -A "$NODE_HOME/data")" ]; then - # Init node - echo "Initializing a new laconicd node with moniker $CERC_MONIKER and chain id $CERC_CHAIN_ID" - laconicd init $CERC_MONIKER --chain-id=$CERC_CHAIN_ID --home $NODE_HOME +export CERC_MONIKER=$(echo "$CERC_MONIKER" | sed -e 's/^["'\'']//g' -e 's/["'\'']$//g') +export CERC_CHAIN_ID=$(echo "$CERC_CHAIN_ID" | sed -e 's/^["'\'']//g' -e 's/["'\'']$//g') +export DENOM=$(echo "$DENOM" | sed -e 's/^["'\'']//g' -e 's/["'\'']$//g') - # TODO: Add command to create gentxs - # Use provided genesis config - cp $input_genesis_file $NODE_HOME/config/genesis.json +# TODO: Update amounts +BALANCE=100000000000000000000000$DENOM +STAKE_AMOUNT=100000000000000000000$DENOM + +# Init node +echo "Initializing a new laconicd node with moniker $CERC_MONIKER and chain id $CERC_CHAIN_ID" +laconicd init $CERC_MONIKER --chain-id=$CERC_CHAIN_ID --home $NODE_HOME + +# Support both importing key and generating account +if [ -n "$PVT_KEY" ]; then + # If PVT_KEY is provided, import the key + laconicd keys import-hex "$KEY_NAME" "$PVT_KEY" else - echo "Node data dir $NODE_HOME/data already exists, skipping initialization..." + # If PVT_KEY is not provided, create a new key + laconicd keys add "$KEY_NAME" fi -# Enable cors -sed -i 's/cors_allowed_origins.*$/cors_allowed_origins = ["*"]/' $HOME/.laconicd/config/config.toml +laconicd genesis add-genesis-account $KEY_NAME $BALANCE --keyring-backend $KEYRING --home $NODE_HOME -# Update config with persistent peers -sed -i "s/^persistent_peers *=.*/persistent_peers = \"$CERC_PEERS\"/g" $NODE_HOME/config/config.toml +laconicd genesis gentx $KEY_NAME $STAKE_AMOUNT --keyring-backend $KEYRING --home $NODE_HOME -echo "Starting laconicd node..." -laconicd start \ - --api.enable \ - --minimum-gas-prices=${MIN_GAS_PRICE}alnt \ - --rpc.laddr="tcp://0.0.0.0:26657" \ - --gql-playground --gql-server \ - --log_level $CERC_LOGLEVEL \ - --home $NODE_HOME +echo "Genesis transaction created successfully..." +# Keep the script running indefinitely +tail -f /dev/null