Added getactivewatchesby xpub and label

This commit is contained in:
kexkey
2019-02-19 14:53:34 -05:00
committed by kexkey
parent 51f50707ea
commit 16650bac84
2 changed files with 109 additions and 3 deletions

View File

@@ -3,8 +3,7 @@
. ./trace.sh
. ./sql.sh
getactivewatches()
{
getactivewatches() {
trace "Entering getactivewatches()..."
local watches
@@ -61,4 +60,97 @@ getactivewatches()
return ${returncode}
}
case "${0}" in *getactivewatches.sh) getactivewatches;; esac
getactivewatchesbyxpub() {
trace "Entering getactivewatchesbyxpub()..."
local xpub=${1}
local returncode
getactivewatchesxpub "pub32" ${xpub}
returncode=$?
trace_rc ${returncode}
return ${returncode}
}
getactivewatchesbylabel() {
trace "Entering getactivewatchesbylabel()..."
local label=${1}
local returncode
getactivewatchesxpub "label" ${label}
returncode=$?
trace_rc ${returncode}
return ${returncode}
}
getactivewatchesxpub() {
trace "Entering getactivewatchesxpub()..."
local where=${1}
trace "[getactivewatchesxpub] where=${where}"
local value=${2}
trace "[getactivewatchesxpub] value=${value}"
local watches
watches=$(sql "SELECT id, address, imported, callback0conf, callback1conf, inserted_ts, derivation_path, pub32_index FROM watching, watching_by_pub32 w32 WHERE watching_by_pub32_id = w32.id AND ${where} = \"${value}\" AND watching AND NOT calledback1conf")
returncode=$?
trace_rc ${returncode}
local id
local address
local imported
local inserted
local cb0conf_url
local cb1conf_url
local timestamp
local derivation_path
local pub32_index
local notfirst=false
echo -n "{\"watches\":["
local IFS=$'\n'
for row in ${watches}
do
if ${notfirst}; then
echo ","
else
notfirst=true
fi
trace "[getactivewatchesxpub] row=${row}"
id=$(echo "${row}" | cut -d '|' -f1)
trace "[getactivewatchesxpub] id=${id}"
address=$(echo "${row}" | cut -d '|' -f2)
trace "[getactivewatchesxpub] address=${address}"
imported=$(echo "${row}" | cut -d '|' -f3)
trace "[getactivewatchesxpub] imported=${imported}"
cb0conf_url=$(echo "${row}" | cut -d '|' -f4)
trace "[getactivewatchesxpub] cb0conf_url=${cb0conf_url}"
cb1conf_url=$(echo "${row}" | cut -d '|' -f5)
trace "[getactivewatchesxpub] cb1conf_url=${cb1conf_url}"
timestamp=$(echo "${row}" | cut -d '|' -f6)
trace "[getactivewatchesxpub] timestamp=${timestamp}"
derivation_path=$(echo "${row}" | cut -d '|' -f7)
trace "[getactivewatchesxpub] derivation_path=${derivation_path}"
pub32_index=$(echo "${row}" | cut -d '|' -f8)
trace "[getactivewatchesxpub] pub32_index=${pub32_index}"
data="{\"id\":\"${id}\","
data="${data}\"address\":\"${address}\","
data="${data}\"imported\":\"${imported}\","
data="${data}\"unconfirmedCallbackURL\":\"${cb0conf_url}\","
data="${data}\"confirmedCallbackURL\":\"${cb1conf_url}\","
data="${data}\"watching_since\":\"${timestamp}\","
data="${data}\"derivation_path\":\"${derivation_path}\","
data="${data}\"pub32_index\":\"${pub32_index}\"}"
trace "[getactivewatchesxpub] data=${data}"
echo -n "${data}"
done
echo "]}"
return ${returncode}
}

View File

@@ -96,6 +96,20 @@ main()
response_to_client "${response}" ${?}
break
;;
getactivewatchesbyxpub)
# GET http://192.168.111.152:8080/getactivewatchesbyxpub/tpubD6NzVbkrYhZ4YR3QK2tyfMMvBghAvqtNaNK1LTyDWcRHLcMUm3ZN2cGm5BS3MhCRCeCkXQkTXXjiJgqxpqXK7PeUSp86DTTgkLpcjMtpKWk
response=$(getactivewatchesbyxpub $(echo "${line}" | cut -d ' ' -f2 | cut -d '/' -f3))
response_to_client "${response}" ${?}
break
;;
getactivewatchesbylabel)
# GET http://192.168.111.152:8080/getactivewatchesbylabel/4421
response=$(getactivewatchesbylabel $(echo "${line}" | cut -d ' ' -f2 | cut -d '/' -f3))
response_to_client "${response}" ${?}
break
;;
getactivewatches)
# curl (GET) 192.168.111.152:8080/getactivewatches