electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 46733d9b0f1e3a196e1b5af49f12703f77a18c9e
parent f0e57e036b40b43d8fc9d9837dde3d431170fc86
Author: ThomasV <thomasv@gitorious>
Date:   Thu, 29 Mar 2012 19:11:05 +0200

separate protocols and port numbers

Diffstat:
Mclient/gui_qt.py | 13++++++++-----
Mclient/interface.py | 2+-
Mclient/version.py | 2+-
Mclient/wallet.py | 35++++++++++++++++++++++++++---------
4 files changed, 36 insertions(+), 16 deletions(-)

diff --git a/client/gui_qt.py b/client/gui_qt.py @@ -841,11 +841,13 @@ class ElectrumWindow(QMainWindow): status = "Not connected" host = wallet.host port = wallet.port + protocol = wallet.protocol else: import random status = "Please choose a server." host = random.choice( interface.servers ) port = wallet.port + protocol = 's' d = QDialog(parent) d.setModal(1) @@ -865,7 +867,7 @@ class ElectrumWindow(QMainWindow): hbox = QHBoxLayout() host_line = QLineEdit() - host_line.setText("%s:%d"% (host,port) ) + host_line.setText("%s:%d:%s"% (host,port,protocol) ) hbox.addWidget(QLabel('Connect to:')) hbox.addWidget(host_line) vbox.addLayout(hbox) @@ -875,8 +877,8 @@ class ElectrumWindow(QMainWindow): servers_list.setHeaderLabels( [ 'Active servers'] ) servers_list.setMaximumHeight(150) for item in wallet.interface.servers: - servers_list.addTopLevelItem(QTreeWidgetItem( [ item ] )) - servers_list.connect(servers_list, SIGNAL('itemClicked(QTreeWidgetItem*, int)'), lambda x:host_line.setText( x.text(0) + ':%d'%wallet.port )) + servers_list.addTopLevelItem(QTreeWidgetItem( [ item[1] + ':' + item[0] ] )) + servers_list.connect(servers_list, SIGNAL('itemClicked(QTreeWidgetItem*, int)'), lambda x:host_line.setText( x.text(0) )) vbox.addWidget(servers_list) else: hbox = QHBoxLayout() @@ -893,11 +895,12 @@ class ElectrumWindow(QMainWindow): try: if ':' in hh: - host, port = hh.split(':') + host, port, protocol = hh.split(':') port = int(port) else: host = hh port = wallet.port + protocol = wallet.protocol except: QMessageBox.information(None, 'Error', 'error', 'OK') if parent == None: @@ -905,7 +908,7 @@ class ElectrumWindow(QMainWindow): else: return - wallet.set_server(host, port) + wallet.set_server(host, port, protocol) return True diff --git a/client/interface.py b/client/interface.py @@ -111,7 +111,7 @@ class Interface: def start_session(self, addresses, version): #print "Starting new session: %s:%d"%(self.host,self.port) self.start() - self.send([('client.version', [version]), ('server.banner',[]), ('blockchain.numblocks.subscribe',[]), ('server.peers.subscribe',[])]) + self.send([('server.version', [version]), ('server.banner',[]), ('blockchain.numblocks.subscribe',[]), ('server.peers.subscribe',[])]) self.subscribe(addresses) diff --git a/client/version.py b/client/version.py @@ -1,2 +1,2 @@ -ELECTRUM_VERSION = "0.42" +ELECTRUM_VERSION = "0.43" SEED_VERSION = 4 # bump this everytime the seed generation is modified diff --git a/client/wallet.py b/client/wallet.py @@ -263,6 +263,7 @@ class Wallet: self.host = random.choice( DEFAULT_SERVERS ) # random choice when the wallet is created self.port = DEFAULT_PORT + self.protocol = 'n' # not saved self.tx_history = {} @@ -280,10 +281,11 @@ class Wallet: self.tx_event = threading.Event() - def set_server(self, host, port): - if host!= self.host or port!=self.port: + def set_server(self, host, port, protocol): + if host!= self.host or port!=self.port or protocol!=self.protocol: self.host = host self.port = port + self.protocol = protocol self.interface.is_connected = False # this exits the polling loop def set_path(self, wallet_path): @@ -530,6 +532,7 @@ class Wallet: 'fee':self.fee, 'host':self.host, 'port':self.port, + 'protocol':self.protocol, 'seed':self.seed, 'addresses':self.addresses, 'change_addresses':self.change_addresses, @@ -565,6 +568,7 @@ class Wallet: self.fee = int( d.get('fee') ) self.seed = d.get('seed') self.host = d.get('host') + self.protocol = d.get('protocol','n') self.port = d.get('port') blocks = d.get('blocks') self.addresses = d.get('addresses') @@ -588,7 +592,7 @@ class Wallet: if self.remote_url: assert self.master_public_key.encode('hex') == self.get_remote_mpk() self.file_exists = True - #self.interface = interface.start_interface(self) + @@ -936,7 +940,20 @@ class Wallet: self.receive_status_callback(addr, status) elif method == 'server.peers.subscribe': - self.interface.servers = map( lambda x:x[1], result ) + servers = [] + for item in result: + s = [] + host = item[1] + if len(item)>2: + for v in item[2]: + if re.match("[nsh]\d+",v): + s.append((v[0],host+":"+v[1:])) + if not s: + s.append(("n",host+":50000")) + else: + s.append(("n",host+":50000")) + servers = servers + s + self.interface.servers = servers elif method == 'blockchain.address.subscribe': addr = params[-1] @@ -954,7 +971,7 @@ class Wallet: elif method == 'blockchain.numblocks.subscribe': self.blocks = result - elif method == 'client.version': + elif method == 'server.version': pass else: @@ -980,14 +997,14 @@ class Wallet: self.handle_response(response) def start_interface(self): - if self.port == 50000: + if self.protocol == 'n': InterfaceClass = NativeInterface - elif self.port == 50001: + elif self.protocol == 's': InterfaceClass = AsynchronousInterface - elif self.port in [80, 81, 8080, 8081]: + elif self.protocol == 'h': InterfaceClass = HttpInterface else: - print "unknown port number: %d. using native protocol."%self.port + print "unknown protocol" InterfaceClass = NativeInterface self.interface = InterfaceClass(self.host, self.port)