diff --git a/proxy_docker/app/script/getactivewatches.sh b/proxy_docker/app/script/getactivewatches.sh index 7348732..d9dba1b 100644 --- a/proxy_docker/app/script/getactivewatches.sh +++ b/proxy_docker/app/script/getactivewatches.sh @@ -6,43 +6,56 @@ get_txns_by_watchlabel(){ trace "Entering get_txns_by_watchlabel()..." local label_txns - $sql=< 0) | . / "|") as $input - | {"label": $input[0], "address": $input[1], "txid": "$input[2], "confirmations": $input[3], "blockheight" : $input[4], "v_out":$input[5], "amount": $input[6]}]} - ' <$($label_txns) - return $label_txns_json + | {"label": $input[0], "address": $input[1], "txid": "$input[2], "confirmations": $input[3], "blockheight" : $input[4], "v_out":$input[5], "amount": $input[6]} + ] + }') + echo "$label_txns_json" + return ${returncode} } get_unused_addresses_by_watchlabel(){ - trace "Entering get_unused_addresses_by_watchlabel()..." - local label_txns - $sql = "SELECT w.watching_by_pub32_id, w.pub32_index, w.address FROM watching as w WHERE w.id NOT IN (SELECT watching_id FROM watching_tx) WHERE w.label=${1}" - $label_txns = $(sql "$sql") + trace "Entering get_unused_addresses_by_watchlabel()... $1" + local label_unused_addrs + query=$(cat <<-HERE + SELECT w32.id, w32.label, w32.pub32, w.pub32_index, w.address + FROM watching as w + INNER JOIN watching_by_pub32 AS w32 ON w.watching_by_pub32_id = w32.id + WHERE w.id NOT IN ( + SELECT watching_id FROM watching_tx + ) + AND w32.label="$1" +HERE + ) + label_unused_addrs=$(sql "$query") returncode=$? trace_rc ${returncode} - $label_txns_json = jq -Rsn ' + label_unused_addrs_json=$(echo "$label_unused_addrs" | jq -Rcsn ' {"label_unused_addresses": [inputs | . / "\n" | (.[] | select(length > 0) | . / "|") as $input - | {"pub32_watch_id": $input[0], "address_pub32_index": $input[1], "address": "$input[2] }]} - ' <$($label_txns) - return $label_txns_json + | {"pub32_watch_id": $input[0], "pub32_label": $input[1], "pub32" : $input[2], "address_pub32_index": $input[3], "address": $input[4] + ] + } + ') + echo "$label_unused_addrs_json" + return ${returncode} } - getactivewatches() { trace "Entering getactivewatches()..."