mirror of
https://github.com/aljazceru/cyphernode.git
synced 2025-12-19 05:35:17 +01:00
getbalancebyxpub
This commit is contained in:
@@ -19,6 +19,8 @@ action_ln_create_invoice=watcher
|
||||
|
||||
# Spender can do what the watcher can do, plus:
|
||||
action_getbalance=spender
|
||||
action_getbalancebyxpub=spender
|
||||
action_getbalancebyxpublabel=spender
|
||||
action_getnewaddress=spender
|
||||
action_spend=spender
|
||||
action_addtobatch=spender
|
||||
|
||||
@@ -39,6 +39,8 @@ action_ln_create_invoice=watcher
|
||||
|
||||
# Spender can do what the watcher can do, plus:
|
||||
action_getbalance=spender
|
||||
action_getbalancebyxpub=spender
|
||||
action_getbalancebyxpublabel=spender
|
||||
action_getnewaddress=spender
|
||||
action_spend=spender
|
||||
action_addtobatch=spender
|
||||
|
||||
@@ -189,6 +189,20 @@ main()
|
||||
response_to_client "${response}" ${?}
|
||||
break
|
||||
;;
|
||||
getbalancebyxpub)
|
||||
# curl (GET) http://192.168.111.152:8080/getbalancebyxpub/upub5GtUcgGed1aGH4HKQ3vMYrsmLXwmHhS1AeX33ZvDgZiyvkGhNTvGd2TA5Lr4v239Fzjj4ZY48t6wTtXUy2yRgapf37QHgt6KWEZ6bgsCLpb
|
||||
|
||||
response=$(getbalancebyxpub $(echo "${line}" | cut -d ' ' -f2 | cut -d '/' -f3))
|
||||
response_to_client "${response}" ${?}
|
||||
break
|
||||
;;
|
||||
getbalancebyxpublabel)
|
||||
# curl (GET) http://192.168.111.152:8080/getbalancebyxpublabel/2219
|
||||
|
||||
response=$(getbalancebyxpublabel $(echo "${line}" | cut -d ' ' -f2 | cut -d '/' -f3))
|
||||
response_to_client "${response}" ${?}
|
||||
break
|
||||
;;
|
||||
getnewaddress)
|
||||
# curl (GET) http://192.168.111.152:8080/getnewaddress
|
||||
|
||||
|
||||
@@ -19,6 +19,15 @@ send_to_watcher_node() {
|
||||
return ${returncode}
|
||||
}
|
||||
|
||||
send_to_xpub_watcher_wallet() {
|
||||
trace "Entering send_to_xpub_watcher_wallet()..."
|
||||
|
||||
send_to_bitcoin_node ${WATCHER_NODE_RPC_URL}/${WATCHER_BTC_NODE_XPUB_WALLET} ${WATCHER_NODE_RPC_CFG} $@
|
||||
local returncode=$?
|
||||
trace_rc ${returncode}
|
||||
return ${returncode}
|
||||
}
|
||||
|
||||
send_to_watcher_node_wallet() {
|
||||
trace "Entering send_to_watcher_node_wallet()..."
|
||||
local walletname=$1
|
||||
|
||||
@@ -71,6 +71,59 @@ getbalance() {
|
||||
return ${returncode}
|
||||
}
|
||||
|
||||
getbalancebyxpublabel() {
|
||||
trace "Entering getbalancebyxpublabel()..."
|
||||
|
||||
local label=${1}
|
||||
trace "[getbalancebyxpublabel] label=${label}"
|
||||
local xpub
|
||||
|
||||
xpub=$(sql "SELECT pub32 FROM watching_by_pub32 WHERE label=\"${label}\"")
|
||||
trace "[getbalancebyxpublabel] xpub=${xpub}"
|
||||
|
||||
getbalancebyxpub ${xpub} "getbalancebyxpublabel"
|
||||
returncode=$?
|
||||
|
||||
return ${returncode}
|
||||
}
|
||||
|
||||
getbalancebyxpub() {
|
||||
trace "Entering getbalancebyxpub()..."
|
||||
|
||||
# ./bitcoin-cli -rpcwallet=xpubwatching01.dat listunspent 0 9999999 "$(./bitcoin-cli -rpcwallet=xpubwatching01.dat getaddressesbylabel upub5GtUcgGed1aGH4HKQ3vMYrsmLXwmHhS1AeX33ZvDgZiyvkGhNTvGd2TA5Lr4v239Fzjj4ZY48t6wTtXUy2yRgapf37QHgt6KWEZ6bgsCLpb | jq "keys" | tr -d '\n ')" | jq "[.[].amount] | add"
|
||||
|
||||
local xpub=${1}
|
||||
trace "[getbalancebyxpub] xpub=${xpub}"
|
||||
|
||||
# If called from getbalancebyxpublabel, set the correct event for response
|
||||
local event=${2:-"getbalancebyxpub"}
|
||||
trace "[getbalancebyxpub] event=${event}"
|
||||
local addresses
|
||||
local balance
|
||||
local data
|
||||
local returncode
|
||||
|
||||
# addresses=$(./bitcoin-cli -rpcwallet=xpubwatching01.dat getaddressesbylabel upub5GtUcgGed1aGH4HKQ3vMYrsmLXwmHhS1AeX33ZvDgZiyvkGhNTvGd2TA5Lr4v239Fzjj4ZY48t6wTtXUy2yRgapf37QHgt6KWEZ6bgsCLpb | jq "keys" | tr -d '\n ')
|
||||
data="{\"method\":\"getaddressesbylabel\",\"params\":[${xpub}]}"
|
||||
trace "[getbalancebyxpub] data=${data}"
|
||||
addresses=$(send_to_xpub_watcher_wallet ${data} | jq "keys" | tr -d '\n ')
|
||||
|
||||
# ./bitcoin-cli -rpcwallet=xpubwatching01.dat listunspent 0 9999999 "$addresses" | jq "[.[].amount] | add"
|
||||
|
||||
data="{\"method\":\"listunspent\",\"params\":[0, 9999999, \"${addresses}\"]}"
|
||||
trace "[getbalancebyxpub] data=${data}"
|
||||
balance=$(send_to_xpub_watcher_wallet ${data} | jq "[.[].amount] | add | . * 100000000 | trunc | . / 100000000")
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
trace "[getbalancebyxpub] balance=${balance}"
|
||||
|
||||
data="{\"event\":\"${event}\",\"xpub\":\"${xpub}\",\"balance\":${balance}}"
|
||||
|
||||
echo "${data}"
|
||||
|
||||
return ${returncode}
|
||||
}
|
||||
|
||||
getnewaddress() {
|
||||
trace "Entering getnewaddress()..."
|
||||
|
||||
|
||||
Reference in New Issue
Block a user