electrum

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

commit 1d26676ee9afd5f6d83a5b52cb9cf5e820a241b9
parent 215f64e64dad5798edb54e3c0bcba4cfd200a7a8
Author: thomasv <thomasv@gitorious>
Date:   Wed, 14 Aug 2013 16:16:03 +0200

parse_servers method

Diffstat:
Mlib/interface.py | 62+++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 33 insertions(+), 29 deletions(-)

diff --git a/lib/interface.py b/lib/interface.py @@ -93,6 +93,38 @@ class Interface(threading.Thread): self.pending_transactions_for_notifications= [] + def parse_servers(self, result): + """ parse servers list into dict format""" + + servers = {} + for item in result: + host = item[1] + out = {} + version = None + pruning_level = '-' + if len(item) > 2: + for v in item[2]: + if re.match("[stgh]\d*", v): + protocol, port = v[0], v[1:] + if port == '': port = DEFAULT_PORTS[protocol] + out[protocol] = port + elif re.match("v(.?)+", v): + version = v[1:] + elif re.match("p\d*", v): + pruning_level = v[1:] + if pruning_level == '': pruning_level = '0' + try: + is_recent = float(version)>=float(PROTOCOL_VERSION) + except: + is_recent = False + + if out and is_recent: + out['pruning'] = pruning_level + servers[host] = out + + return servers + + def queue_json_response(self, c): # uncomment to debug @@ -124,35 +156,7 @@ class Interface(threading.Thread): self.trigger_callback('banner') elif method == 'server.peers.subscribe': - servers = {} - for item in result: - - host = item[1] - out = {} - - version = None - pruning_level = '-' - if len(item) > 2: - for v in item[2]: - if re.match("[stgh]\d*", v): - protocol, port = v[0], v[1:] - if port == '': port = DEFAULT_PORTS[protocol] - out[protocol] = port - elif re.match("v(.?)+", v): - version = v[1:] - elif re.match("p\d*", v): - pruning_level = v[1:] - if pruning_level == '': pruning_level = '0' - try: - is_recent = float(version)>=float(PROTOCOL_VERSION) - except: - is_recent = False - - if out and is_recent: - out['pruning'] = pruning_level - servers[host] = out - - self.servers = servers + self.servers = self.parse_servers(result) self.trigger_callback('peers') else: