Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions dashboard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ DASHBOARD_URL='https://github.com/attogram/dashboard'
DASHBOARD_DISCORD='https://discord.gg/BGQJCbYVBa'
DASHBOARD_LICENSE='MIT'
DASHBOARD_COPYRIGHT='Copyright (c) 2025 Attogram Project <https://github.com/attogram>'
DASHBOARD_DEBUG=0 # 0 = off, 1 = on
export DASHBOARD_DEBUG=0 # 0 = off, 1 = on

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FORMAT="tsv"
Expand Down Expand Up @@ -345,7 +345,11 @@ else
OUTPUTS=()
for module_name in "${MODULES_TO_RUN[@]}"; do
_debug "Calling $module_name"
module_output=$("$MODULES_DIR/$module_name" "$MODULE_EXEC_FORMAT" 2>/dev/null)
if (( DASHBOARD_DEBUG )); then
module_output=$("$MODULES_DIR/$module_name" "$MODULE_EXEC_FORMAT")
else
module_output=$("$MODULES_DIR/$module_name" "$MODULE_EXEC_FORMAT" 2>/dev/null)
fi
if [ -n "$module_output" ]; then
_debug "Saving output from $module_name: $(echo "$module_output" | wc -c | tr -d ' ') bytes"
OUTPUTS+=("$module_output")
Expand Down
24 changes: 22 additions & 2 deletions modules/crypto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ if [ -f "$CONFIG_FILE" ]; then
source "$CONFIG_FILE"
fi

# --- Debugging ---
# Check if DASHBOARD_DEBUG is set and non-zero
if [[ -n "${DASHBOARD_DEBUG:-}" ]] && ((DASHBOARD_DEBUG)); then
set -x
fi

_debug() {
if ! ((((DASHBOARD_DEBUG)))); then return 0; fi
printf '[DEBUG] %s: %s\n' "$(date '+%H:%M:%S')" "$1" >&2
}

# --- Data Fetching ---

# Function to format a raw balance string using its decimals value.
Expand Down Expand Up @@ -57,19 +68,26 @@ get_provider() {
# --- Provider Implementations ---

fetch_from_local_btc() {
_debug "Running fetch_from_local_btc"
if ! command -v bitcoin-cli &> /dev/null; then
echo "[ERROR] bitcoin-cli not found. Please install Bitcoin Core and ensure bitcoin-cli is in your PATH." >&2
return 1
fi
local btc_info
btc_info=$(bitcoin-cli getwalletinfo 2>/dev/null)
if [ $? -ne 0 ]; then
local exit_code=$?
_debug "bitcoin-cli exit code: ${exit_code}"
_debug "btc_info: ${btc_info}"

if [ ${exit_code} -ne 0 ]; then
echo "[ERROR] bitcoin-cli command failed. Please ensure your Bitcoin node is running and configured correctly." >&2
return 1
fi
local wallet_name balance display_name
wallet_name=$(echo "$btc_info" | jq -r '.walletname')
balance=$(echo "$btc_info" | jq -r '.balance')
_debug "wallet_name: ${wallet_name}"
_debug "balance: ${balance}"
display_name="local node ($wallet_name)"
echo "{\"chain\":\"BTC\",\"address\":\"${display_name}\",\"tokens\":[{\"symbol\":\"BTC\",\"balance\":\"${balance}\"}]}"
}
Expand Down Expand Up @@ -149,7 +167,9 @@ while IFS= read -r line; do
case "$PROVIDER" in
local)
if [ "$TICKER" = "BTC" ]; then
wallet_json=$(fetch_from_local_btc)
if ! wallet_json=$(fetch_from_local_btc); then
exit 1
fi
fi
;;
blockcypher)
Expand Down