def on_version(self, i, version): """Check the version of an interface.""" # If the response is not parsable, disconnect. try: if version.startswith('ElectrumX '): i.server_version = version electrumx_version = util.normalize_version(version.split()[1]) min_version = util.normalize_version(MIN_ELECTRUMX_VERSION) if electrumx_version < min_version: self.print_error( 'Disconnecting %s with %s (minimum: %s)' % (i.server, version, MIN_ELECTRUMX_VERSION)) self.invalid_version(i.server) else: i.server_version = float(version) if i.server_version < MIN_SERVER_VERSION: self.print_error( 'Disconnecting %s with version %s (minimum: %s)' % (i.server, i.server_version, MIN_SERVER_VERSION)) self.invalid_version(i.server) except Exception as e: self.print_error( 'Disconnecting %s with version %s (parse version error: %s)' % (i.server, i.server_version, e)) self.invalid_version(i.server)
def parse_servers(result): """ parse servers list into dict format""" from version import PROTOCOL_VERSION 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 = cmp(util.normalize_version(version), util.normalize_version(PROTOCOL_VERSION)) >= 0 except Exception: is_recent = False if out and is_recent: out['pruning'] = pruning_level servers[host] = out return servers