Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Tor to get pruned node blockchain data and connect to remote Core node #383

Merged
merged 7 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 23 additions & 2 deletions src/cryptoadvance/specter/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
ben-kaufman marked this conversation as resolved.
Show resolved Hide resolved
try:
requests_session = requests.Session()
requests_session = requests.Session()
ben-kaufman marked this conversation as resolved.
Show resolved Hide resolved
requests_session.proxies = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is requests_session.proxies = {} needed?

Session object already initialize the attribute proxies to {}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that's redundant, removed. Thanks for the review!

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(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<div id="bitcoin_core_info" class="hidden"
style="text-align: left;">
<div id="bitcoin_core_info" class="hidden" style="text-align: left; max-width: 500px;">
<h1>Bitcoin Core Node Info:</h1>
{% if specter.chain %}
{% if specter.info['pruned'] %}
Expand Down
14 changes: 11 additions & 3 deletions src/cryptoadvance/specter/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

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]
Expand Down