Skip to content

Commit

Permalink
Merge pull request #118 from valory-xyz/develop
Browse files Browse the repository at this point in the history
Release v0.9.7
  • Loading branch information
Adamantios authored Nov 21, 2023
2 parents ea75328 + 4f53e8a commit 9b464ad
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
44 changes: 33 additions & 11 deletions run_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,32 @@ prompt_use_staking() {
done
}

# Function to set or add a variable in the .env file and export it
dotenv_set_key() {
local dotenv_path="$1"
local key_to_set="$2"
local value_to_set="$3"

# Check if the .env file exists
if [ ! -f "$dotenv_path" ]; then
touch "$dotenv_path"
echo "Created $dotenv_path"
fi

# Check if the variable already exists in the .env file
if grep -q "^$key_to_set=" "$dotenv_path"; then
# Variable exists, so update its value using awk
awk -v key="$key_to_set" -v val="$value_to_set" '{gsub("^" key "=.*", key "=" val); print}' "$dotenv_path" > temp && mv temp "$dotenv_path"
echo "Updated '$key_to_set=$value_to_set' in $dotenv_path"
else
# Variable doesn't exist, so add it to the .env file
echo "$key_to_set=$value_to_set" >> "$dotenv_path"
echo "Added '$key_to_set=$value_to_set' to $dotenv_path"
fi

export "$key_to_set=$value_to_set"
}


store=".trader_runner"
env_file_path="$store/.env"
Expand Down Expand Up @@ -311,7 +337,7 @@ create_storage() {

# Prompt use staking
prompt_use_staking
echo "USE_STAKING=$USE_STAKING" > "../$env_file_path"
dotenv_set_key "../$env_file_path" "USE_STAKING" "$USE_STAKING"

if [ "$USE_STAKING" = true ]; then
# New staking services use AGENT_ID=12 until end of Everest staking program
Expand All @@ -320,7 +346,7 @@ create_storage() {
# New non-staking services use AGENT_ID=14
AGENT_ID=14
fi
echo "AGENT_ID"=$AGENT_ID >> "../$env_file_path"
dotenv_set_key "../$env_file_path" "AGENT_ID" "$AGENT_ID"


# Generate the RPC file
Expand Down Expand Up @@ -396,22 +422,18 @@ try_read_storage() {
# INFO: This is a fix to avoid corrupting already-created stores
if [ -z "$USE_STAKING" ]; then
prompt_use_staking
echo "USE_STAKING=$USE_STAKING" > "$env_file_path"
dotenv_set_key "$env_file_path" "USE_STAKING" "$USE_STAKING"
fi

# INFO: This is a fix to avoid corrupting already-created stores
# If $AGENT_ID is not defined at this point, it means it is a service created
# before the AGENT_ID fix was implemented.
if [ -z "$AGENT_ID" ] && [ "$USE_STAKING" = true ]; then
if [ "$USE_STAKING" = true ]; then
# Existing staking services use AGENT_ID=12
AGENT_ID=12
echo "AGENT_ID=$AGENT_ID" >> "$env_file_path"
elif [ -z "$AGENT_ID" ]; then
else
# Existing non-staking services use AGENT_ID=14
AGENT_ID=14
echo "AGENT_ID=$AGENT_ID" >> "$env_file_path"
fi

dotenv_set_key "$env_file_path" "AGENT_ID" "$AGENT_ID"
else
first_run=true
fi
Expand All @@ -429,7 +451,7 @@ directory="trader"
service_repo=https://github.com/$org_name/$directory.git
# This is a tested version that works well.
# Feel free to replace this with a different version of the repo, but be careful as there might be breaking changes
service_version="v0.9.6"
service_version="v0.9.7"

echo ""
echo "---------------"
Expand Down
3 changes: 3 additions & 0 deletions scripts/staking.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"""This script performs staking related operations."""

import argparse
import dotenv
import sys
import time
import traceback
Expand Down Expand Up @@ -160,4 +161,6 @@
except Exception as e: # pylint: disable=broad-except
print(f"An error occurred while executing {Path(__file__).name}: {str(e)}")
traceback.print_exc()
dotenv.unset_key("../.trader_runner/.env", "USE_STAKING")
print("\nPlease confirm whether your service is participating in a staking program, and then retry running the script.")
sys.exit(1)

0 comments on commit 9b464ad

Please sign in to comment.