diff --git a/api_auth_docker/api-sample.properties b/api_auth_docker/api-sample.properties index dac7c04..4016972 100644 --- a/api_auth_docker/api-sample.properties +++ b/api_auth_docker/api-sample.properties @@ -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 diff --git a/install/generator-cyphernode/generators/app/index.js b/install/generator-cyphernode/generators/app/index.js index bc6c70f..3d1f9a8 100644 --- a/install/generator-cyphernode/generators/app/index.js +++ b/install/generator-cyphernode/generators/app/index.js @@ -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 diff --git a/proxy_docker/app/script/requesthandler.sh b/proxy_docker/app/script/requesthandler.sh index a421bd7..ccaa16f 100644 --- a/proxy_docker/app/script/requesthandler.sh +++ b/proxy_docker/app/script/requesthandler.sh @@ -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 diff --git a/proxy_docker/app/script/sendtobitcoinnode.sh b/proxy_docker/app/script/sendtobitcoinnode.sh index 614fdb8..f1bd46c 100644 --- a/proxy_docker/app/script/sendtobitcoinnode.sh +++ b/proxy_docker/app/script/sendtobitcoinnode.sh @@ -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 diff --git a/proxy_docker/app/script/walletoperations.sh b/proxy_docker/app/script/walletoperations.sh index e484804..c48d996 100644 --- a/proxy_docker/app/script/walletoperations.sh +++ b/proxy_docker/app/script/walletoperations.sh @@ -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()..."