cryptoadvance / spectrum

Electrum adaptor simulating Bitcoin RPC protocol
MIT License
8 stars 11 forks source link

Connecting to a electrum backend via Tor #28

Open k9ert opened 1 year ago

k9ert commented 1 year ago

It'd not yet possible to connect to a electrum via Tor. We basically need something very similiar than specter.requests_session:

    def requests_session(self, force_tor=False):
        requests_session = requests.Session()
        if self.only_tor or force_tor:
            proxy_url = self.proxy_url
            proxy_parsed_url = urlparse(self.proxy_url)
            proxy_url = proxy_parsed_url._replace(
                netloc="{}:{}@{}".format(
                    str(random.randint(10000, 0x7FFFFFFF)),
                    "random",
                    proxy_parsed_url.netloc,
                )
            ).geturl()
            requests_session.proxies["http"] = proxy_url
            requests_session.proxies["https"] = proxy_url
        return requests_session