xpubwatch docs and more endpoints

This commit is contained in:
kexkey
2019-03-05 13:59:51 -05:00
committed by kexkey
parent 6787f9cee2
commit d3eba5e881
6 changed files with 186 additions and 2 deletions

View File

@@ -4,8 +4,11 @@
action_watch=watcher
action_unwatch=watcher
action_watchxpub=watcher
action_unwatchxpubbyxpub=watcher
action_unwatchxpubbylabel=watcher
action_getactivewatchesbyxpub=watcher
action_getactivewatchesbylabel=watcher
action_getactivexpubwatches=watcher
action_getactivewatches=watcher
action_getbestblockhash=watcher
action_getbestblockinfo=watcher

View File

@@ -71,6 +71,145 @@ Proxy response:
}
```
### Watch a Bitcoin xpub/ypub/zpub/tpub/upub/vpub extended public key (called by application)
Used to watch the transactions related to an xpub. It will first derive 100 addresses using the provided xpub, derivation path and index information. It will add those addresses to the watching DB table and add those addresses to the Watching-by-xpub wallet. The watching process will take care of calling the provided callbacks when a transaction occurs. When a transaction is seen, Cyphernode will derive and start watching new addresses related to the xpub, keeping a 100 address gap between the last used address in a transaction and the last watched address of that xpub. The label can be used later, instead of the whole xpub, with unwatchxpub* and and getactivewatchesby*.
```http
POST http://cyphernode:8888/watchxpub
with body...
{"label":"4421","pub32":"upub57Wa4MvRPNyAhxr578mQUdPr6MHwpg3Su875hj8K75AeUVZLXtFeiP52BrhNqDg93gjALU1MMh5UPRiiQPrwiTiuBBBRHzeyBMgrbwkmmkq","path":"0/1/n","nstart":109,"unconfirmedCallbackURL":"192.168.111.233:1111/callback0conf","confirmedCallbackURL":"192.168.111.233:1111/callback1conf"}
```
Proxy response:
```json
{
"id":"5",
"event":"watchxpub",
"pub32":"upub57Wa4MvRPNyAhxr578mQUdPr6MHwpg3Su875hj8K75AeUVZLXtFeiP52BrhNqDg93gjALU1MMh5UPRiiQPrwiTiuBBBRHzeyBMgrbwkmmkq",
"label":"2219",
"path":"0/1/n",
"nstart":"109",
"unconfirmedCallbackURL":"192.168.111.233:1111/callback0conf",
"confirmedCallbackURL":"192.168.111.233:1111/callback1conf"
}
```
### Un-watch a previously watched Bitcoin xpub by providing the xpub (called by application)
Updates the watched address rows in DB so that callbacks won't be called on tx confirmations for the provided xpub and related addresses.
```http
GET http://cyphernode:8888/unwatchxpubbyxpub/upub57Wa4MvRPNyAhxr578mQUdPr6MHwpg3Su875hj8K75AeUVZLXtFeiP52BrhNqDg93gjALU1MMh5UPRiiQPrwiTiuBBBRHzeyBMgrbwkmmkq
```
Proxy response:
```json
{
"event":"unwatchxpubbyxpub",
"pub32":"upub57Wa4MvRPNyAhxr578mQUdPr6MHwpg3Su875hj8K75AeUVZLXtFeiP52BrhNqDg93gjALU1MMh5UPRiiQPrwiTiuBBBRHzeyBMgrbwkmmkq"
}
```
### Un-watch a previously watched Bitcoin xpub by providing the label (called by application)
Updates the watched address rows in DB so that callbacks won't be called on tx confirmations for the provided xpub and related addresses.
```http
GET http://cyphernode:8888/unwatchxpubbylabel/4421
```
Proxy response:
```json
{
"event":"unwatchxpubbylabel",
"label":"4421"
}
```
### Get a list of Bitcoin xpub being watched (called by application)
Returns the list of currently watched xpub and callback information.
```http
GET http://cyphernode:8888/getactivexpubwatches
```
Proxy response:
```json
{
"watches": [
{
"id":"291",
"pub32":"upub57Wa4MvRPNyAhxr578mQUdPr6MHwpg3Su875hj8K75AeUVZLXtFeiP52BrhNqDg93gjALU1MMh5UPRiiQPrwiTiuBBBRHzeyBMgrbwkmmkq",
"label":"2217",
"derivation_path":"1/3/n",
"last_imported_n":"121",
"unconfirmedCallbackURL":"192.168.133.233:1111/callback0conf",
"confirmedCallbackURL":"192.168.133.233:1111/callback1conf",
"watching_since":"2018-09-06 21:14:03"}
]
}
```
### Get a list of Bitcoin addresses being watched by provided xpub (called by application)
Returns the list of currently watched addresses related to the provided xpub and callback information.
```http
GET http://cyphernode:8888/getactivewatchesbyxpub/tpubD6NzVbkrYhZ4YR3QK2tyfMMvBghAvqtNaNK1LTyDWcRHLcMUm3ZN2cGm5BS3MhCRCeCkXQkTXXjiJgqxpqXK7PeUSp86DTTgkLpcjMtpKWk
```
Proxy response:
```json
{
"watches": [
{
"id":"291",
"address":"2N8DcqzfkYi8CkYzvNNS5amoq3SbAcQNXKp",
"imported":"1",
"unconfirmedCallbackURL":"192.168.133.233:1111/callback0conf",
"confirmedCallbackURL":"192.168.133.233:1111/callback1conf",
"watching_since":"2018-09-06 21:14:03",
"derivation_path":"1/0/n",
"pub32_index":"44"}
]
}
```
### Get a list of Bitcoin addresses being watched by provided xpub label (called by application)
Returns the list of currently watched addresses related to the provided xpub label and callback information.
```http
GET http://cyphernode:8888/getactivewatchesbylabel/2219
```
Proxy response:
```json
{
"watches": [
{
"id":"291",
"address":"2N8DcqzfkYi8CkYzvNNS5amoq3SbAcQNXKp",
"imported":"1",
"unconfirmedCallbackURL":"192.168.133.233:1111/callback0conf",
"confirmedCallbackURL":"192.168.133.233:1111/callback1conf",
"watching_since":"2018-09-06 21:14:03",
"derivation_path":"1/0/n",
"pub32_index":"44"}
]
}
```
### Confirm a Transaction on Watched Address (called by Bitcoin node on transaction confirmations)
Confirms a transaction on an imported address. The Watching Bitcoin node will notify Cyphernode (thanks to walletnotify in bitcoin.conf) by calling this endpoint with txid when a tx is new or updated on an address. If address is still being watched (flag in DB), the corresponding callbacks will be called.

View File

@@ -24,8 +24,11 @@ const defaultAPIProperties = `
action_watch=watcher
action_unwatch=watcher
action_watchxpub=watcher
action_unwatchxpubbyxpub=watcher
action_unwatchxpubbylabel=watcher
action_getactivewatchesbyxpub=watcher
action_getactivewatchesbylabel=watcher
action_getactivexpubwatches=watcher
action_getactivewatches=watcher
action_getbestblockhash=watcher
action_getbestblockinfo=watcher

View File

@@ -97,3 +97,35 @@ getactivewatchesxpub() {
return ${returncode}
}
getactivexpubwatches() {
trace "Entering getactivexpubwatches()..."
local watches
# Let's build the string directly with sqlite instead of manipulating multiple strings afterwards, it's faster.
# {"id":"${id}","pub32":"${pub32}","label":"${label}","derivation_path":"${derivation_path}","last_imported_n":${last_imported_n},"unconfirmedCallbackURL":"${cb0conf_url}","confirmedCallbackURL":"${cb1conf_url}","watching_since":"${timestamp}"}
watches=$(sql "SELECT '{\"id\":\"' || id || '\",\"pub32\":\"' || pub32 || '\",\"label\":\"' || label || '\",\"derivation_path\":\"' || derivation_path || '\",\"last_imported_n\":' || last_imported_n || ',\"unconfirmedCallbackURL\":\"' || callback0conf || '\",\"confirmedCallbackURL\":\"' || callback1conf || '\",\"watching_since\":\"' || inserted_ts || '\"}' FROM watching_by_pub32 WHERE watching AND NOT calledback1conf")
returncode=$?
trace_rc ${returncode}
local notfirst=false
echo -n "{\"watches\":["
local IFS=$'\n'
for row in ${watches}
do
if ${notfirst}; then
echo ","
else
notfirst=true
fi
trace "[getactivexpubwatches] row=${row}"
echo -n "${row}"
done
echo "]}"
return ${returncode}
}

View File

@@ -124,6 +124,13 @@ main()
response_to_client "${response}" ${?}
break
;;
getactivexpubwatches)
# GET http://192.168.111.152:8080/getactivexpubwatches
response=$(getactivexpubwatches)
response_to_client "${response}" ${?}
break
;;
getactivewatches)
# curl (GET) 192.168.111.152:8080/getactivewatches

View File

@@ -60,7 +60,7 @@ unwatchpub32labelrequest() {
local returncode
trace "[unwatchpub32labelrequest] Unwatch xpub label ${label}"
id=$(sql "SELECT id FROM watching WHERE label='${label}'")
id=$(sql "SELECT id FROM watching_by_pub32 WHERE label='${label}'")
returncode=$?
trace_rc ${returncode}
trace "[unwatchpub32labelrequest] id: ${id}"
@@ -73,7 +73,7 @@ unwatchpub32labelrequest() {
returncode=$?
trace_rc ${returncode}
data="{\"event\":\"unwatchxpubbylabel\",\"pub32\":\"${pub32}\"}"
data="{\"event\":\"unwatchxpubbylabel\",\"label\":\"${label}\"}"
trace "[unwatchpub32labelrequest] responding=${data}"
echo "${data}"