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 = {}
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):
'fee':self.fee,
'host':self.host,
'port':self.port,
+ 'protocol':self.protocol,
'seed':self.seed,
'addresses':self.addresses,
'change_addresses':self.change_addresses,
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')
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)
+
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]
elif method == 'blockchain.numblocks.subscribe':
self.blocks = result
- elif method == 'client.version':
+ elif method == 'server.version':
pass
else:
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)