Skip to content

Commit

Permalink
assetchains_balance.sh: fix GLEEC_OLD utxo count display
Browse files Browse the repository at this point in the history
  • Loading branch information
DeckerSU committed Oct 7, 2024
1 parent 6c39967 commit 668b5b6
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions assetchains_balance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ show_balance () {
ac_option="-ac_name=$coin"
fi

# Construct the komodo-cli command for getbalance
if [[ -n "$param" ]]; then
BALANCE=$($komodo_cli_binary $ac_option "$param" getbalance 2> /dev/null)
else
BALANCE=$($komodo_cli_binary $ac_option getbalance 2> /dev/null)
if [[ "$coin" == "GLEEC_OLD" ]]; then
ac_option="-ac_name=GLEEC"
fi

# Construct the komodo-cli command for getbalance
BALANCE=$($komodo_cli_binary $ac_option ${param:+$param} getbalance 2> /dev/null)

# Check if the balance retrieval was successful
if [[ $? -ne 0 ]]; then
echo -e "${RED}Error:${RESET} Failed to retrieve balance for '$coin'. Please ensure the daemon is running and the coin name is correct." >&2
Expand All @@ -67,8 +67,10 @@ show_balance () {
# Construct the expected scriptPubKey
local expected_scriptPubKey="21${pubkey}ac"

# Fetch and process UTXOs
UTXOS=$($komodo_cli_binary $ac_option listunspent | jq --arg script "$expected_scriptPubKey" '[.[] | select(.generated == false and .amount == 0.0001 and .spendable == true and (.scriptPubKey == $script))] | length')
# If param is set and not empty, ${param:+$param} expands to the value of param,
# If param is unset or empty, ${param:+$param} expands to nothing (i.e., it omits param).
UTXOS=$($komodo_cli_binary $ac_option ${param:+$param} listunspent | jq --arg script "$expected_scriptPubKey" '[.[] | select(.generated == false and .amount == 0.0001 and .spendable == true and (.scriptPubKey == $script))] | length')

if [[ $? -ne 0 ]]; then
echo -e "${RED}Error:${RESET} Failed to retrieve UTXOs for '$coin'." >&2
return 1
Expand Down Expand Up @@ -197,9 +199,9 @@ do
((gleec_count++))

if [[ "$gleec_count" -eq 1 ]]; then
show_balance "$i" "-datadir=$HOME/.komodo/GLEEC_OLD"
show_balance "GLEEC_OLD" "-datadir=$HOME/.komodo/GLEEC_OLD"
elif [[ "$gleec_count" -eq 2 ]]; then
show_balance "$i"
show_balance "GLEEC"
else
echo -e "${YELLOW}GLEEC has been encountered more than twice. No additional actions will be performed.${RESET}" >&2
fi
Expand Down

0 comments on commit 668b5b6

Please sign in to comment.