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 3dcf7d7e186e9e568f2f0fb9fd686d09ebc50ae5
parent 2787a6d0d8b75ae6c576f5ce0d86d2df979013ee
Author: chris-belcher <chris-belcher@users.noreply.github.com>
Date:   Tue, 27 Mar 2018 01:11:57 +0100

fixed rescan-script, added a progress indicator to import addresses

Diffstat:
Mrescan-script.py | 11++++++++---
Mserver.py | 15+++++++++++----
2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/rescan-script.py b/rescan-script.py @@ -3,6 +3,7 @@ from configparser import ConfigParser, NoSectionError from jsonrpc import JsonRpc, JsonRpcError from datetime import datetime +import server def search_for_block_height_of_date(datestr, rpc): target_time = datetime.strptime(datestr, "%d/%m/%Y") @@ -39,10 +40,14 @@ def main(): except NoSectionError: print("Non-existant configuration file `config.cfg`") return + rpc_u, rpc_p = server.obtain_rpc_username_password(config.get( + "bitcoin-rpc", "datadir")) + if rpc_u == None: + return rpc = JsonRpc(host = config.get("bitcoin-rpc", "host"), - port = int(config.get("bitcoin-rpc", "port")), - user = config.get("bitcoin-rpc", "user"), - password = config.get("bitcoin-rpc", "password")) + 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: diff --git a/server.py b/server.py @@ -4,6 +4,7 @@ # as an alternative to address or scriptpubkey import socket, time, json, datetime, struct, binascii, ssl, os.path, platform +import sys from configparser import ConfigParser, NoSectionError from jsonrpc import JsonRpc, JsonRpcError @@ -359,11 +360,17 @@ def get_scriptpubkeys_to_monitor(rpc, config): def import_addresses(rpc, addrs): debug("importing addrs = " + str(addrs)) log("Importing " + str(len(addrs)) + " addresses in total") - st = time.time() - for a in addrs: + addr_i = iter(addrs) + notifications = 10 + for i in range(notifications): + pc = int(100.0 * i / notifications) + sys.stdout.write("[" + str(pc) + "%]... ") + sys.stdout.flush() + for j in range(int(len(addrs) / notifications)): + rpc.call("importaddress", [next(addr_i), ADDRESSES_LABEL, False]) + for a in addr_i: #import the reminder of addresses rpc.call("importaddress", [a, ADDRESSES_LABEL, False]) - et = time.time() - debug("imported addresses in " + str(et - st) + " sec") + print("[100%]") def obtain_rpc_username_password(datadir): if len(datadir.strip()) == 0: