tDeprecate rescan script and create --rescan flag - electrum-personal-server - Maximally lightweight electrum server for a single user
git clone https://git.parazyd.org/electrum-personal-server
Log
Files
Refs
README
---
commit 8745c7c3c83a3a97a80f63b3681ff71a5b702520
parent 8a3000b22333463b49582c92b62e056378c4ce9b
Author: chris-belcher 
Date:   Thu, 18 Apr 2019 20:06:04 +0100

Deprecate rescan script and create --rescan flag

The seperate rescan script is not really necessary. It's cleaner
tto have a --rescan flag for the main script and have people
use that. It will also be much easier when electrum personal
server is packaged up with pyinstaller so there is only one
executable.

Diffstat:
  M electrumpersonalserver/server/comm… |      47 ++++++++++++++++++++-----------
  M setup.py                            |       2 +-

2 files changed, 31 insertions(+), 18 deletions(-)
---
diff --git a/electrumpersonalserver/server/common.py b/electrumpersonalserver/server/common.py
t@@ -611,6 +611,10 @@ def parse_args():
     parser = ArgumentParser(description='Electrum Personal Server daemon')
     parser.add_argument('config_file',
                         help='configuration file (mandatory)')
+    parser.add_argument("--rescan", action="store_true", help="Start the " +
+        " rescan script instead")
+    parser.add_argument("-v", "--version", action="version", version=
+        "%(prog)s " + SERVER_VERSION_NUMBER)
     return parser.parse_args()
 
 #log for checking up/seeing your wallet, debug for when something has gone wrong
t@@ -682,6 +686,10 @@ def main():
         logger.error("Wallet related RPC calls not found, looks like the " +
             "bitcoin node was compiled with the disable wallet flag")
         return
+
+    if opts.rescan:
+        rescan_script(logger, rpc)
+        return
     import_needed, relevant_spks_addrs, deterministic_wallets = \
         get_scriptpubkeys_to_monitor(rpc, config)
     if import_needed:
t@@ -748,7 +756,25 @@ def search_for_block_height_of_date(datestr, rpc):
         else:
             return -1
 
-def rescan():
+def rescan_script(logger, rpc):
+    user_input = input("Enter earliest wallet creation date (DD/MM/YYYY) "
+        "or block height to rescan from: ")
+    try:
+        height = int(user_input)
+    except ValueError:
+        height = search_for_block_height_of_date(user_input, rpc)
+        if height == -1:
+            return
+        height -= 2016 #go back two weeks for safety
+
+    if input("Rescan from block height " + str(height) + " ? (y/n):") != 'y':
+        return
+    logger.info("Rescanning. . . for progress indicator see the bitcoin node's"
+        + " debug.log file")
+    rpc.call("rescanblockchain", [height])
+    logger.info("end")
+
+def rescan_main():
     opts = parse_args()
 
     try:
t@@ -763,6 +789,8 @@ def rescan():
     logger, logfilename = logger_config(logger, config)
     logger.info('Starting Electrum Personal Server rescan script')
     logger.info('Logging to ' + logfilename)
+    logger.info("The seperate rescan script is deprecated, use " +
+        "`electrum-personal-server --rescan` instead.")
     try:
         rpc_u = config.get("bitcoin-rpc", "rpc_user")
         rpc_p = config.get("bitcoin-rpc", "rpc_password")
t@@ -775,19 +803,4 @@ def rescan():
         port = int(config.get("bitcoin-rpc", "port")),
         user = rpc_u, password = rpc_p,
         wallet_filename=config.get("bitcoin-rpc", "wallet_filename").strip())
-    user_input = input("Enter earliest wallet creation date (DD/MM/YYYY) "
-        "or block height to rescan from: ")
-    try:
-        height = int(user_input)
-    except ValueError:
-        height = search_for_block_height_of_date(user_input, rpc)
-        if height == -1:
-            return
-        height -= 2016 #go back two weeks for safety
-
-    if input("Rescan from block height " + str(height) + " ? (y/n):") != 'y':
-        return
-    logger.info("Rescanning. . . for progress indicator see the bitcoin node's"
-        + " debug.log file")
-    rpc.call("rescanblockchain", [height])
-    logger.info("end")
+    rescan_script(logger, rpc)
diff --git a/setup.py b/setup.py
t@@ -13,7 +13,7 @@ setup(
     entry_points={
         "console_scripts": [
             "electrum-personal-server = electrumpersonalserver.server.common:main",
-            "electrum-personal-server-rescan = electrumpersonalserver.server.common:rescan",
+            "electrum-personal-server-rescan = electrumpersonalserver.server.common:rescan_main",
         ]
     },
     package_data={"electrumpersonalserver": ["certs/*"]},