-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole
More file actions
executable file
·151 lines (128 loc) · 4.76 KB
/
console
File metadata and controls
executable file
·151 lines (128 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
# Enigmatic Console Launcher
# Sets up RPC environment and launches the interactive console
set -e
# Color codes for pretty output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}╔════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ Enigmatic Console Environment Setup ║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════╝${NC}"
echo ""
# Check if we're in the right directory
if [ ! -f "enigmatic_dgb/__init__.py" ]; then
echo -e "${RED}Error: Please run this script from the Enigmatic project root directory${NC}"
exit 1
fi
# Function to prompt for value with default
prompt_with_default() {
local prompt="$1"
local default="$2"
local value
if [ -n "$default" ]; then
read -p "$prompt [$default]: " value
echo "${value:-$default}"
else
read -p "$prompt: " value
echo "$value"
fi
}
# Function to prompt for password (hidden input)
prompt_password() {
local prompt="$1"
local value
read -s -p "$prompt: " value
echo "" # New line after hidden input
echo "$value"
}
# Try to load credentials from ~/.enigmatic.yaml first
if [ -f "$HOME/.enigmatic.yaml" ] && [ -z "$DGB_RPC_USER" ]; then
echo -e "${GREEN}✓ Found ~/.enigmatic.yaml${NC}"
# Load credentials from YAML using Python
CREDS=$(python3 -c "import yaml; f=open('$HOME/.enigmatic.yaml'); c=yaml.safe_load(f); r=c.get('rpc',{}); print(f\"{r.get('user','')}|{r.get('password','')}|{r.get('host','127.0.0.1')}|{r.get('port','14022')}|{r.get('wallet','')}\")" 2>/dev/null)
if [ -n "$CREDS" ]; then
IFS='|' read -r YAML_USER YAML_PASS YAML_HOST YAML_PORT YAML_WALLET <<< "$CREDS"
if [ -n "$YAML_USER" ] && [ -n "$YAML_PASS" ]; then
export DGB_RPC_USER="$YAML_USER"
export DGB_RPC_PASSWORD="$YAML_PASS"
export DGB_RPC_HOST="$YAML_HOST"
export DGB_RPC_PORT="$YAML_PORT"
export DGB_RPC_WALLET="$YAML_WALLET"
echo " User: $DGB_RPC_USER"
echo " Host: $DGB_RPC_HOST:$DGB_RPC_PORT"
echo " Wallet: ${DGB_RPC_WALLET:-not specified}"
echo ""
fi
fi
fi
# Check if RPC credentials are already in environment
if [ -n "$DGB_RPC_USER" ] && [ -n "$DGB_RPC_PASSWORD" ] && [ -n "$DGB_RPC_HOST" ] && [ -n "$DGB_RPC_PORT" ]; then
read -p "Use existing credentials? [Y/n]: " use_existing
if [[ ! "$use_existing" =~ ^[Nn] ]]; then
echo -e "${GREEN}Using existing RPC configuration${NC}"
echo ""
else
unset DGB_RPC_USER DGB_RPC_PASSWORD DGB_RPC_HOST DGB_RPC_PORT DGB_RPC_WALLET
fi
fi
# Prompt for credentials if not set
if [ -z "$DGB_RPC_USER" ]; then
echo -e "${YELLOW}RPC credentials not found. Please enter your DigiByte node details:${NC}"
echo ""
export DGB_RPC_USER=$(prompt_with_default "RPC Username" "")
export DGB_RPC_PASSWORD=$(prompt_password "RPC Password")
export DGB_RPC_HOST=$(prompt_with_default "RPC Host" "127.0.0.1")
export DGB_RPC_PORT=$(prompt_with_default "RPC Port" "14022")
export DGB_RPC_WALLET=$(prompt_with_default "RPC Wallet" "")
echo ""
echo -e "${GREEN}✓ RPC credentials configured${NC}"
echo ""
fi
# Check if we should save credentials to .enigmatic.yaml
if [ ! -f "$HOME/.enigmatic.yaml" ]; then
echo -e "${YELLOW}No ~/.enigmatic.yaml found${NC}"
read -p "Save credentials to ~/.enigmatic.yaml for future use? [y/N]: " save_config
if [[ "$save_config" =~ ^[Yy] ]]; then
cat > "$HOME/.enigmatic.yaml" <<EOF
rpc:
host: $DGB_RPC_HOST
port: $DGB_RPC_PORT
user: $DGB_RPC_USER
password: "$DGB_RPC_PASSWORD"
wallet: $DGB_RPC_WALLET
EOF
echo -e "${GREEN}✓ Saved to ~/.enigmatic.yaml${NC}"
echo ""
fi
fi
# Check if virtual environment exists
if [ ! -d ".venv" ]; then
echo -e "${YELLOW}Warning: No .venv directory found${NC}"
echo "You may need to install dependencies first:"
echo " python3 -m venv .venv"
echo " source .venv/bin/activate"
echo " pip install -e ."
echo ""
read -p "Continue anyway? [y/N]: " continue_anyway
if [[ ! "$continue_anyway" =~ ^[Yy] ]]; then
exit 0
fi
fi
# Activate virtual environment if it exists
if [ -d ".venv" ]; then
echo -e "${GREEN}Activating virtual environment...${NC}"
source .venv/bin/activate
fi
# Launch the console
echo -e "${GREEN}Launching Enigmatic Console...${NC}"
echo ""
# Export credentials and run
export DGB_RPC_USER
export DGB_RPC_PASSWORD
export DGB_RPC_HOST
export DGB_RPC_PORT
export DGB_RPC_WALLET
python3 -m enigmatic_dgb.cli console