electrum

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

commit 70af22c9e47df39b987d170ad0a5b2fd13e42ce8
parent ff5074207c84ff34540a282a9b150a8f6dcc3f3c
Author: ThomasV <thomasv@electrum.org>
Date:   Thu,  7 Sep 2017 09:41:21 +0200

update scripts/servers to display server version

Diffstat:
Mlib/network.py | 21++++++++++++---------
Mscripts/peers | 34+++++-----------------------------
Mscripts/servers | 16++--------------
Mscripts/util.py | 3+--
4 files changed, 20 insertions(+), 54 deletions(-)

diff --git a/lib/network.py b/lib/network.py @@ -120,18 +120,21 @@ def parse_servers(result): elif re.match("p\d*", v): pruning_level = v[1:] if pruning_level == '': pruning_level = '0' - try: - is_recent = util.normalize_version(version) >= util.normalize_version(PROTOCOL_VERSION) - except Exception as e: - print_error(e) - is_recent = False - - if out and is_recent: + if out: out['pruning'] = pruning_level + out['version'] = version servers[host] = out - return servers +def filter_version(servers): + def is_recent(version): + try: + return util.normalize_version(version) >= util.normalize_version(PROTOCOL_VERSION) + except Exception as e: + return False + return {k: v for k, v in servers.items() if is_recent(v.get('version'))} + + def filter_protocol(hostmap, protocol = 's'): '''Filters the hostmap for those implementing protocol. The result is a list in serialized form.''' @@ -574,7 +577,7 @@ class Network(util.DaemonThread): self.on_notify_header(interface, result) elif method == 'server.peers.subscribe': if error is None: - self.irc_servers = parse_servers(result) + self.irc_servers = filter_version(parse_servers(result)) self.notify('servers') elif method == 'server.banner': if error is None: diff --git a/scripts/peers b/scripts/peers @@ -3,37 +3,13 @@ import util, json from collections import defaultdict - -def analyze(results): - out = {} - dd = {} - for k, v in results.items(): - height = v.get('block_height') - merkle = v.get('merkle_root') - utxo = v.get('utxo_root') - d = dd.get(merkle, defaultdict(int)) - d[utxo] += 1 - dd[merkle] = d - refs = {} - for merkle, d in dd.items(): - v = list(d.values()) - m = max(v) - dkeys = list(d.keys()) - ref = dkeys[v.index(m)] - refs[merkle] = ref, m - for k, v in results.items(): - height = v.get('block_height') - merkle = v.get('merkle_root') - utxo = v.get('utxo_root') - ref_utxo, num = refs.get(merkle) - if ref_utxo != utxo and num > 1: - out[k] = height, merkle, utxo - return out - +from electrum.network import filter_protocol +from electrum.blockchain import hash_header peers = util.get_peers() +peers = filter_protocol(peers, 's') + results = util.send_request(peers, 'blockchain.headers.subscribe', []) -errors = analyze(results).keys() for n,v in sorted(results.items(), key=lambda x:x[1].get('block_height')): - print("%40s"%n, v.get('block_height'), v.get('utxo_root'), "error" if n in errors else "ok") + print("%60s"%n, v.get('block_height'), hash_header(v)) diff --git a/scripts/servers b/scripts/servers @@ -2,25 +2,13 @@ from electrum import set_verbosity from electrum.network import filter_protocol -from collections import defaultdict import util, json set_verbosity(False) servers = util.get_peers() -results = util.send_request(servers, 'blockchain.headers.subscribe', []) -d = defaultdict(int) +for k, v in sorted(servers.items(), key=lambda x:x[1].get('version')): + print("%40s"%k, v.get('version')) -for k, r in results.items(): - blocks = r.get('block_height') - d[blocks] += 1 - -for k, v in results.items(): - print(k, v.get('block_height')) - -v = list(d.values()) -k = list(d.keys()) -numblocks = k[v.index(max(v))] -print("blocks:", numblocks) diff --git a/scripts/util.py b/scripts/util.py @@ -1,5 +1,6 @@ import select, time, electrum, queue from electrum import Connection, Interface, SimpleConfig + from electrum.network import filter_protocol, parse_servers from collections import defaultdict @@ -60,8 +61,6 @@ def get_peers(): if responses: response = responses[0][1] # One response, (req, response) tuple peers = parse_servers(response.get('result')) - peers = filter_protocol(peers,'s') - #print(response) return peers