make proxy an optional parameter
This commit is contained in:
6
electrum
6
electrum
@@ -116,11 +116,11 @@ if __name__ == '__main__':
|
|||||||
parser.add_option("-s", "--fromaddr", dest="from_addr", default=None, help="set source address for payto/mktx. if it isn't in the wallet, it will ask for the private key unless supplied in the format public_key:private_key. It's not saved in the wallet.")
|
parser.add_option("-s", "--fromaddr", dest="from_addr", default=None, help="set source address for payto/mktx. if it isn't in the wallet, it will ask for the private key unless supplied in the format public_key:private_key. It's not saved in the wallet.")
|
||||||
parser.add_option("-c", "--changeaddr", dest="change_addr", default=None, help="set the change address for payto/mktx. default is a spare address, or the source address if it's not in the wallet")
|
parser.add_option("-c", "--changeaddr", dest="change_addr", default=None, help="set the change address for payto/mktx. default is a spare address, or the source address if it's not in the wallet")
|
||||||
parser.add_option("-r", "--remote", dest="remote_url", default=None, help="URL of a remote wallet")
|
parser.add_option("-r", "--remote", dest="remote_url", default=None, help="URL of a remote wallet")
|
||||||
parser.add_option("-p", "--proxy", dest="proxy", default=simple_config.config["proxy"], help="set proxy [type:]host[:port], where type is socks4,socks5 or http")
|
parser.add_option("-p", "--proxy", dest="proxy", default=None, help="set proxy [type:]host[:port], where type is socks4,socks5 or http")
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
|
|
||||||
if type(options.proxy) == type(''):
|
if options.proxy:
|
||||||
options.proxy = parse_proxy_options(options.proxy)
|
options.proxy = parse_proxy_options(options.proxy)
|
||||||
|
|
||||||
wallet = Wallet()
|
wallet = Wallet()
|
||||||
wallet.set_path(options.wallet_path)
|
wallet.set_path(options.wallet_path)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ DEFAULT_SERVERS = [ 'ecdsa.org:50001:t',
|
|||||||
'electrum.novit.ro:50001:t',
|
'electrum.novit.ro:50001:t',
|
||||||
'electrum.bytesized-hosting.com:50001:t'] # list of default servers
|
'electrum.bytesized-hosting.com:50001:t'] # list of default servers
|
||||||
|
|
||||||
proxy_modes = ['none', 'socks4', 'socks5', 'http' ]
|
proxy_modes = ['socks4', 'socks5', 'http']
|
||||||
|
|
||||||
def replace_keys(obj, old_key, new_key):
|
def replace_keys(obj, old_key, new_key):
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
@@ -65,7 +65,7 @@ def parse_proxy_options(s):
|
|||||||
return proxy
|
return proxy
|
||||||
|
|
||||||
class Interface(threading.Thread):
|
class Interface(threading.Thread):
|
||||||
def __init__(self, host, port, proxy):
|
def __init__(self, host, port, proxy=None):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
self.host = host
|
self.host = host
|
||||||
@@ -136,7 +136,7 @@ class Interface(threading.Thread):
|
|||||||
class PollingInterface(Interface):
|
class PollingInterface(Interface):
|
||||||
""" non-persistent connection. synchronous calls"""
|
""" non-persistent connection. synchronous calls"""
|
||||||
|
|
||||||
def __init__(self, host, port, proxy):
|
def __init__(self, host, port, proxy=None):
|
||||||
Interface.__init__(self, host, port, proxy)
|
Interface.__init__(self, host, port, proxy)
|
||||||
self.session_id = None
|
self.session_id = None
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ class HttpStratumInterface(PollingInterface):
|
|||||||
def send(self, messages):
|
def send(self, messages):
|
||||||
import urllib2, json, time, cookielib
|
import urllib2, json, time, cookielib
|
||||||
|
|
||||||
if self.proxy["mode"] != "none":
|
if self.proxy:
|
||||||
import socks
|
import socks
|
||||||
socks.setdefaultproxy(proxy_modes.index(self.proxy["mode"]), self.proxy["host"], int(self.proxy["port"]) )
|
socks.setdefaultproxy(proxy_modes.index(self.proxy["mode"]), self.proxy["host"], int(self.proxy["port"]) )
|
||||||
socks.wrapmodule(urllib2)
|
socks.wrapmodule(urllib2)
|
||||||
@@ -250,12 +250,12 @@ class HttpStratumInterface(PollingInterface):
|
|||||||
class TcpStratumInterface(Interface):
|
class TcpStratumInterface(Interface):
|
||||||
"""json-rpc over persistent TCP connection, asynchronous"""
|
"""json-rpc over persistent TCP connection, asynchronous"""
|
||||||
|
|
||||||
def __init__(self, host, port, proxy):
|
def __init__(self, host, port, proxy=None):
|
||||||
Interface.__init__(self, host, port, proxy)
|
Interface.__init__(self, host, port, proxy)
|
||||||
|
|
||||||
def init_socket(self):
|
def init_socket(self):
|
||||||
global proxy_modes
|
global proxy_modes
|
||||||
if self.proxy["mode"] == "none":
|
if self.proxy is None:
|
||||||
self.s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
|
self.s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
|
||||||
else:
|
else:
|
||||||
import socks
|
import socks
|
||||||
|
|||||||
Reference in New Issue
Block a user