def rescan(): opts = parse_args() logger = logging.getLogger('ELECTRUMPERSONALSERVER') logger = logger_config(logger, fmt=opts.logfmt, filename=opts.log, logfilemode='a' if opts.appendlog else 'w', stdout_loglevel=opts.loglevel) logger.setLevel(opts.loglevel) logger.info('Starting the Electrum Personal Server rescan script') logger.info('Logging to ' + opts.log) try: config = ConfigParser() config.read(opts.config_file) config.options("master-public-keys") except NoSectionError: logger.error("Non-existant configuration file {}".format( opts.config_file)) return try: rpc_u = config.get("bitcoin-rpc", "rpc_user") rpc_p = config.get("bitcoin-rpc", "rpc_password") except NoOptionError: rpc_u, rpc_p = 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=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")
def main(): opts = parse_args() try: config = RawConfigParser() config.read(opts.config_file) config.options("master-public-keys") except NoSectionError: print("ERROR: Non-existant configuration file {}".format( opts.config_file)) return logger = logging.getLogger('ELECTRUMPERSONALSERVER') logger, logfilename = logger_config(logger, config) logger.info('Starting Electrum Personal Server ' + str(SERVER_VERSION_NUMBER)) logger.info('Logging to ' + logfilename) logger.debug("Process ID (PID) = " + str(os.getpid())) rpc_u = None rpc_p = None cookie_path = None try: rpc_u = config.get("bitcoin-rpc", "rpc_user") rpc_p = config.get("bitcoin-rpc", "rpc_password") logger.debug("obtaining auth from rpc_user/pass") except NoOptionError: cookie_path = obtain_cookie_file_path( config.get("bitcoin-rpc", "datadir")) logger.debug("obtaining auth from .cookie") if rpc_u == None and cookie_path == None: return rpc = JsonRpc(host=config.get("bitcoin-rpc", "host"), port=int(config.get("bitcoin-rpc", "port")), user=rpc_u, password=rpc_p, cookie_path=cookie_path, wallet_filename=config.get("bitcoin-rpc", "wallet_filename").strip(), logger=logger) #TODO somewhere here loop until rpc works and fully sync'd, to allow # people to run this script without waiting for their node to fully # catch up sync'd when getblockchaininfo blocks == headers, or use # verificationprogress printed_error_msg = False while bestblockhash[0] == None: try: bestblockhash[0] = rpc.call("getbestblockhash", []) except JsonRpcError as e: if not printed_error_msg: logger.error("Error with bitcoin json-rpc: " + repr(e)) printed_error_msg = True time.sleep(5) try: rpc.call("listunspent", []) except JsonRpcError as e: logger.error(repr(e)) logger.error("Wallet related RPC call failed, possibly the " + "bitcoin node was compiled with the disable wallet flag") return test_keydata = ( "2 tpubD6NzVbkrYhZ4YVMVzC7wZeRfz3bhqcHvV8M3UiULCfzFtLtp5nwvi6LnBQegrkx" + "YGPkSzXUEvcPEHcKdda8W1YShVBkhFBGkLxjSQ1Nx3cJ tpubD6NzVbkrYhZ4WjgNYq2nF" + "TbiSLW2SZAzs4g5JHLqwQ3AmR3tCWpqsZJJEoZuP5HAEBNxgYQhtWMezszoaeTCg6FWGQB" + "T74sszGaxaf64o5s") chain = rpc.call("getblockchaininfo", [])["chain"] try: gaplimit = 5 deterministicwallet.parse_electrum_master_public_key( test_keydata, gaplimit, rpc, chain) except ValueError as e: logger.error(repr(e)) logger.error( "Descriptor related RPC call failed. Bitcoin Core 0.20.0" + " or higher required. Exiting..") return if opts.rescan: rescan_script(logger, rpc, opts.rescan_date) return while True: logger.debug("Checking whether rescan is in progress") walletinfo = rpc.call("getwalletinfo", []) if "scanning" in walletinfo and walletinfo["scanning"]: logger.debug("Waiting for Core wallet rescan to finish") time.sleep(300) continue break import_needed, relevant_spks_addrs, deterministic_wallets = \ get_scriptpubkeys_to_monitor(rpc, config) if import_needed: if not relevant_spks_addrs and not deterministic_wallets: #import = true and no addresses means exit return deterministicwallet.import_addresses( rpc, relevant_spks_addrs, deterministic_wallets, change_param=-1, count=int(config.get("bitcoin-rpc", "initial_import_count"))) logger.info( "Done.\nIf recovering a wallet which already has existing" + " transactions, then\nrun the rescan script. If you're confident" + " that the wallets are new\nand empty then there's no need to" + " rescan, just restart this script") else: txmonitor = transactionmonitor.TransactionMonitor( rpc, deterministic_wallets, logger) if not txmonitor.build_address_history(relevant_spks_addrs): return try: run_electrum_server(rpc, txmonitor, config) except KeyboardInterrupt: logger.info('Received KeyboardInterrupt, quitting')
def main(): opts = parse_args() try: config = RawConfigParser() config.read(opts.config_file) config.options("master-public-keys") except NoSectionError: print("ERROR: Non-existant configuration file {}".format( opts.config_file)) return logger = logging.getLogger('ELECTRUMPERSONALSERVER') logger, logfilename = logger_config(logger, config) logger.info('Starting Electrum Personal Server') logger.info('Logging to ' + logfilename) try: rpc_u = config.get("bitcoin-rpc", "rpc_user") rpc_p = config.get("bitcoin-rpc", "rpc_password") logger.debug("obtaining auth from rpc_user/pass") except NoOptionError: rpc_u, rpc_p = obtain_rpc_username_password(config.get( "bitcoin-rpc", "datadir")) logger.debug("obtaining auth from .cookie") if rpc_u == None: return rpc = JsonRpc(host = config.get("bitcoin-rpc", "host"), port = int(config.get("bitcoin-rpc", "port")), user = rpc_u, password = rpc_p, wallet_filename=config.get("bitcoin-rpc", "wallet_filename").strip(), logger=logger) #TODO somewhere here loop until rpc works and fully sync'd, to allow # people to run this script without waiting for their node to fully # catch up sync'd when getblockchaininfo blocks == headers, or use # verificationprogress printed_error_msg = False while bestblockhash[0] == None: try: bestblockhash[0] = rpc.call("getbestblockhash", []) except JsonRpcError as e: if not printed_error_msg: logger.error("Error with bitcoin json-rpc: " + repr(e)) printed_error_msg = True time.sleep(5) try: rpc.call("listunspent", []) except JsonRpcError as e: logger.error(repr(e)) logger.error("Wallet related RPC call failed, possibly the " + "bitcoin node was compiled with the disable wallet flag") return if opts.rescan: rescan_script(logger, rpc, opts.rescan_date) return while True: logger.debug("Checking whether rescan is in progress") walletinfo = rpc.call("getwalletinfo", []) if "scanning" in walletinfo and walletinfo["scanning"]: logger.debug("Waiting for Core wallet rescan to finish") time.sleep(300) continue break import_needed, relevant_spks_addrs, deterministic_wallets = \ get_scriptpubkeys_to_monitor(rpc, config) if import_needed: if len(relevant_spks_addrs) == 0: #import = true and no addresses means exit return transactionmonitor.import_addresses(rpc, relevant_spks_addrs) logger.info("Done.\nIf recovering a wallet which already has existing" + " transactions, then\nrun the rescan script. If you're confident" + " that the wallets are new\nand empty then there's no need to" + " rescan, just restart this script") else: txmonitor = transactionmonitor.TransactionMonitor(rpc, deterministic_wallets, logger) if not txmonitor.build_address_history(relevant_spks_addrs): return try: run_electrum_server(rpc, txmonitor, config) except KeyboardInterrupt: logger.info('Received KeyboardInterrupt, quitting')
def main(): opts = parse_args() try: config = RawConfigParser() config.read(opts.config_file) config.options("master-public-keys") except NoSectionError: print("ERROR: Non-existant configuration file {}".format( opts.config_file)) return 1 logger = logging.getLogger('ELECTRUMPERSONALSERVER') logger, logfilename = logger_config(logger, config) logger.info('Starting Electrum Personal Server ' + str(SERVER_VERSION_NUMBER)) logger.info('Logging to ' + logfilename) logger.debug("Process ID (PID) = " + str(os.getpid())) rpc_u = None rpc_p = None cookie_path = None try: rpc_u = config.get("groestlcoin-rpc", "rpc_user") rpc_p = config.get("groestlcoin-rpc", "rpc_password") logger.debug("obtaining auth from rpc_user/pass") except NoOptionError: cookie_path = obtain_cookie_file_path( config.get("groestlcoin-rpc", "datadir")) logger.debug("obtaining auth from .cookie") if rpc_u == None and cookie_path == None: return 1 rpc = JsonRpc(host=config.get("groestlcoin-rpc", "host"), port=int(config.get("groestlcoin-rpc", "port")), user=rpc_u, password=rpc_p, cookie_path=cookie_path, wallet_filename=config.get("groestlcoin-rpc", "wallet_filename").strip(), logger=logger) #TODO somewhere here loop until rpc works and fully sync'd, to allow # people to run this script without waiting for their node to fully # catch up sync'd when getblockchaininfo blocks == headers, or use # verificationprogress printed_error_msg = False while bestblockhash[0] == None: try: bestblockhash[0] = rpc.call("getbestblockhash", []) except JsonRpcError as e: if not printed_error_msg: logger.error("Error with groestlcoin json-rpc: " + repr(e)) printed_error_msg = True time.sleep(5) try: rpc.call("listunspent", []) except JsonRpcError as e: logger.error(repr(e)) logger.error( "Wallet related RPC call failed, possibly the " + "groestlcoin node was compiled with the disable wallet flag") return 1 test_keydata = ( "2 tpubD6NzVbkrYhZ4Xh9Ybbw6cna2UyGzYXmpk6bYuvWAUsD493Eb57ssPKC74CoVyQi" + "thN9hRUKZz5c5BQqnS8zqDisJvDTA6fJgyVjhGFtSZaN tpubD6NzVbkrYhZ4XG7HrP7yo" + "9We8rEmc7RTbViHgKwYNwNN71gvuMpYDWRHCUoGMYKZvDMbF3VpWngHvbpTan9Wd3WTk9q" + "ZzZyuYKAGoPJRGjs") chain = rpc.call("getblockchaininfo", [])["chain"] try: gaplimit = 5 deterministicwallet.parse_electrum_master_public_key( test_keydata, gaplimit, rpc, chain) except ValueError as e: logger.error(repr(e)) logger.error( "Descriptor related RPC call failed. Groestlcoin Core 2.20.1" + " or higher required. Exiting..") return 1 if opts.rescan: rescan_script(logger, rpc, opts.rescan_date) return 0 while True: logger.debug("Checking whether rescan is in progress") walletinfo = rpc.call("getwalletinfo", []) if "scanning" in walletinfo and walletinfo["scanning"]: logger.debug("Waiting for Core wallet rescan to finish") time.sleep(300) continue break import_needed, relevant_spks_addrs, deterministic_wallets = \ get_scriptpubkeys_to_monitor(rpc, config) if import_needed: if not relevant_spks_addrs and not deterministic_wallets: #import = true and no addresses means exit return 0 deterministicwallet.import_addresses( rpc, relevant_spks_addrs, deterministic_wallets, change_param=-1, count=int(config.get("groestlcoin-rpc", "initial_import_count"))) logger.info( "Done.\nIf recovering a wallet which already has existing" + " transactions, then\nrun the rescan script. If you're confident" + " that the wallets are new\nand empty then there's no need to" + " rescan, just restart this script") else: txmonitor = transactionmonitor.TransactionMonitor( rpc, deterministic_wallets, logger) if not txmonitor.build_address_history(relevant_spks_addrs): return 1 try: run_electrum_server(rpc, txmonitor, config) except KeyboardInterrupt: logger.info('Received KeyboardInterrupt, quitting') return 1 return 0
def main(): opts = parse_args() logger = logging.getLogger('ELECTRUMPERSONALSERVER') logger = logger_config(logger, fmt=opts.logfmt, filename=opts.log, logfilemode='a' if opts.appendlog else 'w') logger.setLevel(opts.loglevel) logger.info('Starting Electrum Personal Server') logger.info('Logging to ' + opts.log) try: config = ConfigParser() config.read(opts.config_file) config.options("master-public-keys") except NoSectionError: logger.error("Non-existant configuration file {}".format( opts.config_file)) return try: rpc_u = config.get("bitcoin-rpc", "rpc_user") rpc_p = config.get("bitcoin-rpc", "rpc_password") logger.debug("obtaining auth from rpc_user/pass") except NoOptionError: rpc_u, rpc_p = obtain_rpc_username_password(config.get( "bitcoin-rpc", "datadir")) logger.debug("obtaining auth from .cookie") if rpc_u == None: return rpc = JsonRpc(host = config.get("bitcoin-rpc", "host"), port = int(config.get("bitcoin-rpc", "port")), user = rpc_u, password = rpc_p, wallet_filename=config.get("bitcoin-rpc", "wallet_filename").strip()) #TODO somewhere here loop until rpc works and fully sync'd, to allow # people to run this script without waiting for their node to fully # catch up sync'd when getblockchaininfo blocks == headers, or use # verificationprogress printed_error_msg = False while bestblockhash[0] == None: try: bestblockhash[0] = rpc.call("getbestblockhash", []) except JsonRpcError as e: if not printed_error_msg: logger.error("Error with bitcoin json-rpc: " + repr(e)) printed_error_msg = True time.sleep(5) try: rpc.call("listunspent", []) except JsonRpcError: logger.error("Wallet related RPC calls not found, looks like the " + "bitcoin node was compiled with the disable wallet flag") return import_needed, relevant_spks_addrs, deterministic_wallets = \ get_scriptpubkeys_to_monitor(rpc, config) if import_needed: transactionmonitor.import_addresses(rpc, relevant_spks_addrs) logger.info("Done.\nIf recovering a wallet which already has existing" + " transactions, then\nrun the rescan script. If you're confident" + " that the wallets are new\nand empty then there's no need to" + " rescan, just restart this script") else: txmonitor = transactionmonitor.TransactionMonitor(rpc, deterministic_wallets) if not txmonitor.build_address_history(relevant_spks_addrs): return hostport = (config.get("electrum-server", "host"), int(config.get("electrum-server", "port"))) ip_whitelist = [] for ip in config.get("electrum-server", "ip_whitelist").split(" "): if ip == "*": #matches everything ip_whitelist.append(ip_network("0.0.0.0/0")) ip_whitelist.append(ip_network("::0/0")) else: ip_whitelist.append(ip_network(ip, strict=False)) poll_interval_listening = int(config.get("bitcoin-rpc", "poll_interval_listening")) poll_interval_connected = int(config.get("bitcoin-rpc", "poll_interval_connected")) certfile, keyfile = get_certs(config) try: run_electrum_server(rpc, txmonitor, hostport, ip_whitelist, poll_interval_listening, poll_interval_connected, certfile, keyfile) except KeyboardInterrupt: logger.info('Received KeyboardInterrupt, quitting')