From 5773ff4b6190b6f903c449d8ff945dc33e28e8f9 Mon Sep 17 00:00:00 2001 From: benk10 Date: Sat, 12 Sep 2020 12:03:34 +0300 Subject: [PATCH 1/6] Use Tor to get prruned node blockchain data and connect to remote Bitcoin node --- src/cryptoadvance/specter/rpc.py | 25 +++++++++++++++++++++++-- src/cryptoadvance/specter/wallet.py | 14 +++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/cryptoadvance/specter/rpc.py b/src/cryptoadvance/specter/rpc.py index 901846fc08..afedda9e6b 100644 --- a/src/cryptoadvance/specter/rpc.py +++ b/src/cryptoadvance/specter/rpc.py @@ -264,8 +264,29 @@ def multi(self, calls: list, **kwargs): url = self.url if "wallet" in kwargs: url = url+"/wallet/{}".format(kwargs["wallet"]) - r = requests.post( - url, data=json.dumps(payload), headers=headers, timeout=timeout) + r = None + if 'localhost:' not in url and '127.0.0.1:' not in url: + try: + requests_session = requests.Session() + requests_session = requests.Session() + requests_session.proxies = {} + requests_session.proxies['http'] = 'socks5h://localhost:9050' + requests_session.proxies['https'] = 'socks5h://localhost:9050' + r = requests_session.post( + url, + data=json.dumps(payload), + headers=headers, + timeout=timeout + ) + except Exception: + pass # Tor call failed + if r is None: + r = requests.post( + url, + data=json.dumps(payload), + headers=headers, + timeout=timeout + ) self.r = r if r.status_code != 200: raise RpcError( diff --git a/src/cryptoadvance/specter/wallet.py b/src/cryptoadvance/specter/wallet.py index 2e12792386..d143fcf27e 100644 --- a/src/cryptoadvance/specter/wallet.py +++ b/src/cryptoadvance/specter/wallet.py @@ -432,18 +432,26 @@ def _rescan_utxo_thread(self, explorer=None): for tx in existing ]) # handle missing transactions now - # TODO: do it over Tor + # if Tor is running, requests will be sent over Tor if explorer is not None: + try: + requests_session = requests.Session() + requests_session.proxies = {} + requests_session.proxies['http'] = 'socks5h://localhost:9050' + requests_session.proxies['https'] = 'socks5h://localhost:9050' + requests_session.get(explorer) + except Exception: + requests_session = requests.Session() # make sure there is no trailing / explorer = explorer.rstrip("/") try: # get raw transactions - raws = [requests.get( + raws = [requests_session.get( f"{explorer}/api/tx/{tx['txid']}/hex" ).text for tx in missing] # get proofs - proofs = [requests.get( + proofs = [requests_session.get( f"{explorer}/api/tx/{tx['txid']}/merkleblock-proof" ).text for tx in missing] From 50262ff6ac1d59f80a59dba3bb7246b69c1555af Mon Sep 17 00:00:00 2001 From: benk10 Date: Sat, 12 Sep 2020 12:13:01 +0300 Subject: [PATCH 2/6] Add pysocks --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 4357742ad7..61d6d7aa57 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,5 +9,6 @@ hwi==1.1.2 pyserial==3.4 python-dotenv==0.13.0 requests==2.23.0 +pysocks==1.7.1 six==1.12.0 stem==1.8.0 From 09064fcf9a00b55d03d8f496abf255329c15616a Mon Sep 17 00:00:00 2001 From: benk10 Date: Sun, 13 Sep 2020 08:04:58 +0300 Subject: [PATCH 3/6] Fix width of bitcoin core info popup --- .../includes/sidebar/components/bitcoin_core_info.jinja | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cryptoadvance/specter/templates/includes/sidebar/components/bitcoin_core_info.jinja b/src/cryptoadvance/specter/templates/includes/sidebar/components/bitcoin_core_info.jinja index 8714df2e98..436cb4c0b8 100644 --- a/src/cryptoadvance/specter/templates/includes/sidebar/components/bitcoin_core_info.jinja +++ b/src/cryptoadvance/specter/templates/includes/sidebar/components/bitcoin_core_info.jinja @@ -1,5 +1,4 @@ -