spesmilo / electrum

Electrum Bitcoin Wallet
https://electrum.org
MIT License
7.38k stars 3.07k forks source link

Example Script of Changing Network Proxy/IP Address #6666

Open frogeyedpeas opened 3 years ago

frogeyedpeas commented 3 years ago

As more people are developing in Electrum we might be interested in knowing how to make all electrum requests go through TOR. An example script showing this would be very useful. After looking at Network.py it seems there is a way to pass a proxy argument into the object but its not immediately apparent how to use it.

SomberNight commented 3 years ago

Not sure I follow. Could you maybe detail an example use case?

If you just mean setting a proxy for the GUI or a daemon, as a launch parameter, see https://github.com/spesmilo/electrum/blob/21e46fb14796076afca148fcd6cc8ada11a7d17a/electrum/commands.py#L1330

frogeyedpeas commented 3 years ago

I see that you can use the --proxy flag in the CLI, i dont know how to pass this flag when developing from python, like do we use it in start_network, how do we pass it in, etc... To be more concerete, what I think would be useful if is in the "scripts" folder, if there was a python getting started guide (call it electrum_with_tor.py) for importing the electrum wallet and making a payment + getting a scripthash etc... all over done TOR. This would be good way to show developers how to leverage the proxy and simultaneously give them some working boilerplate for making more secure applications. I'm motivated to suggest this because I know how to develop with the wallet, and make automated payments/check balances from python but its not clear to me as a developer how to pass a proxy to the network object and how to integrate TOR with that.

SomberNight commented 3 years ago

Is the GUI not enough of an example? :) https://github.com/spesmilo/electrum/blob/21e46fb14796076afca148fcd6cc8ada11a7d17a/electrum/gui/qt/network_dialog.py#L396-L408