Using xpubwatching01.dat wallet for xpub watchers

This commit is contained in:
kexkey
2019-02-14 18:56:26 -05:00
committed by kexkey
parent fb49c3a060
commit 51f50707ea
5 changed files with 20 additions and 73 deletions

View File

@@ -163,6 +163,7 @@ confirmation() {
########################################################################################################
# Let's now grow the watch window in the case of a xpub watcher...
trace "[confirmation] Let's now grow the watch window in the case of a xpub watcher"
for row in ${rows}
do

View File

@@ -21,92 +21,32 @@ importmulti_rpc() {
trace "[Entering importmulti_rpc()]"
local walletname=${1}
local addresses=$(echo "${2}" | jq ".addresses" | tr -d '\n ')
local label=${2}
local addresses=$(echo "${3}" | jq ".addresses" | tr -d '\n ')
trace "[importmulti_rpc] addresses=${addresses}"
# [{"address":"2N6Q9kBcLtNswgMSLSQ5oduhbctk7hxEJW8"},{"address":"2NFLhFghAPKEPuZCKoeXYYxuaBxhKXbmhBV"},{"address":"2N7gepbQtRM5Hm4PTjvGadj9wAwEwnAsKiP"},{"address":"2Mth8XDZpXkY9d95tort8HYEAuEesow2tF6"},{"address":"2MwqEmAXhUw6H7bJwMhD13HGWVEj2HgFiNH"},{"address":"2N2Y4BVRdrRFhweub2ehHXveGZC3nryMEJw"}]
# [{"scriptPubKey":{"address":"2N6Q9kBcLtNswgMSLSQ5oduhbctk7hxEJW8"},"timestamp":"now","watchonly":true},{"scriptPubKey":{"address":"2NFLhFghAPKEPuZCKoeXYYxuaBxhKXbmhBV"},"timestamp":"now","watchonly":true},{"scriptPubKey":{"address":"2N7gepbQtRM5Hm4PTjvGadj9wAwEwnAsKiP"},"timestamp":"now","watchonly":true}]
# Will look like:
# [{"address":"2N6Q9kBcLtNswgMSLSQ5oduhbctk7hxEJW8"},{"address":"2NFLhFghAPKEPuZCKoeXYYxuaBxhKXbmhBV"},{"address":"2N7gepbQtRM5Hm4PTjvGadj9wAwEwnAsKiP"}]
# {"address":"2N6Q9kBcLtNswgMSLSQ5oduhbctk7hxEJW8"},
# {"scriptPubKey":{"address":"2N6Q9kBcLtNswgMSLSQ5oduhbctk7hxEJW8"},"timestamp":"now","watchonly":true},
# We want:
# [{"scriptPubKey":{"address":"2N6Q9kBcLtNswgMSLSQ5oduhbctk7hxEJW8"},"timestamp":"now","watchonly":true,"label":"xpub"},{"scriptPubKey":{"address":"2NFLhFghAPKEPuZCKoeXYYxuaBxhKXbmhBV"},"timestamp":"now","watchonly":true,"label":"xpub"},{"scriptPubKey":{"address":"2N7gepbQtRM5Hm4PTjvGadj9wAwEwnAsKiP"},"timestamp":"now","watchonly":true,"label":"xpub"}]
addresses=$(echo "${addresses}" | sed "s/\"address\"/\"scriptPubKey\":\{\"address\"/g" | sed "s/}/},\"timestamp\":\"now\",\"watchonly\":true,\"label\":\"${walletname}\"}/g")
# {"address":"2N6Q9kBcLtNswgMSLSQ5oduhbctk7hxEJW8"},
# {"scriptPubKey":{"address":"2N6Q9kBcLtNswgMSLSQ5oduhbctk7hxEJW8"},"timestamp":"now","watchonly":true,"label":"xpub"},
addresses=$(echo "${addresses}" | sed "s/\"address\"/\"scriptPubKey\":\{\"address\"/g" | sed "s/}/},\"timestamp\":\"now\",\"watchonly\":true,\"label\":\"${label}\"}/g")
trace "[importmulti_rpc] addresses=${addresses}"
# {"method":"importmulti","params":["requests":[<req>],"options":{"rescan":false}]}
# <req> = {"address":"<addr>","timestamp":"now","watchonly":true},...
# Now we use that in the RPC string
local rpcstring="{\"method\":\"importmulti\",\"params\":[${addresses},{\"rescan\":false}]}"
trace "[importmulti_rpc] rpcstring=${rpcstring}"
local result
# result=$(send_to_watcher_node_wallet ${walletname} ${rpcstring})
result=$(send_to_watcher_node ${rpcstring})
result=$(send_to_watcher_node_wallet ${walletname} ${rpcstring})
local returncode=$?
echo "${result}"
return ${returncode}
}
#[{"requests":
# [
# {"scriptPubKey":{"address":"2N6Q9kBcLtNswgMSLSQ5oduhbctk7hxEJW8"},"timestamp":"now","watchonly":true},
# {"scriptPubKey":{"address":"2NFLhFghAPKEPuZCKoeXYYxuaBxhKXbmhBV"},"timestamp":"now","watchonly":true},
# {"scriptPubKey":{"address":"2N7gepbQtRM5Hm4PTjvGadj9wAwEwnAsKiP"},"timestamp":"now","watchonly":true}
# ]},
#{"options":
# {
# "rescan":false
# }
#}]
#
# /usr/bin $ ./bitcoin-cli help importmulti
# importmulti "requests" ( "options" )
#
# Import addresses/scripts (with private or public keys, redeem script (P2SH)), rescanning all addresses in one-shot-only (rescan can be disabled via options). Requires a new wallet backup.
#
# Arguments:
# 1. requests (array, required) Data to be imported
# [ (array of json objects)
# {
# "scriptPubKey": "<script>" | { "address":"<address>" }, (string / json, required) Type of scriptPubKey (string for script, json for address)
# "timestamp": timestamp | "now" , (integer / string, required) Creation time of the key in seconds since epoch (Jan 1 1970 GMT),
# or the string "now" to substitute the current synced blockchain time. The timestamp of the oldest
# key will determine how far back blockchain rescans need to begin for missing wallet transactions.
# "now" can be specified to bypass scanning, for keys which are known to never have been used, and
# 0 can be specified to scan the entire blockchain. Blocks up to 2 hours before the earliest key
# creation time of all keys being imported by the importmulti call will be scanned.
# "redeemscript": "<script>" , (string, optional) Allowed only if the scriptPubKey is a P2SH address or a P2SH scriptPubKey
# "pubkeys": ["<pubKey>", ... ] , (array, optional) Array of strings giving pubkeys that must occur in the output or redeemscript
# "keys": ["<key>", ... ] , (array, optional) Array of strings giving private keys whose corresponding public keys must occur in the output or redeemscript
# "internal": <true> , (boolean, optional, default: false) Stating whether matching outputs should be treated as not incoming payments
# "watchonly": <true> , (boolean, optional, default: false) Stating whether matching outputs should be considered watched even when they're not spendable, only allowed if keys are empty
# "label": <label> , (string, optional, default: '') Label to assign to the address (aka account name, for now), only allowed with internal=false
# }
# ,...
# ]
# 2. options (json, optional)
# {
# "rescan": <false>, (boolean, optional, default: true) Stating if should rescan the blockchain after all imports
# }
#
# Note: This call can take over an hour to complete if rescan is true, during that time, other rpc calls
# may report that the imported keys, addresses or scripts exists but related transactions are still missing.
#
# Examples:
# > bitcoin-cli importmulti '[{ "scriptPubKey": { "address": "<my address>" }, "timestamp":1455191478 }, { "scriptPubKey": { "address": "<my 2nd address>" }, "label": "example 2", "timestamp": 1455191480 }]'
# > bitcoin-cli importmulti '[{ "scriptPubKey": { "address": "<my address>" }, "timestamp":1455191478 }]' '{ "rescan": false}'
#
# Response is an array with the same size as the input that has the execution result :
# [{ "success": true } , { "success": false, "error": { "code": -1, "message": "Internal Server Error"} }, ... ]
#

View File

@@ -144,7 +144,7 @@ watchpub32() {
if [ "${returncode}" -eq 0 ]; then
# Importmulti in Bitcoin Core...
result=$(importmulti_rpc "${pub32}" "${addresses}")
result=$(importmulti_rpc "${WATCHER_BTC_NODE_XPUB_WALLET}" "${pub32}" "${addresses}")
returncode=$?
trace_rc ${returncode}
trace "[watchpub32] result=${result}"
@@ -276,10 +276,13 @@ extend_watchers() {
# We want to keep our gap between last tx and last n watched...
# For example, if the last imported n is 155 and we just got a tx with pub32 index of 66,
# we want to extend the watched addresses to 166 if our gap is 100 (default).
trace "[extend_watchers] We have addresses to add to watchers!"
watchpub32 ${label} ${pub32} ${derivation_path} $((${last_imported_n} + 1)) ${callback0conf} ${callback1conf} ${upgrade_to_n} > /dev/null
returncode=$?
trace_rc ${returncode}
else
trace "[extend_watchers] Nothing to add!"
fi
return ${returncode}