diff --git a/.github/workflows/test-start-node.yml b/.github/workflows/test-start-node.yml index 8195b49..2d49a23 100644 --- a/.github/workflows/test-start-node.yml +++ b/.github/workflows/test-start-node.yml @@ -38,7 +38,7 @@ jobs: timeout-minutes: 10 run: | set -euo pipefail - printf "2\n1\n" | ./start-node.sh 2>&1 | tee preprod_output.txt & + printf "1\n2\n1\n" | ./start-node.sh 2>&1 | tee preprod_output.txt & START_PID=$! sleep 30 if ! kill -0 $START_PID 2>/dev/null; then @@ -65,7 +65,7 @@ jobs: timeout-minutes: 3 run: | set -euo pipefail - printf "3\n1\n" | ./start-node.sh 2>&1 | tee preview_output.txt & + printf "1\n3\n1\n" | ./start-node.sh 2>&1 | tee preview_output.txt & START_PID=$! sleep 30 if ! kill -0 $START_PID 2>/dev/null; then @@ -92,7 +92,7 @@ jobs: timeout-minutes: 3 run: | set -euo pipefail - printf "4\n1\n" | ./start-node.sh 2>&1 | tee sancho_output.txt & + printf "1\n4\n1\n" | ./start-node.sh 2>&1 | tee sancho_output.txt & START_PID=$! sleep 30 if ! kill -0 $START_PID 2>/dev/null; then diff --git a/.gitignore b/.gitignore index 145eb78..c444f1f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ txs/ dumps/ node/ secrets/ +utilities/ node-*/ /scripts/poison /scripts/poison/ @@ -11,4 +12,7 @@ node-*/ # Python virtual environment venv/ __pycache__/ -*.pyc \ No newline at end of file +*.pyc + +# Config file (user-specific, example is tracked) +config/cardano-node-config.json \ No newline at end of file diff --git a/README.md b/README.md index 924e48e..fcaa421 100755 --- a/README.md +++ b/README.md @@ -238,6 +238,122 @@ Make sure you have a node running for these. ./scripts/drep/delegate-to-self.sh ``` +## Using Multiple Nodes and External Nodes + +This toolkit supports connecting to multiple Cardano nodes simultaneously - both Docker containers and external nodes running outside of Docker. You can run scripts against different networks and nodes at the same time. + +### External Node Configuration + +External nodes use environment variables `CARDANO_NODE_SOCKET_PATH` and `CARDANO_NODE_NETWORK_ID`. You can configure these through the `start-node.sh` script, which will prompt you for the values and confirm them before use. + +**Important:** Only one external node connection is supported at a time. For multiple external nodes, switch environment variables between script executions. + +#### Setting Up External Node + +Use the `start-node.sh` script to configure: + +```bash +./start-node.sh +# Select: "Configure connection to an external node via socket file" +# Enter socket path and network ID +# Confirm the values +``` + +Or set environment variables directly: + +```bash +export CARDANO_NODE_SOCKET_PATH="/path/to/node.socket" +export CARDANO_NODE_NETWORK_ID=1 # 1=preprod, 2=preview, 4=sanchonet + +# Run scripts +./scripts/query/tip.sh +``` + +#### Network Magic Numbers + +- **preprod**: Network ID `1` +- **preview**: Network ID `2` +- **sanchonet**: Network ID `4` +- **mainnet**: Network ID `764824073` (blocked for external nodes) + +### Docker Container Selection + +Specify which Docker container to use: + +```bash +# Use specific container +CARDANO_CONTAINER_NAME="node-preprod-10.5.3-container" ./scripts/query/tip.sh + +# Use different container +CARDANO_CONTAINER_NAME="node-preview-10.5.3-container" ./scripts/query/tip.sh +``` + +### Multiple Docker Containers + +When multiple Docker containers are running, the toolkit will: +- **Automatically select** the only container if only one is running +- **Prompt you to choose** if multiple containers are running (interactive mode) +- **Use the first container** if running non-interactively (no TTY) + +To avoid prompts, specify the container name: + +```bash +CARDANO_CONTAINER_NAME="node-preprod-10.5.3-container" ./scripts/query/tip.sh +``` + +### Single Node Configuration (Backward Compatible) + +For backward compatibility, you can still use the old single-node format: + +```json +{ + "socket_path": "/path/to/your/node.socket", + "network": "preprod", + "network_id": 1, + "mode": "external" +} +``` + +### Requirements + +- **Local cardano-cli**: When using external node mode, you must have `cardano-cli` installed locally and available in your PATH +- **Network restriction**: Mainnet connections via external sockets are **not allowed** for security reasons. Only testnet networks (preprod, preview, sanchonet) are supported +- **Socket file**: The socket file must be accessible and the node must be running + +### Network Magic Numbers + +- **preprod**: Network ID `1` +- **preview**: Network ID `2` +- **sanchonet**: Network ID `4` +- **mainnet**: Network ID `764824073` (blocked for external nodes, allowed in Docker mode) + +### Example: Running Scripts Against Multiple Networks + +```bash +# Terminal 1: Query preprod via external node +CARDANO_NODE_SOCKET_PATH="/path/to/preprod.socket" CARDANO_NODE_NETWORK_ID=1 ./scripts/query/tip.sh + +# Terminal 2: Query preview via external node (switch env vars) +CARDANO_NODE_SOCKET_PATH="/path/to/preview.socket" CARDANO_NODE_NETWORK_ID=2 ./scripts/query/tip.sh + +# Terminal 3: Use Docker container for mainnet +CARDANO_CONTAINER_NAME="node-mainnet-10.5.3-container" ./scripts/query/tip.sh +``` + +### Node Selection Priority + +The toolkit uses the following priority order: + +1. `CARDANO_NODE_SOCKET_PATH` + `CARDANO_NODE_NETWORK_ID` - External node (environment variables) +2. `CARDANO_CONTAINER_NAME` - Direct container name specification (for Docker mode) +3. Docker mode with container selection - Default fallback + +**Note:** External nodes require both `CARDANO_NODE_SOCKET_PATH` and `CARDANO_NODE_NETWORK_ID` to be set. Use the `start-node.sh` script to configure and confirm these values. + +### Version Check + +When using external node mode, the toolkit will automatically check and display your local `cardano-cli` version and which node is being used. If `cardano-cli` is not found in PATH, you'll receive a warning. + ## Common Error Messages ### Docker desktop application not open @@ -247,3 +363,19 @@ Cannot connect to the Docker daemon at unix:///Users/XXXX/.docker/run/docker.soc ``` **Fix:** Open docker desktop + +### Mainnet connection blocked + +```bash +Error: Mainnet connections are not allowed. Please use testnet networks (preprod, preview, sanchonet) only. +``` + +**Fix:** This error appears when attempting to connect to mainnet via external socket. Use Docker mode for mainnet, or switch to a testnet network. + +### cardano-cli not found + +```bash +Warning: cardano-cli not found in PATH. External node mode requires cardano-cli to be installed locally. +``` + +**Fix:** Install `cardano-cli` locally and ensure it's in your PATH when using external node mode. diff --git a/scripts/cc/authorize-hot-key.sh b/scripts/cc/authorize-hot-key.sh index 64a684e..adcb7ae 100755 --- a/scripts/cc/authorize-hot-key.sh +++ b/scripts/cc/authorize-hot-key.sh @@ -12,40 +12,43 @@ tx_cert_path="$tx_path_stub.cert" tx_unsigned_path="$tx_path_stub.unsigned" tx_signed_path="$tx_path_stub.signed" -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti $container_name cardano-cli "$@" +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" + +# Helper function to get UTXO with validation +get_utxo() { + local address=$1 + local utxo_output + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) + local utxo + utxo=$(echo "$utxo_output" | jq -r 'keys[0]') + if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then + echo "Error: No UTXO found at address: $address" >&2 + exit 1 + fi + echo "$utxo" } + echo "Authorizing hot key for the constitutional committee." -container_cli conway governance committee create-hot-key-authorization-certificate \ +cardano_cli conway governance committee create-hot-key-authorization-certificate \ --cold-verification-key-file "$keys_dir/cc-cold.vkey" \ --hot-key-file "$keys_dir/cc-hot.vkey" \ --out-file "$tx_cert_path" echo "Building transaction" -container_cli conway transaction build \ +cardano_cli conway transaction build \ --witness-override 2 \ - --tx-in $(container_cli conway query utxo --address $(cat "$keys_dir/payment.addr") --out-file /dev/stdout | jq -r 'keys[0]') \ + --tx-in $(cardano_cli conway query utxo --address $(cat "$keys_dir/payment.addr") --out-file /dev/stdout | jq -r 'keys[0]') \ --change-address $(cat "$keys_dir/payment.addr") \ --certificate-file "$tx_cert_path" \ --out-file "$tx_unsigned_path" echo "Signing transaction" -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/payment.skey" \ --signing-key-file "$keys_dir/cc-cold.skey" \ @@ -54,4 +57,4 @@ container_cli conway transaction sign \ # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file $tx_signed_path \ No newline at end of file +cardano_cli conway transaction submit --tx-file $tx_signed_path \ No newline at end of file diff --git a/scripts/cc/generate-cc-keys.sh b/scripts/cc/generate-cc-keys.sh index abc044f..8b0b150 100755 --- a/scripts/cc/generate-cc-keys.sh +++ b/scripts/cc/generate-cc-keys.sh @@ -7,20 +7,8 @@ project_root=$(cd "$script_dir/../.." && pwd) # Define directory paths relative to project root keys_dir="$project_root/keys" -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti $container_name cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Check if CC keys already exist if [ -f "$keys_dir/cc-cold.vkey" ]; then @@ -33,19 +21,19 @@ fi echo "Generating constitutional committee hot and cold keys." # Generate CC cold keys -container_cli conway governance committee key-gen-cold \ +cardano_cli conway governance committee key-gen-cold \ --verification-key-file "$keys_dir/cc-cold.vkey" \ --signing-key-file "$keys_dir/cc-cold.skey" # Generate CC hot keys -container_cli conway governance committee key-gen-hot \ +cardano_cli conway governance committee key-gen-hot \ --verification-key-file "$keys_dir/cc-hot.vkey" \ --signing-key-file "$keys_dir/cc-hot.skey" # Generate CC cold key hash -container_cli conway governance committee key-hash \ +cardano_cli conway governance committee key-hash \ --verification-key-file "$keys_dir/cc-cold.vkey" > "$keys_dir/cc-cold-key-hash.hash" # Generate CC hot key hash -container_cli conway governance committee key-hash \ +cardano_cli conway governance committee key-hash \ --verification-key-file "$keys_dir/cc-hot.vkey" > "$keys_dir/cc-hot-key-hash.hash" \ No newline at end of file diff --git a/scripts/cc/generate-new-hot-key.sh b/scripts/cc/generate-new-hot-key.sh index 0f1f781..76e9053 100755 --- a/scripts/cc/generate-new-hot-key.sh +++ b/scripts/cc/generate-new-hot-key.sh @@ -7,29 +7,17 @@ project_root=$(cd "$script_dir/../.." && pwd) # Define directory paths relative to project root keys_dir="$project_root/keys" -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti $container_name cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Generate hot CC keys echo "Generating a new constitutional committee hot key (replacing the existing one)." # Generate CC hot keys -container_cli conway governance committee key-gen-hot \ +cardano_cli conway governance committee key-gen-hot \ --verification-key-file "$keys_dir/cc-hot.vkey" \ --signing-key-file "$keys_dir/cc-hot.skey" # Generate CC hot key hash -container_cli conway governance committee key-hash \ +cardano_cli conway governance committee key-hash \ --verification-key-file "$keys_dir/cc-hot.vkey" > "$keys_dir/cc-hot-key-hash.hash" \ No newline at end of file diff --git a/scripts/cc/resign-cold-key.sh b/scripts/cc/resign-cold-key.sh index 11c20c4..0684777 100755 --- a/scripts/cc/resign-cold-key.sh +++ b/scripts/cc/resign-cold-key.sh @@ -12,34 +12,37 @@ tx_cert_path="$tx_path_stub.cert" tx_unsigned_path="$tx_path_stub.unsigned" tx_signed_path="$tx_path_stub.signed" -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti $container_name cardano-cli "$@" +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" + +# Helper function to get UTXO with validation +get_utxo() { + local address=$1 + local utxo_output + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) + local utxo + utxo=$(echo "$utxo_output" | jq -r 'keys[0]') + if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then + echo "Error: No UTXO found at address: $address" >&2 + exit 1 + fi + echo "$utxo" } + echo "Resigning your CC cold key." # Generate CC cold key resignation certificate -container_cli conway governance committee create-cold-key-resignation-certificate \ +cardano_cli conway governance committee create-cold-key-resignation-certificate \ --cold-verification-key-file "$keys_dir/cc-cold.vkey" \ --out-file "$tx_cert_path" # Build transaction echo "Building transaction" -container_cli conway transaction build \ +cardano_cli conway transaction build \ --witness-override 2 \ - --tx-in $(container_cli conway query utxo --address $(cat "$keys_dir/payment.addr") --out-file /dev/stdout | jq -r 'keys[0]') \ + --tx-in $(cardano_cli conway query utxo --address $(cat "$keys_dir/payment.addr") --out-file /dev/stdout | jq -r 'keys[0]') \ --change-address $(cat "$keys_dir/payment.addr") \ --certificate-file "$tx_cert_path" \ --out-file "$tx_unsigned_path" @@ -47,7 +50,7 @@ container_cli conway transaction build \ # Sign transaction echo "Signing transaction" -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/payment.skey" \ --signing-key-file "$keys_dir/cc-cold.skey" \ @@ -56,4 +59,4 @@ container_cli conway transaction sign \ # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file $tx_signed_path \ No newline at end of file +cardano_cli conway transaction submit --tx-file $tx_signed_path \ No newline at end of file diff --git a/scripts/cc/vote.sh b/scripts/cc/vote.sh index 8eab0a6..96db14c 100755 --- a/scripts/cc/vote.sh +++ b/scripts/cc/vote.sh @@ -20,26 +20,30 @@ tx_cert_path="$tx_path_stub.cert" tx_unsigned_path="$tx_path_stub.unsigned" tx_signed_path="$tx_path_stub.signed" -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" +# Get the script's directory +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti $container_name cardano-cli "$@" +# Helper function to get UTXO with validation +get_utxo() { + local address=$1 + local utxo_output + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) + local utxo + utxo=$(echo "$utxo_output" | jq -r 'keys[0]') + if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then + echo "Error: No UTXO found at address: $address" >&2 + exit 1 + fi + echo "$utxo" } + # Voting on a governance action echo "Voting on $GA_TX_HASH with a $CHOICE." # Create vote -container_cli conway governance vote create \ +cardano_cli conway governance vote create \ "--$CHOICE" \ --governance-action-tx-id "$GA_TX_HASH" \ --governance-action-index "$GA_TX_INDEX" \ @@ -49,18 +53,18 @@ container_cli conway governance vote create \ # Build transaction echo "Building transaction" -container_cli conway transaction build \ - --tx-in "$(container_cli conway query utxo --address $(cat "$keys_dir/payment.addr") --out-file /dev/stdout | jq -r 'keys[0]')" \ +cardano_cli conway transaction build \ + --tx-in "$(cardano_cli conway query utxo --address $(cat "$keys_dir/payment.addr") --out-file /dev/stdout | jq -r 'keys[0]')" \ --change-address "$(cat "$keys_dir/payment.addr")" \ --vote-file "$tx_cert_path" \ --witness-override 2 \ --out-file "$tx_unsigned_path" # Sign transaction -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/payment.skey" \ --signing-key-file "$keys_dir/cc-hot.skey" \ --out-file "$tx_signed_path" -container_cli conway transaction submit --tx-file $tx_signed_path \ No newline at end of file +cardano_cli conway transaction submit --tx-file $tx_signed_path \ No newline at end of file diff --git a/scripts/drep/create-and-register-multisig.sh b/scripts/drep/create-and-register-multisig.sh index dc8b993..491c3fc 100755 --- a/scripts/drep/create-and-register-multisig.sh +++ b/scripts/drep/create-and-register-multisig.sh @@ -8,21 +8,24 @@ project_root=$(cd "$script_dir/../.." && pwd) keys_dir="$project_root/keys" txs_dir="$project_root/txs/multi-sig" -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti $container_name cardano-cli "$@" +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" + +# Helper function to get UTXO with validation +get_utxo() { + local address=$1 + local utxo_output + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) + local utxo + utxo=$(echo "$utxo_output" | jq -r 'keys[0]') + if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then + echo "Error: No UTXO found at address: $address" >&2 + exit 1 + fi + echo "$utxo" } + # Registering you as a drep echo "Registering you as a native script multisig DRep." @@ -30,9 +33,9 @@ echo "Registering you as a native script multisig DRep." # cp ./scripts/drep/multi-sig-template.json $txs_dir/multisig-drep.json # # Capture the keyHash values and ensure no newline characters -# newHash1=$(container_cli address key-hash --payment-verification-key-file "$keys_dir/payment.vkey" | tr -d '\n') -# newHash2=$(container_cli address key-hash --payment-verification-key-file "$keys_dir/payment.vkey" | tr -d '\n') -# newHash3=$(container_cli address key-hash --payment-verification-key-file "$keys_dir/payment.vkey" | tr -d '\n') +# newHash1=$(cardano_cli address key-hash --payment-verification-key-file "$keys_dir/payment.vkey" | tr -d '\n') +# newHash2=$(cardano_cli address key-hash --payment-verification-key-file "$keys_dir/payment.vkey" | tr -d '\n') +# newHash3=$(cardano_cli address key-hash --payment-verification-key-file "$keys_dir/payment.vkey" | tr -d '\n') # # Use the captured values in jq # updated_json=$(jq --arg newHash1 "$newHash1" \ @@ -45,36 +48,36 @@ echo "Registering you as a native script multisig DRep." # # Write the updated JSON to file # echo "$updated_json" > "$txs_dir/multisig-drep.json" -container_cli hash script \ +cardano_cli hash script \ --script-file $txs_dir/drep-one-sig.json \ --out-file $txs_dir/drep-one-sig.id -container_cli conway governance drep registration-certificate \ +cardano_cli conway governance drep registration-certificate \ --drep-script-hash "$(cat $txs_dir/drep-one-sig.id)" \ - --key-reg-deposit-amt "$(container_cli conway query gov-state | jq -r .currentPParams.dRepDeposit)" \ + --key-reg-deposit-amt "$(cardano_cli conway query gov-state | jq -r .currentPParams.dRepDeposit)" \ --out-file $txs_dir/drep-multisig-register.cert echo "Building transaction" -container_cli conway transaction build \ +cardano_cli conway transaction build \ --witness-override 2 \ - --tx-in $(container_cli conway query utxo --address $(cat $keys_dir/payment.addr) --out-file /dev/stdout | jq -r 'keys[0]') \ + --tx-in $(cardano_cli conway query utxo --address $(cat $keys_dir/payment.addr) --out-file /dev/stdout | jq -r 'keys[0]') \ --change-address $(cat $keys_dir/payment.addr) \ --certificate-file $txs_dir/drep-multisig-register.cert \ --certificate-script-file $txs_dir/drep-one-sig.json \ --out-file $txs_dir/reg-drep-multisig-register.unsigned -container_cli conway transaction witness \ +cardano_cli conway transaction witness \ --tx-body-file $txs_dir/reg-drep-multisig-register.unsigned \ --signing-key-file $keys_dir/payment.skey \ --out-file $txs_dir/reg-drep-multisig-register.witness -container_cli conway transaction witness \ +cardano_cli conway transaction witness \ --tx-body-file $txs_dir/reg-drep-multisig-register.unsigned \ --signing-key-file $keys_dir/multi-sig/1.skey \ --out-file $txs_dir/reg-drep-multisig-register-1.witness -container_cli conway transaction assemble \ +cardano_cli conway transaction assemble \ --tx-body-file $txs_dir/reg-drep-multisig-register.unsigned \ --witness-file $txs_dir/reg-drep-multisig-register.witness \ --witness-file $txs_dir/reg-drep-multisig-register-1.witness \ @@ -82,5 +85,5 @@ container_cli conway transaction assemble \ echo "Submitting transaction" -container_cli conway transaction submit \ +cardano_cli conway transaction submit \ --tx-file $txs_dir/reg-drep-multisig-register.signed diff --git a/scripts/drep/delegate-to-self.sh b/scripts/drep/delegate-to-self.sh index 88d9e30..20f2d1e 100755 --- a/scripts/drep/delegate-to-self.sh +++ b/scripts/drep/delegate-to-self.sh @@ -41,26 +41,14 @@ if [ ! -f "$keys_dir/stake.skey" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Helper function to get UTXO with validation get_utxo() { local address=$1 local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) local utxo utxo=$(echo "$utxo_output" | jq -r 'keys[0]') if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then @@ -72,50 +60,29 @@ get_utxo() { echo "Delegating your voting rights to your DRep ID ($(cat "$keys_dir/drep.id"))" -container_cli conway stake-address vote-delegation-certificate \ - --stake-verification-key-file "$keys_dir/stake.vkey" \ - --drep-key-hash "$(cat "$keys_dir/drep.id")" \ - --out-file "$tx_cert_path" - -# Check certificate file was created -if [ ! -f "$tx_cert_path" ]; then - echo "Error: Failed to create certificate file" - exit 1 -fi +cardano_cli conway stake-address vote-delegation-certificate \ + --stake-verification-key-file $keys_dir/stake.vkey \ + --drep-key-hash "$(cat $keys_dir/drep.id)" \ + --out-file $tx_cert_path echo "Building transaction" -payment_addr=$(cat "$keys_dir/payment.addr") -utxo=$(get_utxo "$payment_addr") - -container_cli conway transaction build \ +cardano_cli conway transaction build \ --witness-override 2 \ - --tx-in "$utxo" \ - --change-address "$payment_addr" \ - --certificate-file "$tx_cert_path" \ - --out-file "$tx_unsigned_path" - -# Check transaction file was created -if [ ! -f "$tx_unsigned_path" ]; then - echo "Error: Failed to create unsigned transaction file" - exit 1 -fi + --tx-in $(cardano_cli conway query utxo --address $(cat $keys_dir/payment.addr) --out-file /dev/stdout | jq -r 'keys[0]') \ + --change-address $(cat $keys_dir/payment.addr) \ + --certificate-file $tx_cert_path \ + --out-file $tx_unsigned_path echo "Signing transaction" -container_cli conway transaction sign \ - --tx-body-file "$tx_unsigned_path" \ - --signing-key-file "$keys_dir/payment.skey" \ - --signing-key-file "$keys_dir/stake.skey" \ - --out-file "$tx_signed_path" - -# Check signed transaction file was created -if [ ! -f "$tx_signed_path" ]; then - echo "Error: Failed to create signed transaction file" - exit 1 -fi +cardano_cli conway transaction sign \ + --tx-body-file $tx_unsigned_path \ + --signing-key-file $keys_dir/payment.skey \ + --signing-key-file $keys_dir/stake.skey \ + --out-file $tx_signed_path # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" \ No newline at end of file +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/drep/register.sh b/scripts/drep/register.sh index c8eb344..ecb20a6 100755 --- a/scripts/drep/register.sh +++ b/scripts/drep/register.sh @@ -36,26 +36,14 @@ if [ ! -f "$keys_dir/drep.skey" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Helper function to get UTXO with validation get_utxo() { local address=$1 local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) local utxo utxo=$(echo "$utxo_output" | jq -r 'keys[0]') if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then @@ -65,53 +53,33 @@ get_utxo() { echo "$utxo" } + # Registering you as a drep echo "Registering you as a DRep." -container_cli conway governance drep registration-certificate \ - --drep-key-hash "$(cat "$keys_dir/drep.id")" \ - --key-reg-deposit-amt "$(container_cli conway query gov-state | jq -r '.currentPParams.dRepDeposit')" \ - --out-file "$tx_cert_path" - -# Check certificate file was created -if [ ! -f "$tx_cert_path" ]; then - echo "Error: Failed to create certificate file" - exit 1 -fi +cardano_cli conway governance drep registration-certificate \ + --drep-key-hash "$(cat $keys_dir/drep.id)" \ + --key-reg-deposit-amt "$(cardano_cli conway query gov-state | jq -r .currentPParams.dRepDeposit)" \ + --out-file $tx_cert_path echo "Building transaction" -payment_addr=$(cat "$keys_dir/payment.addr") -utxo=$(get_utxo "$payment_addr") - -container_cli conway transaction build \ +cardano_cli conway transaction build \ --witness-override 2 \ - --tx-in "$utxo" \ - --change-address "$payment_addr" \ - --certificate-file "$tx_cert_path" \ - --out-file "$tx_unsigned_path" - -# Check transaction file was created -if [ ! -f "$tx_unsigned_path" ]; then - echo "Error: Failed to create unsigned transaction file" - exit 1 -fi + --tx-in $(cardano_cli conway query utxo --address $(cat $keys_dir/payment.addr) --out-file /dev/stdout | jq -r 'keys[0]') \ + --change-address $(cat $keys_dir/payment.addr) \ + --certificate-file $tx_cert_path \ + --out-file $tx_unsigned_path echo "Signing transaction" -container_cli conway transaction sign \ - --tx-body-file "$tx_unsigned_path" \ - --signing-key-file "$keys_dir/payment.skey" \ - --signing-key-file "$keys_dir/drep.skey" \ - --out-file "$tx_signed_path" - -# Check signed transaction file was created -if [ ! -f "$tx_signed_path" ]; then - echo "Error: Failed to create signed transaction file" - exit 1 -fi +cardano_cli conway transaction sign \ + --tx-body-file $tx_unsigned_path \ + --signing-key-file $keys_dir/payment.skey \ + --signing-key-file $keys_dir/drep.skey \ + --out-file $tx_signed_path # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" \ No newline at end of file +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/drep/retire.sh b/scripts/drep/retire.sh index 7226fb1..2acd1a7 100755 --- a/scripts/drep/retire.sh +++ b/scripts/drep/retire.sh @@ -36,26 +36,14 @@ if [ ! -f "$keys_dir/drep.skey" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Helper function to get UTXO with validation get_utxo() { local address=$1 local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) local utxo utxo=$(echo "$utxo_output" | jq -r 'keys[0]') if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then @@ -65,53 +53,33 @@ get_utxo() { echo "$utxo" } + # Retiring you as a drep echo "Retiring you as a DRep." -container_cli conway governance drep retirement-certificate \ - --drep-key-hash "$(cat "$keys_dir/drep.id")" \ - --deposit-amt "$(container_cli conway query gov-state | jq -r '.currentPParams.dRepDeposit')" \ - --out-file "$tx_cert_path" - -# Check certificate file was created -if [ ! -f "$tx_cert_path" ]; then - echo "Error: Failed to create certificate file" - exit 1 -fi +cardano_cli conway governance drep retirement-certificate \ + --drep-key-hash $(cat $keys_dir/drep.id) \ + --deposit-amt $(cardano_cli conway query gov-state | jq -r .currentPParams.dRepDeposit) \ + --out-file $tx_cert_path echo "Building transaction" -payment_addr=$(cat "$keys_dir/payment.addr") -utxo=$(get_utxo "$payment_addr") - -container_cli conway transaction build \ +cardano_cli conway transaction build \ --witness-override 2 \ - --tx-in "$utxo" \ - --change-address "$payment_addr" \ - --certificate-file "$tx_cert_path" \ - --out-file "$tx_unsigned_path" - -# Check transaction file was created -if [ ! -f "$tx_unsigned_path" ]; then - echo "Error: Failed to create unsigned transaction file" - exit 1 -fi + --tx-in $(cardano_cli conway query utxo --address $(cat $keys_dir/payment.addr) --out-file /dev/stdout | jq -r 'keys[0]') \ + --change-address $(cat $keys_dir/payment.addr) \ + --certificate-file $tx_cert_path \ + --out-file $tx_unsigned_path echo "Signing transaction" -container_cli conway transaction sign \ - --tx-body-file "$tx_unsigned_path" \ - --signing-key-file "$keys_dir/payment.skey" \ - --signing-key-file "$keys_dir/drep.skey" \ - --out-file "$tx_signed_path" - -# Check signed transaction file was created -if [ ! -f "$tx_signed_path" ]; then - echo "Error: Failed to create signed transaction file" - exit 1 -fi +cardano_cli conway transaction sign \ + --tx-body-file $tx_unsigned_path \ + --signing-key-file $keys_dir/payment.skey \ + --signing-key-file $keys_dir/drep.skey \ + --out-file $tx_signed_path # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/drep/vote.sh b/scripts/drep/vote.sh index d5d0b9b..60ac5a0 100755 --- a/scripts/drep/vote.sh +++ b/scripts/drep/vote.sh @@ -46,26 +46,14 @@ if [ ! -f "$keys_dir/drep.skey" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Helper function to get UTXO with validation get_utxo() { local address=$1 local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) local utxo utxo=$(echo "$utxo_output" | jq -r 'keys[0]') if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then @@ -75,10 +63,11 @@ get_utxo() { echo "$utxo" } + # Voting on a governance action echo "Voting on $GA_TX_HASH with a $CHOICE." -container_cli conway governance vote create \ +cardano_cli conway governance vote create \ "--$CHOICE" \ --governance-action-tx-id "$GA_TX_HASH" \ --governance-action-index "$GA_TX_INDEX" \ @@ -96,13 +85,10 @@ fi echo "Building transaction" -payment_addr=$(cat "$keys_dir/payment.addr") -utxo=$(get_utxo "$payment_addr") - -container_cli conway transaction build \ - --tx-in "$utxo" \ - --change-address "$payment_addr" \ - --vote-file "$tx_cert_path" \ +cardano_cli conway transaction build \ + --tx-in "$(cardano_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ + --change-address "$(cat $keys_dir/payment.addr)" \ + --vote-file $tx_cert_path \ --witness-override 2 \ --out-file "$tx_unsigned_path" @@ -114,19 +100,13 @@ fi echo "Signing transaction" -container_cli conway transaction sign \ - --tx-body-file "$tx_unsigned_path" \ - --signing-key-file "$keys_dir/drep.skey" \ - --signing-key-file "$keys_dir/payment.skey" \ - --out-file "$tx_signed_path" - -# Check signed transaction file was created -if [ ! -f "$tx_signed_path" ]; then - echo "Error: Failed to create signed transaction file" - exit 1 -fi +cardano_cli conway transaction sign \ + --tx-body-file $tx_unsigned_path \ + --signing-key-file $keys_dir/drep.skey \ + --signing-key-file $keys_dir/payment.skey \ + --out-file $tx_signed_path # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/ga/hardfork.sh b/scripts/ga/hardfork.sh index 42757b2..1d198ba 100755 --- a/scripts/ga/hardfork.sh +++ b/scripts/ga/hardfork.sh @@ -20,24 +20,28 @@ tx_cert_path="$tx_path_stub.action" tx_unsigned_path="$tx_path_stub.unsigned" tx_signed_path="$tx_path_stub.signed" -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti $container_name cardano-cli "$@" +# Get the script's directory +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" + +# Helper function to get UTXO with validation +get_utxo() { + local address=$1 + local utxo_output + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) + local utxo + utxo=$(echo "$utxo_output" | jq -r 'keys[0]') + if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then + echo "Error: No UTXO found at address: $address" >&2 + exit 1 + fi + echo "$utxo" } + echo "Finding the previous Hardfork to reference" -GOV_STATE=$(container_cli conway query gov-state | jq -r '.nextRatifyState.nextEnactState.prevGovActionIds') +GOV_STATE=$(cardano_cli conway query gov-state | jq -r '.nextRatifyState.nextEnactState.prevGovActionIds') PREV_GA_TX_HASH=$(echo "$GOV_STATE" | jq -r '.HardFork.txId') PREV_GA_INDEX=$(echo "$GOV_STATE" | jq -r '.HardFork.govActionIx') @@ -47,9 +51,8 @@ echo "Previous Hardfork GA: $PREV_GA_TX_HASH#$PREV_GA_INDEX" # Building, signing and submitting an hardfork change governance action echo "Creating and submitting hardfork governance action." -container_cli conway governance action create-hardfork \ - --testnet \ - --governance-action-deposit $(container_cli conway query gov-state | jq -r '.currentPParams.govActionDeposit') \ +cardano_cli conway governance action create-hardfork \ + --governance-action-deposit $(cardano_cli conway query gov-state | jq -r '.currentPParams.govActionDeposit') \ --deposit-return-stake-verification-key-file $keys_dir/stake.vkey \ --anchor-url "$METADATA_URL" \ --anchor-data-hash "$METADATA_HASH" \ @@ -62,15 +65,15 @@ container_cli conway governance action create-hardfork \ echo "Building transaction" -container_cli conway transaction build \ - --tx-in "$(container_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ +cardano_cli conway transaction build \ + --tx-in "$(cardano_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ --proposal-file "$tx_cert_path" \ --change-address "$(cat $keys_dir/payment.addr)" \ --out-file "$tx_unsigned_path" echo "Signing transaction" -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file $keys_dir/payment.skey \ --out-file "$tx_signed_path" @@ -78,4 +81,4 @@ container_cli conway transaction sign \ # Submit the transaction echo "Submitting transaction" -# container_cli conway transaction submit --tx-file $tx_signed_path +# cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/ga/info.sh b/scripts/ga/info.sh index bafd0ff..8b7b103 100755 --- a/scripts/ga/info.sh +++ b/scripts/ga/info.sh @@ -37,26 +37,14 @@ if [ ! -f "$keys_dir/stake.vkey" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Helper function to get UTXO with validation get_utxo() { local address=$1 local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) local utxo utxo=$(echo "$utxo_output" | jq -r 'keys[0]') if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then @@ -66,15 +54,15 @@ get_utxo() { echo "$utxo" } + # Building, signing and submitting an info governance action echo "Creating and submitting info governance action." -container_cli conway governance action create-info \ - --testnet \ - --governance-action-deposit "$(container_cli conway query gov-state | jq -r '.currentPParams.govActionDeposit')" \ - --deposit-return-stake-verification-key-file "$keys_dir/stake.vkey" \ - --anchor-url "$METADATA_URL" \ - --anchor-data-hash "$METADATA_HASH" \ +cardano_cli conway governance action create-info \ + --governance-action-deposit $(cardano_cli conway query gov-state | jq -r '.currentPParams.govActionDeposit') \ + --deposit-return-stake-verification-key-file $keys_dir/stake.vkey \ + --anchor-url $METADATA_URL \ + --anchor-data-hash $METADATA_HASH \ --check-anchor-data \ --out-file "$tx_cert_path" @@ -86,12 +74,9 @@ fi echo "Building transaction" -payment_addr=$(cat "$keys_dir/payment.addr") -utxo=$(get_utxo "$payment_addr") - -container_cli conway transaction build \ - --tx-in "$utxo" \ - --change-address "$payment_addr" \ +cardano_cli conway transaction build \ + --tx-in "$(cardano_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ + --change-address "$(cat $keys_dir/payment.addr)" \ --proposal-file "$tx_cert_path" \ --out-file "$tx_unsigned_path" @@ -103,7 +88,7 @@ fi echo "Signing transaction" -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/payment.skey" \ --out-file "$tx_signed_path" @@ -117,4 +102,4 @@ fi # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/ga/new-committee.sh b/scripts/ga/new-committee.sh index 507ae2f..8633ed8 100755 --- a/scripts/ga/new-committee.sh +++ b/scripts/ga/new-committee.sh @@ -20,21 +20,25 @@ tx_cert_path="$tx_path_stub.action" tx_unsigned_path="$tx_path_stub.unsigned" tx_signed_path="$tx_path_stub.signed" -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti $container_name cardano-cli "$@" +# Get the script's directory +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" + +# Helper function to get UTXO with validation +get_utxo() { + local address=$1 + local utxo_output + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) + local utxo + utxo=$(echo "$utxo_output" | jq -r 'keys[0]') + if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then + echo "Error: No UTXO found at address: $address" >&2 + exit 1 + fi + echo "$utxo" } + export THRESHOLD="2/3" # Atlantic Council @@ -79,7 +83,7 @@ export REMOVE_CC_5_SCRIPT_HASH="e8165b3328027ee0d74b1f07298cb092fd99aa7697a1436f echo "Finding the previous Committee GA to reference" -GOV_STATE=$(container_cli conway query gov-state | jq -r '.nextRatifyState.nextEnactState.prevGovActionIds') +GOV_STATE=$(cardano_cli conway query gov-state | jq -r '.nextRatifyState.nextEnactState.prevGovActionIds') PREV_GA_TX_HASH=$(echo "$GOV_STATE" | jq -r '.Committee.txId') PREV_GA_INDEX=$(echo "$GOV_STATE" | jq -r '.Committee.govActionIx') @@ -89,9 +93,8 @@ echo "Previous Committee GA Tx Hash: $PREV_GA_TX_HASH#$PREV_GA_INDEX" # Building, signing and submitting an new-committee change governance action echo "Creating and submitting new-committee governance action." -container_cli conway governance action update-committee \ - --testnet \ - --governance-action-deposit $(container_cli conway query gov-state | jq -r '.currentPParams.govActionDeposit') \ +cardano_cli conway governance action update-committee \ + --governance-action-deposit $(cardano_cli conway query gov-state | jq -r '.currentPParams.govActionDeposit') \ --deposit-return-stake-verification-key-file $keys_dir/stake.vkey \ --remove-cc-cold-script-hash "6a0cd9563908692460413e08bef26eda0265ec23868fd1560d5cd42f" \ --remove-cc-cold-script-hash "be4d67a5dd8de49543cc489aca920a377ea7a7e9855c8934d33e5765" \ @@ -120,15 +123,15 @@ container_cli conway governance action update-committee \ echo "Building transaction" -container_cli conway transaction build \ - --tx-in "$(container_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ +cardano_cli conway transaction build \ + --tx-in "$(cardano_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ --proposal-file "$tx_cert_path" \ --change-address "$(cat $keys_dir/payment.addr)" \ --out-file "$tx_unsigned_path" \ echo "Signing transaction" -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file $keys_dir/payment.skey \ --out-file "$tx_signed_path" \ @@ -136,4 +139,4 @@ container_cli conway transaction sign \ # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file $tx_signed_path +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/ga/new-consitution.sh b/scripts/ga/new-consitution.sh index c8b3e9d..e1ed2e9 100755 --- a/scripts/ga/new-consitution.sh +++ b/scripts/ga/new-consitution.sh @@ -22,24 +22,28 @@ tx_cert_path="$tx_path_stub.action" tx_unsigned_path="$tx_path_stub.unsigned" tx_signed_path="$tx_path_stub.signed" -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti $container_name cardano-cli "$@" +# Get the script's directory +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" + +# Helper function to get UTXO with validation +get_utxo() { + local address=$1 + local utxo_output + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) + local utxo + utxo=$(echo "$utxo_output" | jq -r 'keys[0]') + if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then + echo "Error: No UTXO found at address: $address" >&2 + exit 1 + fi + echo "$utxo" } + echo "Finding the previous Constitution GA to reference" -GOV_STATE=$(container_cli conway query gov-state | jq -r '.nextRatifyState.nextEnactState.prevGovActionIds') +# GOV_STATE=$(cardano_cli conway query gov-state | jq -r '.nextRatifyState.nextEnactState.prevGovActionIds') PREV_GA_TX_HASH=$(echo "$GOV_STATE" | jq -r '.Constitution.txId') PREV_GA_INDEX=$(echo "$GOV_STATE" | jq -r '.Constitution.govActionIx') @@ -49,9 +53,8 @@ echo "Previous Constitution GA Tx Hash: $PREV_GA_TX_HASH#$PREV_GA_INDEX" # Building, signing and submitting an new-constitution change governance action echo "Creating and submitting new-constitution governance action." -container_cli conway governance action create-constitution \ - --testnet \ - --governance-action-deposit $(container_cli conway query gov-state | jq -r '.currentPParams.govActionDeposit') \ +cardano_cli conway governance action create-constitution \ + --governance-action-deposit $(cardano_cli conway query gov-state | jq -r '.currentPParams.govActionDeposit') \ --deposit-return-stake-verification-key-file $keys_dir/stake.vkey \ --anchor-url "$METADATA_URL" \ --anchor-data-hash "$METADATA_HASH" \ @@ -66,15 +69,15 @@ container_cli conway governance action create-constitution \ echo "Building transaction" -container_cli conway transaction build \ - --tx-in "$(container_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ +cardano_cli conway transaction build \ + --tx-in "$(cardano_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ --proposal-file "$tx_cert_path" \ --change-address "$(cat $keys_dir/payment.addr)" \ --out-file "$tx_unsigned_path" \ echo "Signing transaction" -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file $keys_dir/payment.skey \ --out-file "$tx_signed_path" @@ -82,4 +85,4 @@ container_cli conway transaction sign \ # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file $tx_signed_path +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/ga/no-confidence.sh b/scripts/ga/no-confidence.sh index b9fe80a..23ce9f0 100755 --- a/scripts/ga/no-confidence.sh +++ b/scripts/ga/no-confidence.sh @@ -20,24 +20,28 @@ tx_cert_path="$tx_path_stub.action" tx_unsigned_path="$tx_path_stub.unsigned" tx_signed_path="$tx_path_stub.signed" -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti $container_name cardano-cli "$@" +# Get the script's directory +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" + +# Helper function to get UTXO with validation +get_utxo() { + local address=$1 + local utxo_output + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) + local utxo + utxo=$(echo "$utxo_output" | jq -r 'keys[0]') + if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then + echo "Error: No UTXO found at address: $address" >&2 + exit 1 + fi + echo "$utxo" } + echo "Finding the previous No Confidence to reference" -GOV_STATE=$(container_cli conway query gov-state | jq -r '.nextRatifyState.nextEnactState.prevGovActionIds') +GOV_STATE=$(cardano_cli conway query gov-state | jq -r '.nextRatifyState.nextEnactState.prevGovActionIds') PREV_GA_TX_HASH=$(echo "$GOV_STATE" | jq -r '.Committee.txId') PREV_GA_INDEX=$(echo "$GOV_STATE" | jq -r '.Committee.govActionIx') @@ -47,9 +51,8 @@ echo "Previous No Confidence GA: $PREV_GA_TX_HASH#$PREV_GA_INDEX" # Building, signing and submitting an no-confidence change governance action echo "Creating and submitting no-confidence governance action." -container_cli conway governance action create-no-confidence \ - --testnet \ - --governance-action-deposit $(container_cli conway query gov-state | jq -r '.currentPParams.govActionDeposit') \ +cardano_cli conway governance action create-no-confidence \ + --governance-action-deposit $(cardano_cli conway query gov-state | jq -r '.currentPParams.govActionDeposit') \ --deposit-return-stake-verification-key-file $keys_dir/stake.vkey \ --anchor-url "$METADATA_URL" \ --anchor-data-hash "$METADATA_HASH" \ @@ -60,15 +63,15 @@ container_cli conway governance action create-no-confidence \ echo "Building transaction" -container_cli conway transaction build \ - --tx-in "$(container_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ +cardano_cli conway transaction build \ + --tx-in "$(cardano_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ --proposal-file "$tx_cert_path" \ --change-address "$(cat $keys_dir/payment.addr)" \ --out-file "$tx_unsigned_path" \ echo "Signing transaction" -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file $keys_dir/payment.skey \ --out-file "$tx_signed_path" @@ -76,5 +79,4 @@ container_cli conway transaction sign \ # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file $tx_signed_path - +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/ga/parameter.sh b/scripts/ga/parameter.sh index c9f4adb..8340efa 100755 --- a/scripts/ga/parameter.sh +++ b/scripts/ga/parameter.sh @@ -17,46 +17,46 @@ tx_cert_path="$tx_path_stub.action" tx_unsigned_path="$tx_path_stub.unsigned" tx_signed_path="$tx_path_stub.signed" -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Extract network and version from container name (format: node-network-version-container) -network=$(echo $container_name | cut -d'-' -f2) -version=$(echo $container_name | cut -d'-' -f3) -guardrails_script_path="$project_root/node-$network-$version/config/guardrails-script.plutus" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti $container_name cardano-cli "$@" +guardrails_script_path="./config/guardrails-script.plutus" + +# Get the script's directory +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" + +# Helper function to get UTXO with validation +get_utxo() { + local address=$1 + local utxo_output + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) + local utxo + utxo=$(echo "$utxo_output" | jq -r 'keys[0]') + if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then + echo "Error: No UTXO found at address: $address" >&2 + exit 1 + fi + echo "$utxo" } + # Building, signing and submitting an parameter change governance action echo "Creating and submitting parameter change governance action." echo "Hashing guardrails script" -SCRIPT_HASH=$(container_cli hash script --script-file $guardrails_script_path) +SCRIPT_HASH=$(cardano_cli hash script --script-file $guardrails_script_path) echo "Script hash: $SCRIPT_HASH" echo "Finding the previous Parameter Change to reference" -GOV_STATE=$(container_cli conway query gov-state | jq -r '.nextRatifyState.nextEnactState.prevGovActionIds') +GOV_STATE=$(cardano_cli conway query gov-state | jq -r '.nextRatifyState.nextEnactState.prevGovActionIds') PREV_GA_TX_HASH=$(echo "$GOV_STATE" | jq -r '.PParamUpdate.txId') PREV_GA_INDEX=$(echo "$GOV_STATE" | jq -r '.PParamUpdate.govActionIx') echo "Previous Protocol Param Change GA: $PREV_GA_TX_HASH#$PREV_GA_INDEX" -container_cli conway governance action create-protocol-parameters-update \ - --testnet \ - --governance-action-deposit $(container_cli conway query gov-state | jq -r '.currentPParams.govActionDeposit') \ +cardano_cli conway governance action create-protocol-parameters-update \ + --governance-action-deposit $(cardano_cli conway query gov-state | jq -r '.currentPParams.govActionDeposit') \ --deposit-return-stake-verification-key-file $keys_dir/stake.vkey \ --anchor-url "$METADATA_URL" \ --anchor-data-hash "$METADATA_HASH" \ @@ -70,9 +70,9 @@ container_cli conway governance action create-protocol-parameters-update \ echo "Building transaction" -container_cli conway transaction build \ - --tx-in "$(container_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ - --tx-in-collateral "$(container_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ +cardano_cli conway transaction build \ + --tx-in "$(cardano_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ + --tx-in-collateral "$(cardano_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ --proposal-file "$tx_cert_path" \ --proposal-script-file $guardrails_script_path \ --proposal-redeemer-value {} \ @@ -81,7 +81,7 @@ container_cli conway transaction build \ echo "Signing transaction" -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file $keys_dir/payment.skey \ --out-file "$tx_signed_path" @@ -89,4 +89,4 @@ container_cli conway transaction sign \ # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file $tx_signed_path +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/ga/treasury.sh b/scripts/ga/treasury.sh index a2cbaae..de25996 100755 --- a/scripts/ga/treasury.sh +++ b/scripts/ga/treasury.sh @@ -23,37 +23,37 @@ tx_cert_path="$tx_path_stub.action" tx_unsigned_path="$tx_path_stub.unsigned" tx_signed_path="$tx_path_stub.signed" -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Extract network and version from container name (format: node-network-version-container) -network=$(echo $container_name | cut -d'-' -f2) -version=$(echo $container_name | cut -d'-' -f3) -guardrails_script_path="$project_root/node-$network-$version/config/guardrails-script.plutus" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti $container_name cardano-cli "$@" +guardrails_script_path="./config/guardrails-script.plutus" + +# Get the script's directory +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" + +# Helper function to get UTXO with validation +get_utxo() { + local address=$1 + local utxo_output + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) + local utxo + utxo=$(echo "$utxo_output" | jq -r 'keys[0]') + if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then + echo "Error: No UTXO found at address: $address" >&2 + exit 1 + fi + echo "$utxo" } + # Building, signing and submitting an treasury governance action echo "Creating and submitting treasury withdrawal governance action." echo "Hashing guardrails script" -SCRIPT_HASH=$(container_cli hash script --script-file $guardrails_script_path) +SCRIPT_HASH=$(cardano_cli hash script --script-file $guardrails_script_path) echo "Script hash: $SCRIPT_HASH" -container_cli conway governance action create-treasury-withdrawal \ - --testnet \ - --governance-action-deposit $(container_cli conway query gov-state | jq -r '.currentPParams.govActionDeposit') \ +cardano_cli conway governance action create-treasury-withdrawal \ + --governance-action-deposit $(cardano_cli conway query gov-state | jq -r '.currentPParams.govActionDeposit') \ --deposit-return-stake-verification-key-file $keys_dir/stake.vkey \ --anchor-url "$METADATA_URL" \ --anchor-data-hash "$METADATA_HASH" \ @@ -65,9 +65,9 @@ container_cli conway governance action create-treasury-withdrawal \ echo "Building transaction" -container_cli conway transaction build \ - --tx-in "$(container_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ - --tx-in-collateral "$(container_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ +cardano_cli conway transaction build \ + --tx-in "$(cardano_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ + --tx-in-collateral "$(cardano_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ --proposal-file "$tx_cert_path" \ --proposal-script-file $guardrails_script_path \ --proposal-redeemer-value {} \ @@ -76,11 +76,11 @@ container_cli conway transaction build \ echo "Signing transaction" -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file $keys_dir/payment.skey \ --out-file "$tx_signed_path" echo "Submitting transaction" -container_cli conway transaction submit --tx-file $tx_signed_path +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/generate-keys.sh b/scripts/generate-keys.sh index 1091bee..df0a54c 100755 --- a/scripts/generate-keys.sh +++ b/scripts/generate-keys.sh @@ -11,29 +11,21 @@ keys_dir="$project_root/keys" # Create keys directory if it doesn't exist mkdir -p "$keys_dir" -# Get the container name from the get-container script -container_name="$("$script_dir/helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -network=$(echo "$container_name" | cut -d'-' -f2) - -if [ "$network" = "mainnet" ]; then - echo "These scripts are not secure and should not be used to create mainnet transactions!!" - echo "Exiting." - exit 0 +# Source the cardano-cli wrapper +source "$script_dir/helper/cardano-cli-wrapper.sh" + +# Check network for mainnet warning (only in Docker mode) +if [ "$NODE_MODE" = "docker" ]; then + container_name="$("$script_dir/helper/get-container.sh")" + network=$(echo $container_name | cut -d'-' -f2) + + if [ "$network" = "mainnet" ]; then + echo "These scripts are not secure and should not be used to create mainnet transactions!!" + echo "Exiting." + exit 0 + fi fi -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} - # Check if keys already exist if [ -f "$keys_dir/drep.id" ]; then echo "Keys already generated." @@ -46,32 +38,32 @@ echo "Generating keys; payment, stake and DRep." echo "from keys, generate payment address, stake address and DRep ID." # Generate payment keys -container_cli address key-gen \ +cardano_cli address key-gen \ --verification-key-file "$keys_dir/payment.vkey" \ --signing-key-file "$keys_dir/payment.skey" # Generate stake keys -container_cli stake-address key-gen \ +cardano_cli stake-address key-gen \ --verification-key-file "$keys_dir/stake.vkey" \ --signing-key-file "$keys_dir/stake.skey" # Generate DRep keys -container_cli conway governance drep key-gen \ +cardano_cli conway governance drep key-gen \ --verification-key-file "$keys_dir/drep.vkey" \ --signing-key-file "$keys_dir/drep.skey" # Generate DRep ID -container_cli conway governance drep id \ +cardano_cli conway governance drep id \ --drep-verification-key-file "$keys_dir/drep.vkey" \ --out-file "$keys_dir/drep.id" # Get payment address from keys -container_cli address build \ +cardano_cli address build \ --payment-verification-key-file "$keys_dir/payment.vkey" \ --stake-verification-key-file "$keys_dir/stake.vkey" \ --out-file "$keys_dir/payment.addr" # Derive stake address from stake keys -container_cli stake-address build \ +cardano_cli stake-address build \ --stake-verification-key-file "$keys_dir/stake.vkey" \ --out-file "$keys_dir/stake.addr" \ No newline at end of file diff --git a/scripts/helper/cardano-cli-wrapper.sh b/scripts/helper/cardano-cli-wrapper.sh new file mode 100755 index 0000000..a40cd07 --- /dev/null +++ b/scripts/helper/cardano-cli-wrapper.sh @@ -0,0 +1,212 @@ +#!/bin/bash + +# Unified wrapper for cardano-cli that supports both Docker and external node modes +# This script should be sourced by other scripts + +# Define colors +CYAN='\033[0;36m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No color + +# Get the script's directory (works when sourced) +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +base_dir="$(cd "$script_dir/../.." && pwd)" + +# Load configuration +source "$script_dir/load-config.sh" + +# Function to convert host paths to container paths for Docker mode +convert_to_container_path() { + local path="$1" + if [ "$NODE_MODE" = "docker" ]; then + # Convert project root paths to container paths + # ./txs -> /txs + # ./keys -> /keys + # ./dumps -> /dumps + path=$(echo "$path" | sed "s|^$base_dir/txs|/txs|") + path=$(echo "$path" | sed "s|^$base_dir/keys|/keys|") + path=$(echo "$path" | sed "s|^$base_dir/dumps|/dumps|") + fi + echo "$path" +} + +# Check cardano-cli version and display node info (only once, when wrapper is sourced) +check_cardano_cli_version() { + if [ "$NODE_MODE" = "external" ]; then + if ! command -v cardano-cli &> /dev/null; then + echo "Warning: cardano-cli not found in PATH. External node mode requires cardano-cli to be installed locally." >&2 + return 1 + fi + + local cli_version=$(cardano-cli version 2>/dev/null | head -n 1 || echo "unknown") + # Clean up version string (remove "cardano-cli" prefix if present) + cli_version=$(echo "$cli_version" | sed 's/^cardano-cli //') + + if [ -n "${CARDANO_NETWORK:-}" ]; then + echo -e "${CYAN}Info:${NC} ${YELLOW}External node${NC} | ${GREEN}$CARDANO_NETWORK${NC} | ${BLUE}cardano-cli $cli_version${NC}" >&2 + else + echo -e "${CYAN}Info:${NC} ${YELLOW}External node${NC} | network ID: ${GREEN}${CARDANO_NODE_NETWORK_ID:-}${NC} | ${BLUE}cardano-cli $cli_version${NC}" >&2 + fi + elif [ "$NODE_MODE" = "docker" ]; then + # Get container name (only if explicitly set to avoid interactive selection) + local container_name="" + if [ -n "${CARDANO_CONTAINER_NAME:-}" ]; then + container_name="$CARDANO_CONTAINER_NAME" + elif [ -n "${CARDANO_CONTAINER_NAME_OVERRIDE:-}" ]; then + container_name="$CARDANO_CONTAINER_NAME_OVERRIDE" + else + # Only try to get container name if there's exactly one running container (non-interactive) + local running_count=$(docker ps --format '{{.Names}}' 2>/dev/null | grep -E '^node-' | wc -l | tr -d ' ') + if [ "$running_count" -eq 1 ]; then + container_name=$(docker ps --format '{{.Names}}' 2>/dev/null | grep -E '^node-' | head -n 1) + fi + fi + + if [ -n "$container_name" ]; then + # Extract network and version from container name (pattern: node-{network}-{version}-container) + local network="" + local node_version="" + if [[ "$container_name" =~ ^node-([^-]+)-([^-]+)-container$ ]]; then + network="${BASH_REMATCH[1]}" + node_version="${BASH_REMATCH[2]}" + fi + + # Get cardano-cli version from container + local cli_version=$(docker exec "$container_name" cardano-cli version 2>/dev/null | head -n 1 || echo "unknown") + # Clean up version string (remove "cardano-cli" prefix if present) + cli_version=$(echo "$cli_version" | sed 's/^cardano-cli //') + + if [ -n "$network" ] && [ -n "$node_version" ]; then + echo -e "${CYAN}Info:${NC} ${YELLOW}node v$node_version${NC} | ${GREEN}$network${NC} | ${BLUE}cardano-cli $cli_version${NC}" >&2 + else + echo -e "${CYAN}Info:${NC} ${YELLOW}Docker container: $container_name${NC} | ${BLUE}cardano-cli $cli_version${NC}" >&2 + fi + fi + fi +} + +# Get container name for Docker mode +get_container_name() { + if [ "$NODE_MODE" = "docker" ]; then + # Check for direct container name specification + if [ -n "${CARDANO_CONTAINER_NAME:-}" ]; then + # Verify the container exists and is running + if docker ps --format '{{.Names}}' | grep -q "^${CARDANO_CONTAINER_NAME}$"; then + echo "$CARDANO_CONTAINER_NAME" + return 0 + else + echo "Error: Container '$CARDANO_CONTAINER_NAME' is not running." >&2 + exit 1 + fi + fi + # Use get-container.sh (which handles CARDANO_CONTAINER_NAME_OVERRIDE) + "$script_dir/get-container.sh" + fi +} + +# Unified cardano-cli function +cardano_cli() { + local network_flag_args=() + local is_mainnet=false + local needs_network_flag=false + + # Check if command needs network flags + # Query commands that connect to node socket don't need network flags + # Commands that need network flags: address, transaction building, some key operations + local first_arg="${1:-}" + local second_arg="${2:-}" + + # Commands that typically need network flags + case "$first_arg" in + address|transaction|key) + needs_network_flag=true + ;; + query) + # Query commands don't need network flags when connecting via socket + needs_network_flag=false + ;; + *) + # For other commands, check if they're query-like (connect to node) + # If second arg is "query", it's a query command + if [ "$second_arg" = "query" ]; then + needs_network_flag=false + else + # Default to needing network flag for safety (address, transaction, etc.) + needs_network_flag=true + fi + ;; + esac + + # Determine network flag if needed + if [ "$needs_network_flag" = true ]; then + if [ -n "${CARDANO_NODE_NETWORK_ID:-}" ]; then + if [ "${CARDANO_NODE_NETWORK_ID:-}" = "764824073" ]; then + is_mainnet=true + network_flag_args=("--mainnet") + else + network_flag_args=("--testnet-magic" "$CARDANO_NODE_NETWORK_ID") + fi + elif [ -n "${CARDANO_NETWORK:-}" ]; then + case "$CARDANO_NETWORK" in + mainnet) + is_mainnet=true + network_flag_args=("--mainnet") + ;; + preprod) network_flag_args=("--testnet-magic" "1") ;; + preview) network_flag_args=("--testnet-magic" "2") ;; + sanchonet) network_flag_args=("--testnet-magic" "4") ;; + esac + fi + fi + + # Block mainnet connections for external nodes + # if [ "$NODE_MODE" = "external" ] && [ "$is_mainnet" = true ]; then + # echo "Error: Mainnet connections are not allowed. Please use testnet networks (preprod, preview, sanchonet) only." >&2 + # exit 1 + # fi + + if [ "$NODE_MODE" = "external" ]; then + # External node mode: use local cardano-cli with socket + # Set socket path via environment variable (works with all cardano-cli versions) + if [ ${#network_flag_args[@]} -gt 0 ]; then + CARDANO_NODE_SOCKET_PATH="$NODE_SOCKET_PATH" cardano-cli "${network_flag_args[@]}" "$@" + else + CARDANO_NODE_SOCKET_PATH="$NODE_SOCKET_PATH" cardano-cli "$@" + fi + else + # Docker mode: execute inside container + local container_name=$(get_container_name) + if [ -z "$container_name" ]; then + echo "Error: Failed to determine a running container." >&2 + exit 1 + fi + + # Convert file paths in arguments to container paths + # Look for file path arguments (those that contain the base directory path) + local converted_args=() + local prev_arg="" + for arg in "$@"; do + # Check if this argument contains the base directory path (it's a host file path) + if [[ "$arg" == "$base_dir"* ]]; then + # Convert host path to container path + converted_args+=("$(convert_to_container_path "$arg")") + else + # Not a host path, add as-is + converted_args+=("$arg") + fi + prev_arg="$arg" + done + + if [ ${#network_flag_args[@]} -gt 0 ]; then + docker exec -ti "$container_name" cardano-cli "${network_flag_args[@]}" "${converted_args[@]}" + else + docker exec -ti "$container_name" cardano-cli "${converted_args[@]}" + fi + fi +} + +# Call version check when wrapper is sourced +check_cardano_cli_version + diff --git a/scripts/helper/combine-utxos.sh b/scripts/helper/combine-utxos.sh index 01a6df5..acb047a 100755 --- a/scripts/helper/combine-utxos.sh +++ b/scripts/helper/combine-utxos.sh @@ -8,6 +8,11 @@ project_root=$(cd "$script_dir/../.." && pwd) # Define directory paths relative to project root keys_dir="$project_root/keys" txs_dir="$project_root/txs/helper" +tx_unsigned="$txs_dir/combine-utxos-tx.unsigned" +tx_signed="$txs_dir/combine-utxos-tx.signed" + +# Create transaction directory if it doesn't exist +mkdir -p "$txs_dir" # Check required files exist if [ ! -f "$keys_dir/payment.addr" ]; then @@ -21,30 +26,17 @@ if [ ! -f "$keys_dir/payment.skey" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/cardano-cli-wrapper.sh" payment_addr=$(cat "$keys_dir/payment.addr") echo "Combining all only ada UTxOs at $payment_addr" # build transaction -tx_unsigned="$txs_dir/combine-utxos-tx.unsigned" -tx_signed="$txs_dir/combine-utxos-tx.signed" -container_cli conway transaction build \ - $(container_cli conway query utxo --address "$payment_addr" --out-file /dev/stdout \ +cardano_cli conway transaction build \ + $(cardano_cli conway query utxo --address $(cat "$keys_dir/payment.addr") --out-file /dev/stdout \ | jq -r 'to_entries | map(select(.value.datum == null and .value.datumhash == null and .value.inlineDatum == null and .value.inlineDatumRaw == null and .value.referenceScript == null)) | map(" --tx-in " + .key) @@ -59,7 +51,8 @@ if [ ! -f "$tx_unsigned" ]; then fi # Sign transaction -container_cli conway transaction sign \ + +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned" \ --signing-key-file "$keys_dir/payment.skey" \ --out-file "$tx_signed" @@ -71,5 +64,6 @@ if [ ! -f "$tx_signed" ]; then fi # Submit transaction -container_cli conway transaction submit \ + +cardano_cli conway transaction submit \ --tx-file "$tx_signed" diff --git a/scripts/helper/get-container.sh b/scripts/helper/get-container.sh index 0ae075e..b672e03 100755 --- a/scripts/helper/get-container.sh +++ b/scripts/helper/get-container.sh @@ -1,6 +1,21 @@ #!/bin/bash # set -euo pipefail +# Get the list of running containers +# Supports CARDANO_CONTAINER_NAME_OVERRIDE environment variable + +# Check for container name override first +if [ -n "$CARDANO_CONTAINER_NAME_OVERRIDE" ]; then + # Verify the container exists and is running + if docker ps --format '{{.Names}}' | grep -q "^${CARDANO_CONTAINER_NAME_OVERRIDE}$"; then + echo "$CARDANO_CONTAINER_NAME_OVERRIDE" + exit 0 + else + echo "Error: Container '$CARDANO_CONTAINER_NAME_OVERRIDE' is not running." >&2 + exit 1 + fi +fi + # Get the list of running containers running_containers=$(docker ps --format '{{.Names}}') @@ -11,15 +26,21 @@ IFS=$'\n' read -r -d '' -a running_containers <<< "$running_containers" if [ ${#running_containers[@]} -eq 1 ]; then echo "${running_containers[0]}" elif [ ${#running_containers[@]} -gt 1 ]; then - select container_name in "${running_containers[@]}"; do - if [ -n "$container_name" ]; then - echo "$container_name" - break - else - echo "Invalid selection." - exit 1 - fi - done + # If running non-interactively (no TTY), use first container or fail + if [ ! -t 0 ]; then + echo "Warning: Multiple containers running but no TTY available. Using first container: ${running_containers[0]}" >&2 + echo "${running_containers[0]}" + else + select container_name in "${running_containers[@]}"; do + if [ -n "$container_name" ]; then + echo "$container_name" + break + else + echo "Invalid selection." + exit 1 + fi + done + fi else echo "No running containers found." exit 1 diff --git a/scripts/helper/load-config.sh b/scripts/helper/load-config.sh new file mode 100755 index 0000000..61e5d77 --- /dev/null +++ b/scripts/helper/load-config.sh @@ -0,0 +1,197 @@ +#!/bin/bash + +# Define colors +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +BLUE='\033[0;34m' +CYAN='\033[0;36m' +NC='\033[0m' # No color + +# Load configuration for node connection +# Sets: NODE_MODE, NODE_SOCKET_PATH, CARDANO_NETWORK, CARDANO_NODE_NETWORK_ID +# +# Priority: +# 1. CARDANO_CONTAINER_NAME (explicit container selection) +# 2. CARDANO_FORCE_DOCKER=true (force Docker mode) +# 3. Interactive selection if both Docker containers and external socket are available +# 4. External node: CARDANO_NODE_SOCKET_PATH + CARDANO_NODE_NETWORK_ID (environment variables) +# 5. Docker mode: Auto-select container (default) + +# Check for explicit container name (highest priority) +if [ -n "${CARDANO_CONTAINER_NAME:-}" ]; then + export NODE_MODE="docker" + return 0 +fi + +# Check for force Docker mode +if [ "${CARDANO_FORCE_DOCKER:-}" = "true" ] || [ "${CARDANO_FORCE_DOCKER:-}" = "1" ]; then + export NODE_MODE="docker" + return 0 +fi + +# Check if docker-compose.yml exists (indicates Docker setup is expected) +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +base_dir="$(cd "$script_dir/../.." && pwd)" +docker_compose_file="$base_dir/docker-compose.yml" + +# Get running containers +running_containers="" +if command -v docker &> /dev/null; then + running_containers=$(docker ps --format '{{.Names}}' 2>/dev/null | grep -E '^node-' || true) +fi + +# Safety check: If docker-compose.yml exists but no containers are running and no socket is set, +# user probably forgot to start Docker +if [ -f "$docker_compose_file" ] && [ -z "$running_containers" ] && [ -z "${CARDANO_NODE_SOCKET_PATH:-}" ]; then + echo "Error: Docker setup detected (docker-compose.yml exists) but no containers are running." >&2 + echo "Please start your Docker containers first:" >&2 + echo " ./start-node.sh" >&2 + exit 1 +fi + +# Check if we need interactive selection +# This happens when both Docker containers and external socket are available +if [ -n "${CARDANO_NODE_SOCKET_PATH:-}" ] && [ -n "$running_containers" ]; then + # Both Docker containers and external socket are available - let user choose + # Check if we're in an interactive terminal + if [ -t 0 ] && [ -t 1 ]; then + echo -e "${CYAN}Multiple node options available:${NC}" >&2 + echo "" >&2 + + # Build container array + container_array=() + while IFS= read -r container; do + [ -n "$container" ] && container_array+=("$container") + done <<< "$running_containers" + + socket_path="${CARDANO_NODE_SOCKET_PATH/#\~/$HOME}" + + # Display colored options + option_num=1 + for container in "${container_array[@]}"; do + echo -e "${BLUE} $option_num) ${GREEN}Docker:${NC} $container" >&2 + option_num=$((option_num + 1)) + done + echo -e "${BLUE} $option_num) ${YELLOW}External:${NC} $socket_path" >&2 + echo "" >&2 + echo -e "${CYAN}Select which node to use:${NC}" >&2 + + # Build plain options array for selection + options=() + for container in "${container_array[@]}"; do + options+=("docker:$container") + done + options+=("external:$socket_path") + + # Prompt user with colored prompt + while true; do + echo -ne "${CYAN}#? ${NC}" >&2 + read -r selection < /dev/tty + + # Validate input + if ! [[ "$selection" =~ ^[0-9]+$ ]] || [ "$selection" -lt 1 ] || [ "$selection" -gt ${#options[@]} ]; then + echo -e "${RED}Invalid selection. Please enter a number between 1 and ${#options[@]}.${NC}" >&2 + continue + fi + + # Get selected option (convert to 0-based index) + selected_index=$((selection - 1)) + choice="${options[$selected_index]}" + + if [[ "$choice" == docker:* ]]; then + # User selected Docker container + selected_container="${choice#docker:}" + export CARDANO_CONTAINER_NAME="$selected_container" + export NODE_MODE="docker" + echo -e "${GREEN}Selected: Docker: $selected_container${NC}" >&2 + return 0 + elif [[ "$choice" == external:* ]]; then + # User selected external node - continue with external node setup below + break + fi + done + fi +fi + +# Check for external node configuration (environment variables) +# External nodes use CARDANO_NODE_SOCKET_PATH and CARDANO_NODE_NETWORK_ID +if [ -n "${CARDANO_NODE_SOCKET_PATH:-}" ]; then + # Expand ~ to home directory + socket_path="${CARDANO_NODE_SOCKET_PATH/#\~/$HOME}" + + # Validate socket file exists first + if [ ! -S "$socket_path" ] && [ ! -f "$socket_path" ]; then + echo "Error: Socket file '$socket_path' does not exist or is not accessible." >&2 + echo "Please check that CARDANO_NODE_SOCKET_PATH points to a valid socket file." >&2 + exit 1 + fi + + # If no containers are running but socket is set and valid, ask for confirmation + if [ -z "$running_containers" ]; then + # Check if we're in an interactive terminal + if [ -t 0 ] && [ -t 1 ]; then + echo -e "${YELLOW}No Docker containers are running, but external socket path is configured:${NC}" >&2 + echo -e "${BLUE} $socket_path${NC}" >&2 + echo "" >&2 + echo -e "${CYAN}Do you want to use this external node? (y/n):${NC}" >&2 + read -r confirm < /dev/tty + if [ "$confirm" != "y" ] && [ "$confirm" != "Y" ]; then + echo -e "${YELLOW}Cancelled. Please start Docker containers or unset CARDANO_NODE_SOCKET_PATH.${NC}" >&2 + exit 0 + fi + else + # Non-interactive mode - can't ask for confirmation, so error out + echo -e "${RED}Error: No Docker containers are running and external socket is configured.${NC}" >&2 + echo -e "${YELLOW}Cannot prompt for confirmation in non-interactive mode.${NC}" >&2 + echo -e "${YELLOW}Please start Docker containers or run in an interactive terminal.${NC}" >&2 + exit 1 + fi + fi + + # Validate socket file extension + if [[ "$socket_path" != *.socket ]]; then + echo "Warning: Socket file should have .socket extension: $socket_path" >&2 + fi + + export NODE_MODE="external" + export NODE_SOCKET_PATH="$socket_path" + + # CARDANO_NODE_NETWORK_ID must be set for external nodes + if [ -z "${CARDANO_NODE_NETWORK_ID:-}" ]; then + echo "Error: CARDANO_NODE_NETWORK_ID must be set when using CARDANO_NODE_SOCKET_PATH" >&2 + exit 1 + fi + + # Validate network ID is numeric + if ! [[ "${CARDANO_NODE_NETWORK_ID:-}" =~ ^[0-9]+$ ]]; then + echo "Error: CARDANO_NODE_NETWORK_ID must be a number." >&2 + exit 1 + fi + + export CARDANO_NODE_NETWORK_ID + + # Block mainnet for external nodes + # if [ "${CARDANO_NODE_NETWORK_ID:-}" = "764824073" ]; then + # echo "Error: Mainnet connections via external sockets are not allowed for security reasons." >&2 + # echo "Please use Docker mode for mainnet, or set CARDANO_NODE_NETWORK_ID to a testnet value (1, 2, or 4)." >&2 + # exit 1 + # fi + + # Derive CARDANO_NETWORK from network ID if not set + if [ -z "${CARDANO_NETWORK:-}" ]; then + case "${CARDANO_NODE_NETWORK_ID:-}" in + 764824073) export CARDANO_NETWORK="mainnet" ;; + 1) export CARDANO_NETWORK="preprod" ;; + 2) export CARDANO_NETWORK="preview" ;; + 4) export CARDANO_NETWORK="sanchonet" ;; + esac + else + export CARDANO_NETWORK + fi + return 0 +fi + +# Default to Docker mode (will auto-select container) +export NODE_MODE="docker" + diff --git a/scripts/helper/sign-submit-tx.sh b/scripts/helper/sign-submit-tx.sh index a139bbb..77fedcd 100755 --- a/scripts/helper/sign-submit-tx.sh +++ b/scripts/helper/sign-submit-tx.sh @@ -27,25 +27,14 @@ if [ ! -f "$keys_dir/payment.skey" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/cardano-cli-wrapper.sh" # Send ada to the multisig payment script echo "Signing and submitting $tx_unsigned_path transaction." -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/payment.skey" \ --out-file "$tx_signed_path" @@ -59,4 +48,5 @@ fi # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" + +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/multi-sig/create-info-action.sh b/scripts/multi-sig/create-info-action.sh index cf4713b..50d1a4e 100755 --- a/scripts/multi-sig/create-info-action.sh +++ b/scripts/multi-sig/create-info-action.sh @@ -57,26 +57,15 @@ if [ ! -f "$keys_dir/payment.skey" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Helper function to get UTXO with validation get_utxo() { local address=$1 local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) local utxo utxo=$(echo "$utxo_output" | jq -r 'keys[0]') if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then @@ -86,13 +75,14 @@ get_utxo() { echo "$utxo" } + # Building, signing and submitting an info governance action echo "Creating and submitting info governance action, using the multi-sig's ada." -container_cli conway governance action create-info \ - --testnet \ - --governance-action-deposit "$(container_cli conway query gov-state | jq -r '.currentPParams.govActionDeposit')" \ - --deposit-return-stake-verification-key-file "$keys_dir/stake.vkey" \ + +cardano_cli conway governance action create-info \ + --governance-action-deposit $(cardano_cli conway query gov-state | jq -r '.currentPParams.govActionDeposit') \ + --deposit-return-stake-verification-key-file $keys_dir/stake.vkey \ --anchor-url "$METADATA_URL" \ --anchor-data-hash "$METADATA_HASH" \ --out-file "$tx_cert_path" @@ -105,16 +95,12 @@ fi echo "Building transaction" -script_addr=$(cat "$keys_dir/multi-sig/script.addr") -payment_addr=$(cat "$keys_dir/payment.addr") -script_utxo=$(get_utxo "$script_addr") -payment_utxo=$(get_utxo "$payment_addr") -container_cli conway transaction build \ - --tx-in "$script_utxo" \ - --tx-in-script-file "$keys_dir/multi-sig/script.json" \ - --tx-in "$payment_utxo" \ - --change-address "$payment_addr" \ +cardano_cli conway transaction build \ + --tx-in "$(cardano_cli conway query utxo --address "$(cat $keys_dir/multi-sig/script.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ + --tx-in-script-file $keys_dir/multi-sig/script.json \ + --tx-in "$(cardano_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ + --change-address "$(cat $keys_dir/payment.addr)" \ --proposal-file "$tx_cert_path" \ --required-signer-hash "$(cat "$keys_dir/multi-sig/1.keyhash")" \ --required-signer-hash "$(cat "$keys_dir/multi-sig/2.keyhash")" \ @@ -128,29 +114,29 @@ if [ ! -f "$tx_unsigned_path" ]; then fi # Create multisig witnesses -container_cli conway transaction witness \ +cardano_cli conway transaction witness \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/multi-sig/1.skey" \ --out-file "$tx_path_stub-1.witness" -container_cli conway transaction witness \ +cardano_cli conway transaction witness \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/multi-sig/2.skey" \ --out-file "$tx_path_stub-2.witness" -container_cli conway transaction witness \ +cardano_cli conway transaction witness \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/multi-sig/3.skey" \ --out-file "$tx_path_stub-3.witness" # Create witness -container_cli conway transaction witness \ +cardano_cli conway transaction witness \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/payment.skey" \ --out-file "$tx_path_stub-payment.witness" # Assemble Transaction -container_cli conway transaction assemble \ +cardano_cli conway transaction assemble \ --tx-body-file "$tx_unsigned_path" \ --witness-file "$tx_path_stub-payment.witness" \ --witness-file "$tx_path_stub-1.witness" \ @@ -167,4 +153,5 @@ fi # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" + +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/multi-sig/create-param-action.sh b/scripts/multi-sig/create-param-action.sh index 3d6dcfe..f5808a3 100755 --- a/scripts/multi-sig/create-param-action.sh +++ b/scripts/multi-sig/create-param-action.sh @@ -57,29 +57,15 @@ if [ ! -f "$keys_dir/payment.skey" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Extract network from container name (format: node-network-version-container) -network=$(echo "$container_name" | cut -d'-' -f2) - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Helper function to get UTXO with validation get_utxo() { local address=$1 local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) local utxo utxo=$(echo "$utxo_output" | jq -r 'keys[0]') if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then @@ -89,6 +75,7 @@ get_utxo() { echo "$utxo" } + echo "\nPull the latest guardrails script." # Use network-specific URL (mainnet uses world.dev, testnets use play.dev) if [ "$network" = "mainnet" ]; then @@ -105,16 +92,17 @@ if [ ! -f "$txs_dir/guardrails-script.plutus" ]; then fi echo "\nGet the guardrails script hash from the genesis file." -SCRIPT_HASH=$(container_cli hash script --script-file "$txs_dir/guardrails-script.plutus") + +SCRIPT_HASH=$(cardano_cli hash script --script-file $txs_dir/guardrails-script.plutus) echo "Script hash: $SCRIPT_HASH" # Building, signing and submitting an parameter update governance action echo "Creating and submitting protocol param update governance action, using the multi-sig's ada." -container_cli conway governance action create-protocol-parameters-update \ - --testnet \ - --governance-action-deposit "$(container_cli conway query gov-state | jq -r '.currentPParams.govActionDeposit')" \ - --deposit-return-stake-verification-key-file "$keys_dir/stake.vkey" \ + +cardano_cli conway governance action create-protocol-parameters-update \ + --governance-action-deposit $(cardano_cli conway query gov-state | jq -r '.currentPParams.govActionDeposit') \ + --deposit-return-stake-verification-key-file $keys_dir/stake.vkey \ --anchor-url "$METADATA_URL" \ --anchor-data-hash "$METADATA_HASH" \ --constitution-script-hash "$SCRIPT_HASH" \ @@ -129,17 +117,13 @@ fi echo "Building transaction" -script_addr=$(cat "$keys_dir/multi-sig/script.addr") -payment_addr=$(cat "$keys_dir/payment.addr") -script_utxo=$(get_utxo "$script_addr") -payment_utxo=$(get_utxo "$payment_addr") - -container_cli conway transaction build \ - --tx-in "$script_utxo" \ - --tx-in-script-file "$keys_dir/multi-sig/script.json" \ - --tx-in "$payment_utxo" \ - --tx-in-collateral "$payment_utxo" \ - --change-address "$payment_addr" \ + +cardano_cli conway transaction build \ + --tx-in "$(cardano_cli conway query utxo --address "$(cat $keys_dir/multi-sig/script.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ + --tx-in-script-file $keys_dir/multi-sig/script.json \ + --tx-in "$(cardano_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ + --tx-in-collateral "$(cardano_cli conway query utxo --address "$(cat $keys_dir/payment.addr)" --out-file /dev/stdout | jq -r 'keys[0]')" \ + --change-address "$(cat $keys_dir/payment.addr)" \ --proposal-file "$tx_cert_path" \ --proposal-script-file "$txs_dir/guardrails-script.plutus" \ --proposal-redeemer-value {} \ @@ -155,29 +139,29 @@ if [ ! -f "$tx_unsigned_path" ]; then fi # Create multisig witnesses -container_cli conway transaction witness \ +cardano_cli conway transaction witness \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/multi-sig/1.skey" \ --out-file "$tx_path_stub-1.witness" -container_cli conway transaction witness \ +cardano_cli conway transaction witness \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/multi-sig/2.skey" \ --out-file "$tx_path_stub-2.witness" -container_cli conway transaction witness \ +cardano_cli conway transaction witness \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/multi-sig/3.skey" \ --out-file "$tx_path_stub-3.witness" # Create witness -container_cli conway transaction witness \ +cardano_cli conway transaction witness \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/payment.skey" \ --out-file "$tx_path_stub-payment.witness" # Assemble Transaction -container_cli conway transaction assemble \ +cardano_cli conway transaction assemble \ --tx-body-file "$tx_unsigned_path" \ --witness-file "$tx_path_stub-payment.witness" \ --witness-file "$tx_path_stub-1.witness" \ @@ -194,4 +178,5 @@ fi # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" + +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/multi-sig/drep-metadata.sh b/scripts/multi-sig/drep-metadata.sh index d0674d1..cd59151 100755 --- a/scripts/multi-sig/drep-metadata.sh +++ b/scripts/multi-sig/drep-metadata.sh @@ -50,26 +50,15 @@ if [ ! -f "$txs_dir/metadata.json" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Helper function to get UTXO with validation get_utxo() { local address=$1 local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) local utxo utxo=$(echo "$utxo_output" | jq -r 'keys[0]') if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then @@ -79,30 +68,26 @@ get_utxo() { echo "$utxo" } -echo "Building DRep Update Certificate" -container_cli conway governance drep update-certificate \ - --drep-script-hash "$(cat "$txs_dir/drep-one-sig.id")" \ - --out-file "$tx_cert_path" +echo "Building DRep Update Certificate" -# Check certificate file was created -if [ ! -f "$tx_cert_path" ]; then - echo "Error: Failed to create certificate file" - exit 1 -fi +cardano_cli conway governance drep update-certificate \ + --drep-script-hash $(cat $txs_dir/drep-one-sig.id) \ + --out-file $tx_cert_path echo "Building transaction" payment_addr=$(cat "$keys_dir/payment.addr") utxo=$(get_utxo "$payment_addr") -container_cli conway transaction build \ - --tx-in "$utxo" \ - --change-address "$payment_addr" \ - --required-signer-hash "$(cat "$keys_dir/multi-sig/1.keyhash")" \ - --certificate-file "$tx_cert_path" \ - --certificate-script-file "$txs_dir/drep-one-sig.json" \ - --metadata-json-file "$txs_dir/metadata.json" \ + +cardano_cli conway transaction build \ + --tx-in $(cardano_cli conway query utxo --address $(cat $keys_dir/payment.addr) --out-file /dev/stdout | jq -r 'keys[0]') \ + --change-address $(cat $keys_dir/payment.addr) \ + --required-signer-hash "$(cat $keys_dir/multi-sig/1.keyhash)" \ + --certificate-file $tx_cert_path \ + --certificate-script-file $txs_dir/drep-one-sig.json \ + --metadata-json-file $txs_dir/metadata.json \ --out-file "$tx_unsigned_path" # Check transaction file was created @@ -112,19 +97,19 @@ if [ ! -f "$tx_unsigned_path" ]; then fi # Create multisig witnesses -container_cli conway transaction witness \ +cardano_cli conway transaction witness \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/multi-sig/1.skey" \ --out-file "$tx_path_stub-1.witness" # Create witness -container_cli conway transaction witness \ +cardano_cli conway transaction witness \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/payment.skey" \ --out-file "$tx_path_stub-payment.witness" # Assemble Transaction -container_cli conway transaction assemble \ +cardano_cli conway transaction assemble \ --tx-body-file "$tx_unsigned_path" \ --witness-file "$tx_path_stub-payment.witness" \ --witness-file "$tx_path_stub-1.witness" \ @@ -139,4 +124,5 @@ fi # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" + +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/multi-sig/generate-keys-and-script.sh b/scripts/multi-sig/generate-keys-and-script.sh index 2eacbc8..8948a57 100755 --- a/scripts/multi-sig/generate-keys-and-script.sh +++ b/scripts/multi-sig/generate-keys-and-script.sh @@ -15,20 +15,9 @@ if [ ! -f "$scripts_dir/multi-sig/multi-sig-template.json" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" echo "Creating three keys to control a multi-sig script." @@ -36,28 +25,29 @@ echo "Creating three keys to control a multi-sig script." mkdir -p "$keys_dir/multi-sig" # Key 1 -container_cli address key-gen \ - --verification-key-file "$keys_dir/multi-sig/1.vkey" \ - --signing-key-file "$keys_dir/multi-sig/1.skey" -container_cli address key-hash \ - --payment-verification-key-file "$keys_dir/multi-sig/1.vkey" > "$keys_dir/multi-sig/1.keyhash" +cardano_cli address key-gen \ + --verification-key-file keys/multi-sig/1.vkey \ + --signing-key-file keys/multi-sig/1.skey + +cardano_cli address key-hash \ + --payment-verification-key-file keys/multi-sig/1.vkey > keys/multi-sig/1.keyhash # Key 2 -container_cli address key-gen \ - --verification-key-file "$keys_dir/multi-sig/2.vkey" \ - --signing-key-file "$keys_dir/multi-sig/2.skey" +cardano_cli address key-gen \ + --verification-key-file keys/multi-sig/2.vkey \ + --signing-key-file keys/multi-sig/2.skey -container_cli address key-hash \ - --payment-verification-key-file "$keys_dir/multi-sig/2.vkey" > "$keys_dir/multi-sig/2.keyhash" +cardano_cli address key-hash \ + --payment-verification-key-file keys/multi-sig/2.vkey > keys/multi-sig/2.keyhash # Key 3 -container_cli address key-gen \ - --verification-key-file "$keys_dir/multi-sig/3.vkey" \ - --signing-key-file "$keys_dir/multi-sig/3.skey" +cardano_cli address key-gen \ + --verification-key-file keys/multi-sig/3.vkey \ + --signing-key-file keys/multi-sig/3.skey -container_cli address key-hash \ - --payment-verification-key-file "$keys_dir/multi-sig/3.vkey" > "$keys_dir/multi-sig/3.keyhash" +cardano_cli address key-hash \ + --payment-verification-key-file keys/multi-sig/3.vkey > keys/multi-sig/3.keyhash echo "Copying the script template." @@ -74,7 +64,7 @@ jq --arg kh1 "$(tr -d '\r' < "$keys_dir/multi-sig/1.keyhash")" \ echo "Creating script address." -container_cli address build \ +cardano_cli address build \ --payment-script-file "$keys_dir/multi-sig/script.json" \ --out-file "$keys_dir/multi-sig/script.addr" diff --git a/scripts/multi-sig/query-multisig.sh b/scripts/multi-sig/query-multisig.sh index b42e6e3..ca0c618 100755 --- a/scripts/multi-sig/query-multisig.sh +++ b/scripts/multi-sig/query-multisig.sh @@ -15,25 +15,15 @@ if [ ! -f "$keys_dir/multi-sig/script.addr" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" script_addr=$(cat "$keys_dir/multi-sig/script.addr") echo "Querying UTXOs for your multisig script address: $script_addr" # Query the UTxOs controlled by multisig script address -container_cli conway query utxo \ - --address "$script_addr" \ - --out-file /dev/stdout \ No newline at end of file + +cardano_cli conway query utxo \ + --address "$(cat $keys_dir/multi-sig/script.addr)" \ + --out-file /dev/stdout diff --git a/scripts/multi-sig/send-ada-from-script.sh b/scripts/multi-sig/send-ada-from-script.sh index de884fa..3abfcba 100755 --- a/scripts/multi-sig/send-ada-from-script.sh +++ b/scripts/multi-sig/send-ada-from-script.sh @@ -50,26 +50,15 @@ if [ ! -f "$keys_dir/payment.skey" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Helper function to get UTXO with validation get_utxo() { local address=$1 local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) local utxo utxo=$(echo "$utxo_output" | jq -r 'keys[0]') if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then @@ -79,55 +68,47 @@ get_utxo() { echo "$utxo" } + # Send ada to the multisig payment script echo "Sending $LOVELACE_AMOUNT lovelace to the payment address from the script." echo "Building transaction" -script_addr=$(cat "$keys_dir/multi-sig/script.addr") -payment_addr=$(cat "$keys_dir/payment.addr") -script_utxo=$(get_utxo "$script_addr") - -container_cli conway transaction build \ - --tx-in "$script_utxo" \ - --tx-in-script-file "$keys_dir/multi-sig/script.json" \ - --tx-out "$payment_addr+$LOVELACE_AMOUNT" \ - --change-address "$script_addr" \ - --required-signer-hash "$(cat "$keys_dir/multi-sig/1.keyhash")" \ - --required-signer-hash "$(cat "$keys_dir/multi-sig/2.keyhash")" \ - --required-signer-hash "$(cat "$keys_dir/multi-sig/3.keyhash")" \ - --out-file "$tx_unsigned_path" -# Check transaction file was created -if [ ! -f "$tx_unsigned_path" ]; then - echo "Error: Failed to create unsigned transaction file" - exit 1 -fi +cardano_cli conway transaction build \ + --tx-in $(cardano_cli conway query utxo --address $(cat $keys_dir/multi-sig/script.addr) --out-file /dev/stdout | jq -r 'keys[0]') \ + --tx-in-script-file $keys_dir/multi-sig/script.json \ + --tx-out $(cat $keys_dir/payment.addr)+$LOVELACE_AMOUNT \ + --change-address $(cat $keys_dir/multi-sig/script.addr) \ + --required-signer-hash "$(cat $keys_dir/multi-sig/1.keyhash)" \ + --required-signer-hash "$(cat $keys_dir/multi-sig/2.keyhash)" \ + --required-signer-hash "$(cat $keys_dir/multi-sig/3.keyhash)" \ + --out-file "$tx_unsigned_path" # Create multisig witnesses -container_cli conway transaction witness \ +cardano_cli conway transaction witness \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/multi-sig/1.skey" \ --out-file "$tx_path_stub-1.witness" -container_cli conway transaction witness \ +cardano_cli conway transaction witness \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/multi-sig/2.skey" \ --out-file "$tx_path_stub-2.witness" -container_cli conway transaction witness \ +cardano_cli conway transaction witness \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/multi-sig/3.skey" \ --out-file "$tx_path_stub-3.witness" # Create witness -container_cli conway transaction witness \ +cardano_cli conway transaction witness \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/payment.skey" \ --out-file "$tx_path_stub-payment.witness" # Assemble Transaction -container_cli conway transaction assemble \ +cardano_cli conway transaction assemble \ --tx-body-file "$tx_unsigned_path" \ --witness-file "$tx_path_stub-payment.witness" \ --witness-file "$tx_path_stub-1.witness" \ @@ -144,4 +125,5 @@ fi # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" + +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/multi-sig/send-ada-to-script.sh b/scripts/multi-sig/send-ada-to-script.sh index 4966eb0..a613a11 100755 --- a/scripts/multi-sig/send-ada-to-script.sh +++ b/scripts/multi-sig/send-ada-to-script.sh @@ -34,26 +34,15 @@ if [ ! -f "$keys_dir/multi-sig/script.addr" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Helper function to get UTXO with validation get_utxo() { local address=$1 local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) local utxo utxo=$(echo "$utxo_output" | jq -r 'keys[0]') if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then @@ -63,28 +52,20 @@ get_utxo() { echo "$utxo" } + # Send ada to the multisig payment script echo "Sending $LOVELACE_AMOUNT lovelace to the multisig payment address." echo "Building transaction" -payment_addr=$(cat "$keys_dir/payment.addr") -script_addr=$(cat "$keys_dir/multi-sig/script.addr") -utxo=$(get_utxo "$payment_addr") -container_cli conway transaction build \ - --tx-in "$utxo" \ - --tx-out "$script_addr+$LOVELACE_AMOUNT" \ - --change-address "$payment_addr" \ +cardano_cli conway transaction build \ + --tx-in $(cardano_cli conway query utxo --address $(cat $keys_dir/payment.addr) --out-file /dev/stdout | jq -r 'keys[0]') \ + --tx-out $(cat $keys_dir/multi-sig/script.addr)+$LOVELACE_AMOUNT \ + --change-address $(cat $keys_dir/payment.addr) \ --out-file "$tx_unsigned_path" -# Check transaction file was created -if [ ! -f "$tx_unsigned_path" ]; then - echo "Error: Failed to create unsigned transaction file" - exit 1 -fi - -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/payment.skey" \ --out-file "$tx_signed_path" @@ -98,4 +79,5 @@ fi # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" + +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/multi-sig/stake-multisig.sh b/scripts/multi-sig/stake-multisig.sh index 8e8ce14..9278d58 100755 --- a/scripts/multi-sig/stake-multisig.sh +++ b/scripts/multi-sig/stake-multisig.sh @@ -40,26 +40,15 @@ if [ ! -f "$txs_dir/drep-one-sig.json" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Helper function to get UTXO with validation get_utxo() { local address=$1 local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) local utxo utxo=$(echo "$utxo_output" | jq -r 'keys[0]') if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then @@ -69,11 +58,12 @@ get_utxo() { echo "$utxo" } + echo "Registering your multi-sig as a stake credential." -container_cli conway stake-address registration-certificate \ - --stake-script-file "$txs_dir/drep-one-sig.json" \ - --key-reg-deposit-amt "$(container_cli conway query gov-state | jq -r '.currentPParams.stakeAddressDeposit')" \ +cardano_cli conway stake-address registration-certificate \ + --stake-script-file $txs_dir/drep-one-sig.json \ + --key-reg-deposit-amt "$(cardano_cli conway query gov-state | jq -r .currentPParams.stakeAddressDeposit)" \ --out-file "$tx_cert_path" # Check certificate file was created @@ -84,15 +74,13 @@ fi echo "Building transaction" -payment_addr=$(cat "$keys_dir/payment.addr") -utxo=$(get_utxo "$payment_addr") -container_cli conway transaction build \ - --tx-in "$utxo" \ - --change-address "$payment_addr" \ - --required-signer-hash "$(cat "$keys_dir/multi-sig/1.keyhash")" \ - --certificate-file "$tx_cert_path" \ - --certificate-script-file "$txs_dir/drep-one-sig.json" \ +cardano_cli conway transaction build \ + --tx-in $(cardano_cli conway query utxo --address $(cat $keys_dir/payment.addr) --out-file /dev/stdout | jq -r 'keys[0]') \ + --change-address $(cat $keys_dir/payment.addr) \ + --required-signer-hash "$(cat $keys_dir/multi-sig/1.keyhash)" \ + --certificate-file $tx_cert_path \ + --certificate-script-file $txs_dir/drep-one-sig.json \ --out-file "$tx_unsigned_path" # Check transaction file was created @@ -102,19 +90,19 @@ if [ ! -f "$tx_unsigned_path" ]; then fi # Create multisig witnesses -container_cli conway transaction witness \ +cardano_cli conway transaction witness \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/multi-sig/1.skey" \ --out-file "$tx_path_stub-1.witness" # Create witness -container_cli conway transaction witness \ +cardano_cli conway transaction witness \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/payment.skey" \ --out-file "$tx_path_stub-payment.witness" # Assemble Transaction -container_cli conway transaction assemble \ +cardano_cli conway transaction assemble \ --tx-body-file "$tx_unsigned_path" \ --witness-file "$tx_path_stub-payment.witness" \ --witness-file "$tx_path_stub-1.witness" \ @@ -129,4 +117,5 @@ fi # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" + +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/query/dump-node-state.sh b/scripts/query/dump-node-state.sh index a783f82..7c8749e 100755 --- a/scripts/query/dump-node-state.sh +++ b/scripts/query/dump-node-state.sh @@ -8,70 +8,70 @@ project_root=$(cd "$script_dir/.." && pwd) # Define directory paths relative to project root dumps_dir="$project_root/dumps" -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." +# Get the network name +if [ -n "$CARDANO_NETWORK" ]; then + network="$CARDANO_NETWORK" +elif [ "$NODE_MODE" = "docker" ]; then + # For Docker mode, extract from container name + container_name="$("$script_dir/../helper/get-container.sh")" + network=$(echo $container_name | cut -d'-' -f2) +else + echo "Error: Could not determine network name. Please set CARDANO_NETWORK environment variable." >&2 exit 1 fi -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} - -# Get the network name - -# Split the container name and extract the second part -network=$(echo "$container_name" | cut -d'-' -f2) - -# Create dumps directory if it doesn't exist -mkdir -p "$dumps_dir/$network" # Dumping out CC state echo "Dumping constitutional committee state." -container_cli conway query committee-state > "$dumps_dir/$network/committee.json" +cardano_cli conway query committee-state > ./dumps/$network/committee.json # Dumping out constitution state echo "Dumping constitution state." -container_cli conway query constitution > "$dumps_dir/$network/constitution.json" + +cardano_cli conway query constitution > ./dumps/$network/constitution.json # Query DReps from ledger state echo "Dumping DReps from ledger state." -container_cli conway query drep-state \ - --all-dreps > "$dumps_dir/$network/dreps-info.json" -container_cli conway query drep-stake-distribution \ - --all-dreps > "$dumps_dir/$network/dreps-power.json" +cardano_cli conway query drep-state \ + --all-dreps > ./dumps/$network/dreps-info.json + +cardano_cli conway query drep-stake-distribution \ + --all-dreps > ./dumps/$network/dreps-power.json # Dumping governance ledger state echo "Dumping whole governance state from ledger state." -container_cli conway query gov-state > "$dumps_dir/$network/gov-state.json" + +cardano_cli conway query gov-state > ./dumps/$network/gov-state.json # Dumping proposals stored in ledger state echo "Dumping governance actions from ledger state." -container_cli conway query gov-state | jq -r '.proposals' > "$dumps_dir/$network/governance-actions.json" + +cardano_cli conway query gov-state | jq -r '.proposals' > ./dumps/$network/governance-actions.json # Dumping out parameters state echo "Dumping protocol parameters state." -container_cli conway query protocol-parameters > "$dumps_dir/$network/params.json" + +cardano_cli conway query protocol-parameters > ./dumps/$network/params.json # Dumping out SPO state echo "Dumping SPO stake distribution state." -container_cli conway query spo-stake-distribution \ - --all-spos > "$dumps_dir/$network/spo-stake.json" + +cardano_cli conway query spo-stake-distribution \ + --all-spos > ./dumps/$network/spo-stake.json # Dumping out SPO state echo "Dumping treasury state." -container_cli conway query treasury > "$dumps_dir/$network/treasury.json" \ No newline at end of file + +cardano_cli conway query treasury > ./dumps/$network/treasury.json diff --git a/scripts/query/own-utxos.sh b/scripts/query/own-utxos.sh index 1c9bb36..61dbf0b 100755 --- a/scripts/query/own-utxos.sh +++ b/scripts/query/own-utxos.sh @@ -15,25 +15,15 @@ if [ ! -f "$keys_dir/payment.addr" ]; then exit 0 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" payment_addr=$(cat "$keys_dir/payment.addr") echo "Querying UTXOs for your address: $payment_addr" # Query the UTxOs controlled by the payment address -container_cli conway query utxo \ - --address "$payment_addr" \ - --out-file /dev/stdout \ No newline at end of file + +cardano_cli conway query utxo \ + --address "$(cat $keys_dir/payment.addr)" \ + --out-file /dev/stdout diff --git a/scripts/query/stake-info.sh b/scripts/query/stake-info.sh index 36f93e0..717afea 100755 --- a/scripts/query/stake-info.sh +++ b/scripts/query/stake-info.sh @@ -21,24 +21,14 @@ if [ ! -f "$keys_dir/stake.addr" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" stake_addr=$(cat "$keys_dir/stake.addr") echo "Querying Stake Account info for your address: $stake_addr" -container_cli conway query stake-address-info \ - --address "$stake_addr" \ - --out-file /dev/stdout + +cardano_cli conway query stake-address-info \ + --address "$(cat $keys_dir/stake.addr)" \ + --out-file /dev/stdout diff --git a/scripts/query/stake-pools.sh b/scripts/query/stake-pools.sh index d56fb26..5b69617 100755 --- a/scripts/query/stake-pools.sh +++ b/scripts/query/stake-pools.sh @@ -4,20 +4,9 @@ set -euo pipefail # Get the script's directory script_dir=$(dirname "$0") -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Query the stake pools -container_cli conway query stake-pools \ No newline at end of file +cardano_cli conway query stake-pools \ No newline at end of file diff --git a/scripts/query/tip.sh b/scripts/query/tip.sh index 287a9f8..c790bb6 100755 --- a/scripts/query/tip.sh +++ b/scripts/query/tip.sh @@ -4,20 +4,8 @@ set -euo pipefail # Get the script's directory script_dir=$(dirname "$0") -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Query the tip of the blockchain as observed by the node -container_cli conway query tip \ No newline at end of file +cardano_cli conway query tip \ No newline at end of file diff --git a/scripts/query/utxos-for-address.sh b/scripts/query/utxos-for-address.sh index 04e0f56..743b195 100755 --- a/scripts/query/utxos-for-address.sh +++ b/scripts/query/utxos-for-address.sh @@ -12,24 +12,13 @@ project_root=$(cd "$script_dir/../.." && pwd) # Define directory paths relative to project root keys_dir="$project_root/keys" -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" echo "Querying UTXOs for address: $ADDRESS" # Query the UTxOs controlled by the payment address -container_cli conway query utxo \ +cardano_cli conway query utxo \ --address "$ADDRESS" \ --out-file /dev/stdout \ No newline at end of file diff --git a/scripts/simple/metadata-tx.sh b/scripts/simple/metadata-tx.sh index 97b17b8..6ffd8e9 100755 --- a/scripts/simple/metadata-tx.sh +++ b/scripts/simple/metadata-tx.sh @@ -33,26 +33,15 @@ if [ ! -f "$txs_dir/metadata.json" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Helper function to get UTXO with validation get_utxo() { local address=$1 local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) local utxo utxo=$(echo "$utxo_output" | jq -r 'keys[0]') if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then @@ -62,24 +51,16 @@ get_utxo() { echo "$utxo" } -echo "Building transaction" -payment_addr=$(cat "$keys_dir/payment.addr") -utxo=$(get_utxo "$payment_addr") +echo "Building transaction" -container_cli conway transaction build \ - --tx-in "$utxo" \ - --change-address "$payment_addr" \ +cardano_cli conway transaction build \ + --tx-in $(cardano_cli conway query utxo --address $(cat $keys_dir/payment.addr) --out-file /dev/stdout | jq -r 'keys[0]') \ + --change-address $(cat $keys_dir/payment.addr) \ --metadata-json-file "$txs_dir/metadata.json" \ --out-file "$tx_unsigned_path" -# Check transaction file was created -if [ ! -f "$tx_unsigned_path" ]; then - echo "Error: Failed to create unsigned transaction file" - exit 1 -fi - -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/payment.skey" \ --out-file "$tx_signed_path" @@ -93,4 +74,5 @@ fi # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" + +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/simple/send-ada.sh b/scripts/simple/send-ada.sh index 5eb11d9..eb738d6 100755 --- a/scripts/simple/send-ada.sh +++ b/scripts/simple/send-ada.sh @@ -29,56 +29,23 @@ if [ ! -f "$keys_dir/payment.skey" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} - -# Helper function to get UTXO with validation -get_utxo() { - local address=$1 - local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) - local utxo - utxo=$(echo "$utxo_output" | jq -r 'keys[0]') - if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then - echo "Error: No UTXO found at address: $address" >&2 - exit 1 - fi - echo "$utxo" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Send ada to the multisig payment script echo "Sending $LOVELACE_AMOUNT lovelace to $ADDRESS." -payment_addr=$(cat "$keys_dir/payment.addr") -utxo=$(get_utxo "$payment_addr") echo "Building transaction" -container_cli conway transaction build \ - --tx-in "$utxo" \ - --tx-out "$ADDRESS+$LOVELACE_AMOUNT" \ - --change-address "$payment_addr" \ +cardano_cli conway transaction build \ + --tx-in $(cardano_cli conway query utxo --address $(cat $keys_dir/payment.addr) --out-file /dev/stdout | jq -r 'keys[0]') \ + --tx-out "$ADDRESS"+$LOVELACE_AMOUNT \ + --change-address $(cat $keys_dir/payment.addr) \ --out-file "$tx_unsigned_path" -# Check transaction file was created -if [ ! -f "$tx_unsigned_path" ]; then - echo "Error: Failed to create unsigned transaction file" - exit 1 -fi - -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/payment.skey" \ --out-file "$tx_signed_path" @@ -92,4 +59,5 @@ fi # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" + +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/simple/send-to-many.sh b/scripts/simple/send-to-many.sh index ee8d7f9..ff5c554 100755 --- a/scripts/simple/send-to-many.sh +++ b/scripts/simple/send-to-many.sh @@ -1,10 +1,6 @@ #!/bin/bash set -euo pipefail -# ~~~~~~~~~~~~ CHANGE THIS ~~~~~~~~~~~~ -LOVELACE_AMOUNT=1230000 -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - # Get the script's directory and project root script_dir=$(dirname "$0") project_root=$(cd "$script_dir/../.." && pwd) @@ -12,12 +8,20 @@ project_root=$(cd "$script_dir/../.." && pwd) # Define directory paths relative to project root keys_dir="$project_root/keys" txs_dir="$project_root/txs/simple" -CSV_FILE="$keys_dir/addresses-testnet.csv" -METADATA_FILE="$keys_dir/metadata-testnet.json" tx_path_stub="$txs_dir/send-to-many" tx_unsigned_path="$tx_path_stub.unsigned" tx_signed_path="$tx_path_stub.signed" +# ~~~~~~~~~~~~ CHANGE THIS ~~~~~~~~~~~~ +LOVELACE_AMOUNT=1000000 + +CSV_FILE=$project_root/utilities/committee-rewards-addresses.csv +METADATA_FILE=$project_root/utilities/committee-rewards-metadata.json + +PAYMENT_ADDR="addr1qx93k28kzzu4fng49cfcj8w7m8px36wf9z8j94638lu8cw574gazl7xgwlxg4uxe4ytwnttj8qw489waumt82gx5jdtqwh8hn0" +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + # Check required files exist if [ ! -f "$keys_dir/payment.addr" ]; then echo "Error: Payment address file not found: $keys_dir/payment.addr" @@ -30,34 +34,9 @@ if [ ! -f "$keys_dir/payment.skey" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} - -# Helper function to get UTXO with validation -get_utxo() { - local address=$1 - local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) - local utxo - utxo=$(echo "$utxo_output" | jq -r 'keys[0]') - if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then - echo "Error: No UTXO found at address: $address" >&2 - exit 1 - fi - echo "$utxo" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Check if CSV file exists if [ ! -f "$CSV_FILE" ]; then @@ -81,7 +60,7 @@ while IFS=',' read -r addr rest; do continue fi # Remove quotes and whitespace - addr=$(echo "$addr" | sed 's/"//g' | xargs) + addr=$(echo "$addr" | xargs) if [ -n "$addr" ]; then addresses+=("$addr") fi @@ -97,8 +76,19 @@ echo "Found ${#addresses[@]} addresses in CSV file" echo "Sending $LOVELACE_AMOUNT lovelace to each address" # Get UTXO from payment address -payment_addr=$(cat "$keys_dir/payment.addr") -utxo=$(get_utxo "$payment_addr") + +# payment_addr=$(cat $keys_dir/payment.addr) +payment_addr=$PAYMENT_ADDR +echo "Using payment address: $payment_addr" +# utxo_output=$(cardano_cli conway query utxo --address "$payment_addr" --out-file /dev/stdout) +# utxo=$(echo "$utxo_output" | jq -r 'keys[0]') + +utxo="b35fdadd3c496fcc86f78f235de3aa2c091f88de5534e999f005ac4ad29aff8e#0" + +if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then + echo "Error: No UTXO found at payment address" + exit 1 +fi echo "Using UTXO: $utxo" @@ -113,53 +103,111 @@ build_args=( # Add tx-out for each address for addr in "${addresses[@]}"; do build_args+=("--tx-out" "$addr+$LOVELACE_AMOUNT") + echo ""--tx-out" "$addr+$LOVELACE_AMOUNT"" done -# Add change address -build_args+=( - "--change-address" "$payment_addr" -) - -# Add metadata if specified -if [ -n "$METADATA_FILE" ]; then - if [ -f "$METADATA_FILE" ]; then - echo "Including metadata from: $METADATA_FILE" - build_args+=("--metadata-json-file" "$METADATA_FILE") - else - echo "Warning: Metadata file not found: $METADATA_FILE" - echo "Continuing without metadata..." - fi -fi - -build_args+=("--out-file" "$tx_unsigned_path") - -container_cli "${build_args[@]}" - -# Check transaction file was created -if [ ! -f "$tx_unsigned_path" ]; then - echo "Error: Failed to create unsigned transaction file" - exit 1 -fi - -# Sign the transaction -echo "Signing transaction" - -container_cli conway transaction sign \ - --tx-body-file "$tx_unsigned_path" \ - --signing-key-file "$keys_dir/payment.skey" \ - --out-file "$tx_signed_path" - -# Check signed transaction file was created -if [ ! -f "$tx_signed_path" ]; then - echo "Error: Failed to create signed transaction file" - exit 1 -fi - -# Submit the transaction -echo "Submitting transaction" - -container_cli conway transaction submit --tx-file "$tx_signed_path" - -echo "Transaction submitted successfully!" -echo "Sent $LOVELACE_AMOUNT lovelace to ${#addresses[@]} addresses" +# cardano-cli conway transaction build \ +# --mainnet \ +# --tx-in "b35fdadd3c496fcc86f78f235de3aa2c091f88de5534e999f005ac4ad29aff8e#0" \ +# --tx-out addr1q8wlrs4ntlxpsf6k5c69f86e964pksty5mvsttkauk4yqfswx2v2y8xu6mgdulhcqszuuqkcxntj0899cxuyral4vrjsvc+$LOVELACE_AMOUNT \ +# --tx-out addr1q8r4hru8ncsr74faz8aj3hu2t4jujckfyv0a34x39344wpkppndn3ly7hepmyavkazs2tje3ketp0pn0pymcs0tm07jqv9+$LOVELACE_AMOUNT \ +# --tx-out addr1q9jzmf9326dn5eehsw68ctvkktq9um2x092d9kdesmcuucs220kw2x0lk964luk46gtlmkyamdzsnqscemshp9jr3j3s92+$LOVELACE_AMOUNT \ +# --tx-out addr1qxsxg746tsgfxw98gmcxsev37jfytxr809seeq6t87wdw7md78v5yq4uafh4lcx94pz45p47quhdttl93jtxa4n33sts57+$LOVELACE_AMOUNT \ +# --tx-out addr1qyyuf3ua0e2sjas9egqjqvza6ut3jyn0kxr3e5l2upeuasgsfm9826q0pkhau2kf6nuj0065dgejfen0kk6t7cg0d9yqed+$LOVELACE_AMOUNT \ +# --tx-out addr1q8vd7lvhd2sf9pys7p3wdcpdtqnpyrs0nz7lc2t6lny7ptsn3dddzfmkf7zn5kgelsgrg8xp3atxvagy2sprhdtv98uqzr+$LOVELACE_AMOUNT \ +# --tx-out addr1qx3nmmfgs3n2gj408vnh2frjpnj02me7q32ljrfln4cjrs0uc4cfa0u0qtc9trlafnzgzfz04rp9w27n87sy5zkj298s3k+$LOVELACE_AMOUNT \ +# --tx-out addr1q84zyxga7lru033v2ryuced3kxq0ca00mrjvegjamu6e33600un3vmjpt4nskfeg3nqwew6un5z4evducx0aprs7ka5s64+$LOVELACE_AMOUNT \ +# --tx-out addr1q85wy2qhmqnvl2xdsvqpv4f2q2x8lt3n623z0gvw0p6lx7rl9fzsf5c7jd47qey9necq5nva78tqh8q63vnf5eh4sagq2s+$LOVELACE_AMOUNT \ +# --tx-out addr1q9zaake0nwcxe09m7rg35xukhdw6v3qu0wzq7gguwf38kdyrf7u2rmeeq9ary0ds2ves9rt5luhpcg205zn77s2rzy3s9r+$LOVELACE_AMOUNT \ +# --tx-out addr1q8q25anxdp5hsmukxm99h7fh95rcuxed4ryk4jwzwhj7rpl8y7qqf0xuarfnjyljdqa2szayfdev9ytselvy47jh8aaq06+$LOVELACE_AMOUNT \ +# --tx-out addr1qylctn9a4h46ww7jsqah533s7ldrlrzn7mrhl5rdptrumn6ke58azzzukvzyymfk9ank0hx59vmg3e6htuuaqalar9qqyj+$LOVELACE_AMOUNT \ +# --tx-out addr1qyy8v6ryzthd3cf6z46ewkxedw40t82ne7krr0epq0hcuhcqqdgc7n2tswxsfhqyu2s6s8n62fm8w8dgnss2fk3q498spw+$LOVELACE_AMOUNT \ +# --tx-out addr1q9mcsgapzarg96n7cdt0m0l04jcr8lsypdh4jupcfg7u0tsuczyl9mps9cj5afffaudy6qk9hr7lts46xtqyrf77napspt+$LOVELACE_AMOUNT \ +# --tx-out addr1qxn6q4pj34utsalhs6ppjfl9fcp5h4rmvw6z594nuf6c8leymj34m5yg4hfcqcdqz9emf2avarj09h2atx0an6vvjjasw0+$LOVELACE_AMOUNT \ +# --tx-out addr1q9mm86mtnm4zuumnakzrzucfy72fqc2cecar0lagg58wdkkmrju2vl5ql0adr6nyvwa5qekr042gektv7ewzussye8qskk+$LOVELACE_AMOUNT \ +# --tx-out addr1q8zvq7dnczsfaf3s7uhpqdtk7rufru0qey3vmwge2tur6zuat40gj8ydxp0xuy6qwfe9y5hxh5amwsmfa8h7hwkz8yksrf+$LOVELACE_AMOUNT \ +# --tx-out addr1q99uk27c5wrj5qlumngpw6wcx2vgc6ew4e8rnh09mjsk6v0l3x8f7ny6el5zdpw9as2fctc6fxqqkmrzaelxdkudydaq4w+$LOVELACE_AMOUNT \ +# --tx-out addr1qxzcr6xfgu4u5dwhruqml9yj0v9j8l2vl3qcwdla4famv3vlex2jvsm78g26gu6sjg7t95a2y5s6whydc2vh73k7arws7s+$LOVELACE_AMOUNT \ +# --tx-out addr1qyr25mj9lcvkmfgg79ng35xdgqjk23rvypgtnjd9786xxm8pa7ucanumazwle37f3austjcyguxf4rl2p7ue4n4qnkjqk4+$LOVELACE_AMOUNT \ +# --tx-out addr1q82vx5jca42vx5n7qpu05vu8r6vxmvgc2nvuknmhnky7vpx0n6h44fq8ujuyu807vll9atjpc8z6zl0pyv6n2neezysq04+$LOVELACE_AMOUNT \ +# --tx-out addr1qy4daca3jj3jfj88n68r6nq0xktd0pg8qg8u846wks6kj3gfts83rwdnzxtqv7k2dalz2f98nx3pyz8d6k8djkxyxvfsp0+$LOVELACE_AMOUNT \ +# --tx-out addr1qygf8g0sd8v8tqha03nemmagj2s78sys4zdhun38c9a2p8mq7zcmh7er8kcgw6xfhdawk04hrtkt4x894dd3947x3xtqd9+$LOVELACE_AMOUNT \ +# --tx-out addr1q8g9grgfvupmww57krrqzjun8tsq8de5h67k66grtctwy4yz7kjjfjakkevmpsk4dk9scqtx9kr4u9s8av9nakrkh04s53+$LOVELACE_AMOUNT \ +# --tx-out addr1qyazppj7y0d8v8sp7ne4ngu8axkd8fq88zwaujn24fq85mnv52vtzx8s3g663v8qtt8g0ru27j7j6udsfkm7jzf5ypjs5t+$LOVELACE_AMOUNT \ +# --tx-out addr1qyav65zpcz56ulyzgjc76s9cgfjnxjrwdlpwsathdwf2l5lhj42k4j2wwqe5zytcpc0pvcpncwhp4jc40qvd3fjpg7ts4g+$LOVELACE_AMOUNT \ +# --tx-out addr1q8f5a2lr2xzt9989nkr2nv4zld2hj05v3tsdkvtc34dnlv8y0cwmpc3zw79z2z8sqma9cf75xz3kyglum84xsj3kzc4qh9+$LOVELACE_AMOUNT \ +# --tx-out addr1qy4xmqqvsx823906led0m9gerpfkyhgctsj8nysm3lhwx55s87338qzeuap40ddjfglelmsp8hymdwt0ly5eq4fqu5uqrd+$LOVELACE_AMOUNT \ +# --tx-out addr1q96smdr4zclu747uf26f2nqynulqmhze4ake4ua5mktharpzlj7prvw5z3p209ye0c4a34qqywsfp7chw5hul4rx4j8qrw+$LOVELACE_AMOUNT \ +# --tx-out addr1qxrdq3xk2wr6qqe2kjkdmtmpf2untcauwncl7vp4qqgseuc62a5358dy04zt0ek3a5m3u69dhp7ya4jzeyvvtnmf93rqdm+$LOVELACE_AMOUNT \ +# --tx-out addr1q9csfkv940e0juf3m8lftjr6s4eapx5vlkf05mrfag0y0csvlktu7n06027e588vf2mxt3uajup7r6kwvc45k3wgayqqvg+$LOVELACE_AMOUNT \ +# --tx-out addr1q9malun7ytnqh6z2zrajkhavx624577phc7xzxnwgkq726vj9sdxyx5ycvuczmr5yrqvvyet97xwvuepn9p4848wpraqp9+$LOVELACE_AMOUNT \ +# --tx-out addr1qysenuaxd49u74l8trz59mff7yxxlgwhpu8gj76w9pcpp038adkn5awy42fe9aq9yu2kjvuxqggxu220x7ktnscqyv0sea+$LOVELACE_AMOUNT \ +# --tx-out addr1qyyj2wuemm4sgx9fppezkark0mr97lhlk66j25ujnw2zs5x4p39tuzawxuf8afnlcp3mhl2ay0uyggeujrm5kct237rsa8+$LOVELACE_AMOUNT \ +# --tx-out addr1v83asw72qe5epvvwj8gg22cc5en4568gk2vephh8vxf22zsmv5kc2+$LOVELACE_AMOUNT \ +# --tx-out addr1qxsc5gppzecxezl82vkpp6j4g6tve62yg37kmltxtm7njwxe8v6sh93ufj38648njrmmcwpqhlf94mhd9p9r583sp0vsq6+$LOVELACE_AMOUNT \ +# --tx-out addr1q969pqdex204usts3dypdq592whk46hfe44s9k3n04h2hxe0tmwel0mj55vcggeqymqzz0h6fgvp0rdakhctl0s0nz7q7z+$LOVELACE_AMOUNT \ +# --tx-out addr1qx4t8uw8xne0f545cjdu9c2uhtezchw5h8hhnzfvwky4s8retdxxx9z84wts7ywszpfyzzu2m0xsttgffytp0t45pjvsdy+$LOVELACE_AMOUNT \ +# --tx-out addr1q95gj4xg4kwc6qp6m4cr5qfpxe5k9fyqlntx8cglssx7ty4nx4wa20lvsyj8lgvxrw6uw7fclma0p76us5fff6qxgvlqc9+$LOVELACE_AMOUNT \ +# --tx-out addr1q8ctar2qsmx8ffwz7ju868a459720m57jakj398s0hlqkrrlchtgtyzca7pxm2e3cdud8p7358ggxgv2xsm90e3l2r9qxu+$LOVELACE_AMOUNT \ +# --tx-out addr1qyevgjyszgryta92tj5phnvhnkc45t3dd08r2en6tdjrcnte69ykzwnem33zdglnk3rm6n2pl4xw6y0ackyke0vx0n7qkq+$LOVELACE_AMOUNT \ +# --tx-out addr1qxvqnvlnscsznw8p6369824hs8pra9vmwf6pw2y932736zhgqvcsrcpe0a74xm4mf8ymnzsza34q2e96jp9jxfnfwnhq9s+$LOVELACE_AMOUNT \ +# --tx-out addr1q9ynxme7c0tcmmvgk2tjuv63aw7zk9tk6yqkaqd48ulhkyl5f6v47dp5rc7286z5f57339d0c79khw4y3lwxzm8ywkzs02+$LOVELACE_AMOUNT \ +# --tx-out addr1q87qazerlfzc25p8wj4ecn9n6zmmdt62knsdjvs67hpwlsxylp3t9qnzvjnxatn7q04n03029k3nxssd3f66vv554rmsle+$LOVELACE_AMOUNT \ +# --tx-out addr1qy236l8zxnyvvm7uaxtvp87k36a045h8em0y82clams4wfuwpj9clsvsf85cd4xc59zjztr5zwpummwckmzr2myjwjnsrv+$LOVELACE_AMOUNT \ +# --tx-out addr1qxrqkurzqk2czm4zgmwsang735r3adhwmeadwen55hyrk5nu926a5u550v8yc52vmuyeyqs2rt7de9up65zxvynf5w8sum+$LOVELACE_AMOUNT \ +# --tx-out addr1qxyzre7hzxnm33xc0nk0hx3tz6g2yyz4524adfev0dz5ukd94zvpc45v3wht4rzg03qfkujcg4cpauscgj7s0n2dj6wspd+$LOVELACE_AMOUNT \ +# --tx-out addr1qyd0ffyzhwn4pqazdp8cs2j0l3taevqvgmrxrkw5f6ncck52ztpy62vems8lrklc3pd6rpvr28qwcnj8p5gvlpad9hlsjq+$LOVELACE_AMOUNT \ +# --tx-out addr1qycvusgng68pgnyu3zr6jkg9yyx3hq96734fhdqktmnffwkw2fkwcpv4v0g3m6y5antuhlwjplrv99whkt02un2dtwas6z+$LOVELACE_AMOUNT \ +# --tx-out addr1qx8xn0zwc6vrqm0lw7daql5x7x8tlale6tz005g2hhfn85av635z0fphdhmxujen259r4tr6veseej3whlxmkz8xe97qjc+$LOVELACE_AMOUNT \ +# --change-address "addr1qx93k28kzzu4fng49cfcj8w7m8px36wf9z8j94638lu8cw574gazl7xgwlxg4uxe4ytwnttj8qw489waumt82gx5jdtqwh8hn0" \ +# --out-file "./committee-rewards.unsigned" + +# # Add change address +# build_args+=( +# "--change-address" "$payment_addr" +# ) + +# # Add metadata if specified +# if [ -n "$METADATA_FILE" ]; then +# if [ -f "$METADATA_FILE" ]; then +# echo "Including metadata from: $METADATA_FILE" +# build_args+=("--metadata-json-file" "$METADATA_FILE") +# else +# echo "Warning: Metadata file not found: $METADATA_FILE" +# echo "Continuing without metadata..." +# fi +# fi + +# build_args+=("--out-file" "$tx_unsigned_path") + +# cardano_cli "${build_args[@]}" + +# # Check transaction file was created +# if [ ! -f "$tx_unsigned_path" ]; then +# echo "Error: Failed to create unsigned transaction file" +# exit 1 +# fi + +# # # Sign the transaction +# # echo "Signing transaction" + +# # cardano_cli conway transaction sign \ +# # --tx-body-file "$tx_unsigned_path" \ +# # --signing-key-file "$keys_dir/payment.skey" \ +# # --out-file "$tx_signed_path" + +# # # Check signed transaction file was created +# # if [ ! -f "$tx_signed_path" ]; then +# # echo "Error: Failed to create signed transaction file" +# # exit 1 +# # fi + +# # # Submit the transaction +# # echo "Submitting transaction" + + +# # cardano_cli conway transaction submit --tx-file $tx_signed_path + +# # echo "Transaction submitted successfully!" +# # echo "Sent $LOVELACE_AMOUNT lovelace to ${#addresses[@]} addresses" diff --git a/scripts/simple/treasury-donate.sh b/scripts/simple/treasury-donate.sh index db40c77..f69f273 100755 --- a/scripts/simple/treasury-donate.sh +++ b/scripts/simple/treasury-donate.sh @@ -28,26 +28,15 @@ if [ ! -f "$keys_dir/payment.skey" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Helper function to get UTXO with validation get_utxo() { local address=$1 local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) local utxo utxo=$(echo "$utxo_output" | jq -r 'keys[0]') if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then @@ -57,27 +46,20 @@ get_utxo() { echo "$utxo" } + # Send ada to the multisig payment script echo "Sending $LOVELACE_AMOUNT lovelace to the treasury." echo "Building transaction" -payment_addr=$(cat "$keys_dir/payment.addr") -utxo=$(get_utxo "$payment_addr") -container_cli conway transaction build \ - --tx-in "$utxo" \ - --change-address "$payment_addr" \ - --treasury-donation "$LOVELACE_AMOUNT" \ +cardano_cli conway transaction build \ + --tx-in $(cardano_cli conway query utxo --address $(cat $keys_dir/payment.addr) --out-file /dev/stdout | jq -r 'keys[0]') \ + --change-address $(cat $keys_dir/payment.addr) \ + --treasury-donation $LOVELACE_AMOUNT \ --out-file "$tx_unsigned_path" -# Check transaction file was created -if [ ! -f "$tx_unsigned_path" ]; then - echo "Error: Failed to create unsigned transaction file" - exit 1 -fi - -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/payment.skey" \ --out-file "$tx_signed_path" @@ -91,4 +73,5 @@ fi # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" + +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/stake/delegate-to-drep.sh b/scripts/stake/delegate-to-drep.sh index d507da2..7ac68bb 100755 --- a/scripts/stake/delegate-to-drep.sh +++ b/scripts/stake/delegate-to-drep.sh @@ -39,26 +39,15 @@ if [ ! -f "$keys_dir/stake.skey" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Helper function to get UTXO with validation get_utxo() { local address=$1 local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) local utxo utxo=$(echo "$utxo_output" | jq -r 'keys[0]') if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then @@ -68,11 +57,13 @@ get_utxo() { echo "$utxo" } + # Delegating to an DRep echo "Delegating you to DRep: $drep_id." -container_cli conway stake-address vote-delegation-certificate \ - --stake-verification-key-file "$keys_dir/stake.vkey" \ + +cardano_cli conway stake-address vote-delegation-certificate \ + --stake-verification-key-file $keys_dir/stake.vkey \ --drep-key-hash "$drep_id" \ --out-file "$tx_cert_path" @@ -84,13 +75,11 @@ fi echo "Building transaction" -payment_addr=$(cat "$keys_dir/payment.addr") -utxo=$(get_utxo "$payment_addr") -container_cli conway transaction build \ +cardano_cli conway transaction build \ --witness-override 2 \ - --tx-in "$utxo" \ - --change-address "$payment_addr" \ + --tx-in $(cardano_cli conway query utxo --address $(cat $keys_dir/payment.addr) --out-file /dev/stdout | jq -r 'keys[0]') \ + --change-address $(cat $keys_dir/payment.addr) \ --certificate-file "$tx_cert_path" \ --out-file "$tx_unsigned_path" @@ -102,7 +91,7 @@ fi echo "Signing transaction" -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/payment.skey" \ --signing-key-file "$keys_dir/stake.skey" \ @@ -117,4 +106,5 @@ fi # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" + +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/stake/delegate-to-spo.sh b/scripts/stake/delegate-to-spo.sh index f0067ea..a84cd59 100755 --- a/scripts/stake/delegate-to-spo.sh +++ b/scripts/stake/delegate-to-spo.sh @@ -39,26 +39,15 @@ if [ ! -f "$keys_dir/stake.skey" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Helper function to get UTXO with validation get_utxo() { local address=$1 local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) local utxo utxo=$(echo "$utxo_output" | jq -r 'keys[0]') if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then @@ -68,37 +57,24 @@ get_utxo() { echo "$utxo" } + # Delegating to an SPO echo "Delegating you to SPO: $spo_id." -container_cli conway stake-address stake-delegation-certificate \ - --stake-verification-key-file "$keys_dir/stake.vkey" \ + +cardano_cli conway stake-address stake-delegation-certificate \ + --stake-verification-key-file $keys_dir/stake.vkey \ --stake-pool-id "$spo_id" \ --out-file "$tx_cert_path" -# Check certificate file was created -if [ ! -f "$tx_cert_path" ]; then - echo "Error: Failed to create certificate file" - exit 1 -fi - -payment_addr=$(cat "$keys_dir/payment.addr") -utxo=$(get_utxo "$payment_addr") - -container_cli conway transaction build \ +cardano_cli conway transaction build \ --witness-override 2 \ - --tx-in "$utxo" \ - --change-address "$payment_addr" \ + --tx-in $(cardano_cli conway query utxo --address $(cat $keys_dir/payment.addr) --out-file /dev/stdout | jq -r 'keys[0]') \ + --change-address $(cat $keys_dir/payment.addr) \ --certificate-file "$tx_cert_path" \ --out-file "$tx_unsigned_path" -# Check transaction file was created -if [ ! -f "$tx_unsigned_path" ]; then - echo "Error: Failed to create unsigned transaction file" - exit 1 -fi - -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/payment.skey" \ --signing-key-file "$keys_dir/stake.skey" \ @@ -113,4 +89,5 @@ fi # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" + +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/stake/key-deregister.sh b/scripts/stake/key-deregister.sh index d54ea15..02aedd9 100755 --- a/scripts/stake/key-deregister.sh +++ b/scripts/stake/key-deregister.sh @@ -35,26 +35,15 @@ if [ ! -f "$keys_dir/stake.skey" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Helper function to get UTXO with validation get_utxo() { local address=$1 local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) local utxo utxo=$(echo "$utxo_output" | jq -r 'keys[0]') if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then @@ -64,12 +53,14 @@ get_utxo() { echo "$utxo" } + # Unregistering your stake key echo "Deregistering your stake key." -container_cli conway stake-address deregistration-certificate \ - --stake-verification-key-file "$keys_dir/stake.vkey" \ - --key-reg-deposit-amt "$(container_cli conway query gov-state | jq -r '.currentPParams.stakeAddressDeposit')" \ + +cardano_cli conway stake-address deregistration-certificate \ + --stake-verification-key-file $keys_dir/stake.vkey \ + --key-reg-deposit-amt $(cardano_cli conway query gov-state | jq -r .currentPParams.stakeAddressDeposit) \ --out-file "$tx_cert_path" # Check certificate file was created @@ -80,23 +71,15 @@ fi echo "Building transaction" -payment_addr=$(cat "$keys_dir/payment.addr") -utxo=$(get_utxo "$payment_addr") -container_cli conway transaction build \ +cardano_cli conway transaction build \ --witness-override 2 \ - --tx-in "$utxo" \ - --change-address "$payment_addr" \ + --tx-in $(cardano_cli conway query utxo --address $(cat $keys_dir/payment.addr) --out-file /dev/stdout | jq -r 'keys[0]') \ + --change-address $(cat $keys_dir/payment.addr) \ --certificate-file "$tx_cert_path" \ --out-file "$tx_unsigned_path" -# Check transaction file was created -if [ ! -f "$tx_unsigned_path" ]; then - echo "Error: Failed to create unsigned transaction file" - exit 1 -fi - -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/payment.skey" \ --signing-key-file "$keys_dir/stake.skey" \ @@ -111,4 +94,5 @@ fi # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" + +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/stake/key-register.sh b/scripts/stake/key-register.sh index 2972ba1..0028596 100755 --- a/scripts/stake/key-register.sh +++ b/scripts/stake/key-register.sh @@ -35,42 +35,17 @@ if [ ! -f "$keys_dir/stake.skey" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} - -# Helper function to get UTXO with validation (supports index selection) -get_utxo() { - local address=$1 - local index=${2:-0} - local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) - local utxo - utxo=$(echo "$utxo_output" | jq -r "keys[$index]") - if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then - echo "Error: No UTXO found at address: $address (index $index)" >&2 - exit 1 - fi - echo "$utxo" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Registering your stake key echo "Registering your stake key." -container_cli conway stake-address registration-certificate \ - --stake-verification-key-file "$keys_dir/stake.vkey" \ - --key-reg-deposit-amt "$(container_cli conway query gov-state | jq -r '.currentPParams.stakeAddressDeposit')" \ + +cardano_cli conway stake-address registration-certificate \ + --stake-verification-key-file $keys_dir/stake.vkey \ + --key-reg-deposit-amt "$(cardano_cli conway query gov-state | jq -r .currentPParams.stakeAddressDeposit)" \ --out-file "$tx_cert_path" # Check certificate file was created @@ -81,13 +56,11 @@ fi echo "Building transaction" -payment_addr=$(cat "$keys_dir/payment.addr") -utxo=$(get_utxo "$payment_addr" 1) -container_cli conway transaction build \ +cardano_cli conway transaction build \ --witness-override 2 \ - --tx-in "$utxo" \ - --change-address "$payment_addr" \ + --tx-in $(cardano_cli conway query utxo --address $(cat $keys_dir/payment.addr) --out-file /dev/stdout | jq -r 'keys[1]') \ + --change-address $(cat $keys_dir/payment.addr) \ --certificate-file "$tx_cert_path" \ --out-file "$tx_unsigned_path" @@ -99,7 +72,7 @@ fi echo "Signing transaction" -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/payment.skey" \ --signing-key-file "$keys_dir/stake.skey" \ @@ -114,4 +87,5 @@ fi # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" + +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/scripts/stake/withdraw-rewards.sh b/scripts/stake/withdraw-rewards.sh index aafade0..dae8c65 100755 --- a/scripts/stake/withdraw-rewards.sh +++ b/scripts/stake/withdraw-rewards.sh @@ -36,26 +36,14 @@ if [ ! -f "$keys_dir/stake.skey" ]; then exit 1 fi -# Get the container name from the get-container script -container_name="$("$script_dir/../helper/get-container.sh")" - -if [ -z "$container_name" ]; then - echo "Failed to determine a running container." - exit 1 -fi - -echo "Using running container: $container_name" - -# Function to execute cardano-cli commands inside the container -container_cli() { - docker exec -ti "$container_name" cardano-cli "$@" -} +# Source the cardano-cli wrapper +source "$script_dir/../helper/cardano-cli-wrapper.sh" # Helper function to get UTXO with validation get_utxo() { local address=$1 local utxo_output - utxo_output=$(container_cli conway query utxo --address "$address" --out-file /dev/stdout) + utxo_output=$(cardano_cli conway query utxo --address "$address" --out-file /dev/stdout) local utxo utxo=$(echo "$utxo_output" | jq -r 'keys[0]') if [ -z "$utxo" ] || [ "$utxo" = "null" ]; then @@ -65,21 +53,20 @@ get_utxo() { echo "$utxo" } -stake_account_balance=$(container_cli conway query stake-address-info --address "$(cat "$keys_dir/stake.addr")" | jq -r '.[0].rewardAccountBalance') + + +stake_account_balance=$(cardano_cli conway query stake-address-info --address $(cat $keys_dir/stake.addr) | jq -r '.[0].rewardAccountBalance') # Send ada to the multisig payment script echo "Withdrawing all balance of $stake_account_balance from stake account." echo "Building transaction" -payment_addr=$(cat "$keys_dir/payment.addr") -stake_addr=$(cat "$keys_dir/stake.addr") -utxo=$(get_utxo "$payment_addr") -container_cli conway transaction build \ - --tx-in "$utxo" \ - --change-address "$payment_addr" \ - --withdrawal "$stake_addr+$stake_account_balance" \ +cardano_cli conway transaction build \ + --tx-in $(cardano_cli conway query utxo --address $(cat $keys_dir/payment.addr) --out-file /dev/stdout | jq -r 'keys[0]') \ + --change-address $(cat $keys_dir/payment.addr) \ + --withdrawal $(cat $keys_dir/stake.addr)+$stake_account_balance \ --out-file "$tx_unsigned_path" # Check transaction file was created @@ -90,7 +77,7 @@ fi echo "Signing transaction" -container_cli conway transaction sign \ +cardano_cli conway transaction sign \ --tx-body-file "$tx_unsigned_path" \ --signing-key-file "$keys_dir/payment.skey" \ --signing-key-file "$keys_dir/stake.skey" \ @@ -105,4 +92,5 @@ fi # Submit the transaction echo "Submitting transaction" -container_cli conway transaction submit --tx-file "$tx_signed_path" + +cardano_cli conway transaction submit --tx-file $tx_signed_path diff --git a/start-node.sh b/start-node.sh index 373e94c..3f1a269 100755 --- a/start-node.sh +++ b/start-node.sh @@ -1,5 +1,11 @@ #!/bin/bash -set -euo pipefail + +# errors are handled gracefully to tell the user +# set -euo pipefail + +# ---------------------------------------- +ALLOW_MAINNET_EXTERNAL="false" +# ---------------------------------------- # Define colors RED='\033[0;31m' @@ -20,11 +26,12 @@ echo " /_/ \___/____/\__/_/ /_/\___/\__/ /_____/\____/\___/_/|_|\___/_/ echo " " echo -# Check and display running nodes +# Function to show currently running nodes show_running_nodes() { local running_nodes + running_nodes=$(docker ps --format "{{.Names}}" | grep -E "^node-[^-]+-[^-]+-container$" || true) - + if [ -n "$running_nodes" ]; then echo -e "${CYAN}Currently running Cardano node(s):${NC}" echo "$running_nodes" | while read -r container; do @@ -39,14 +46,124 @@ show_running_nodes() { fi } -# Display running nodes +# Show running nodes at startup show_running_nodes +# Prompt the user to select connection type first +echo -e "${CYAN}How would you like to connect to a Cardano node?${NC}" +connection_options=("Start a new Docker node" "Configure connection to an external node via socket file") +select connection_type in "${connection_options[@]}"; do + if [ -n "$connection_type" ]; then + echo -e "${GREEN}You have selected: $connection_type${NC}" + break + else + echo -e "${RED}Invalid selection. Please try again.${NC}" + fi +done + # Define the list of available networks available_networks=("mainnet" "preprod" "preview" "sanchonet") + +# If user selected external node configuration +if [ "$connection_type" = "Configure connection to an external node via socket file" ]; then + echo + echo -e "${CYAN}Checking external node configuration...${NC}" + + # Check if environment variables are set (use parameter expansion to handle unbound variables) + if [ -z "${CARDANO_NODE_SOCKET_PATH:-}" ]; then + echo -e "${RED}Error: CARDANO_NODE_SOCKET_PATH environment variable is not set.${NC}" + echo -e "${YELLOW}Please set it before running this script:${NC}" + echo -e "${BLUE} export CARDANO_NODE_SOCKET_PATH=\"/path/to/node.socket\"${NC}" + exit 1 + fi + + if [ -z "${CARDANO_NODE_NETWORK_ID:-}" ]; then + echo -e "${RED}Error: CARDANO_NODE_NETWORK_ID environment variable is not set.${NC}" + echo -e "${YELLOW}Please set it before running this script:${NC}" + echo -e "${BLUE} export CARDANO_NODE_NETWORK_ID=1 # 1=preprod, 2=preview, 4=sanchonet${NC}" + exit 1 + fi + + # Expand ~ in socket path + socket_path="${CARDANO_NODE_SOCKET_PATH/#\~/$HOME}" + + # Validate socket file exists + if [ ! -S "$socket_path" ] && [ ! -f "$socket_path" ]; then + echo -e "${RED}Error: Socket file '$socket_path' does not exist or is not accessible.${NC}" + echo -e "${YELLOW}Please check that CARDANO_NODE_SOCKET_PATH points to a valid socket file.${NC}" + exit 1 + fi + + # Validate socket file extension + if [[ "$socket_path" != *.socket ]]; then + echo -e "${YELLOW}Warning: Socket file should have .socket extension.${NC}" + fi + + # Validate socket file is actually a socket file type + if [ ! -S "$socket_path" ]; then + echo -e "${YELLOW}Warning: '$socket_path' exists but is not a socket file type.${NC}" + echo -e "${CYAN}Do you want to continue anyway? (y/n):${NC}" + read -r continue_choice < /dev/tty + if [ "$continue_choice" != "y" ] && [ "$continue_choice" != "Y" ]; then + echo -e "${YELLOW}Cancelled.${NC}" + exit 0 + fi + fi + + # Validate network ID is numeric + if ! [[ "${CARDANO_NODE_NETWORK_ID:-}" =~ ^[0-9]+$ ]]; then + echo -e "${RED}Error: CARDANO_NODE_NETWORK_ID must be a number.${NC}" + exit 1 + fi + + # Block mainnet for external nodes + if [ "${CARDANO_NODE_NETWORK_ID:-}" = "764824073" ] && [ "${ALLOW_MAINNET_EXTERNAL:-}" != "true" ]; then + echo -e "${RED}Error: Mainnet connections via external sockets are not allowed for security reasons.${NC}" + echo -e "${YELLOW}Please use Docker mode for mainnet, or set CARDANO_NODE_NETWORK_ID to a testnet value (1, 2, or 4).${NC}" + exit 1 + fi + + # Determine network name from ID + case "${CARDANO_NODE_NETWORK_ID:-}" in + 1) network_name="preprod" ;; + 2) network_name="preview" ;; + 4) network_name="sanchonet" ;; + *) network_name="unknown" ;; + esac + + # Confirm with user + echo + echo -e "${GREEN}External node configuration detected:${NC}" + echo -e "${BLUE} Socket path: $socket_path${NC}" + echo -e "${BLUE} Network ID: ${CARDANO_NODE_NETWORK_ID:-}${NC}" + if [ "$network_name" != "unknown" ]; then + echo -e "${BLUE} Network: $network_name${NC}" + fi + echo + echo -e "${CYAN}Is this correct? (y/n):${NC}" + read -r confirm < /dev/tty + + if [ "$confirm" != "y" ] && [ "$confirm" != "Y" ]; then + echo -e "${YELLOW}Cancelled. Please set the correct environment variables and try again.${NC}" + exit 0 + fi + + echo + echo -e "${GREEN}Configuration confirmed!${NC}" + echo -e "${BLUE}You can now run scripts with these environment variables set.${NC}" + echo + echo -e "${BLUE}Example:${NC}" + echo -e "${YELLOW} ./scripts/query/tip.sh${NC}" + exit 0 +fi + +# Continue with Docker node setup +echo +echo -e "${CYAN}Setting up Docker node...${NC}" + # Define the list of available node versions -available_versions=("10.5.1" "10.5.3" "10.6.1") +available_versions=( "10.5.3" "10.5.1") # Initialize variables to avoid unbound variable errors network="" @@ -197,10 +314,7 @@ multi_sig_dir="$tx_dir/multi-sig" simple_dir="$tx_dir/simple" helper_dir="$tx_dir/helper" -# Dumps dir dumps_dir="$base_dir/dumps/$network" - -# Utilities dir utilities_dir="$base_dir/utilities" # Base URL for node config files @@ -292,4 +406,9 @@ fi # Forward the logs to the terminal echo -e "${GREEN}Docker container logs:${NC}" +echo -e "${BLUE}Container name: node-$network-$node_version-container${NC}" +echo -e "${BLUE}To use this container with scripts, you can specify:${NC}" +echo -e "${YELLOW} CARDANO_CONTAINER_NAME=\"node-$network-$node_version-container\" ./scripts/query/tip.sh${NC}" +echo -e "${BLUE}Or let the script auto-select if it's the only running container.${NC}" +echo docker logs "node-$network-$node_version-container" --follow \ No newline at end of file