# Path: electrumx/lib/util.py
# class cachedproperty(object):
# 
#     def __init__(self, f):
#         self.f = f
# 
#     def __get__(self, obj, type_):
#         obj = obj or type_
#         value = self.f(obj)
#         setattr(obj, self.f.__name__, value)
#         return value
# 
# def protocol_tuple(s):
#     '''Converts a protocol version number, such as "1.0" to a tuple (1, 0).
# 
#     If the version number is bad, (0, ) indicating version 0 is returned.'''
#     try:
#         return tuple(int(part) for part in s.split('.'))
#     except (TypeError, ValueError, AttributeError):
#         return (0, )
# 
# def version_string(ptuple):
#     '''Convert a version tuple such as (1, 2) to "1.2".
#     There is always at least one dot, so (1, ) becomes "1.0".'''
#     while len(ptuple) < 2:
#         ptuple += (0, )
#     return '.'.join(str(p) for p in ptuple)


from ipaddress import ip_address, IPv4Address, IPv6Address, IPv4Network, IPv6Network
from socket import AF_INET, AF_INET6
from aiorpcx import is_valid_hostname
from electrumx.lib.util import cachedproperty, protocol_tuple, version_string

    @cachedproperty
    def tcp_port(self):
        '''Returns None if no TCP port, otherwise the port as an integer.'''
        return self._port('tcp_port')

    @cachedproperty
    def server_version(self):
        '''Returns the server version as a string if known, otherwise None.'''
        return self._string('server_version')

    @cachedproperty
    def pruning(self):
        '''Returns the pruning level as an integer.  None indicates no
        pruning.'''
        pruning = self._integer('pruning')
        if pruning and pruning > 0:
            return pruning
        return None

    def _protocol_version_string(self, key):
        version_str = self.features.get(key)
        ptuple = protocol_tuple(version_str)
        return version_string(ptuple)

    @cachedproperty
    def protocol_min(self):
        '''Minimum protocol version as a string, e.g., 1.0'''
        return self._protocol_version_string('protocol_min')


# Path: electrumx/lib/util.py
# class cachedproperty(object):
# 
#     def __init__(self, f):
#         self.f = f
# 
#     def __get__(self, obj, type_):
#         obj = obj or type_
#         value = self.f(obj)
#         setattr(obj, self.f.__name__, value)
#         return value
# 
# def protocol_tuple(s):
#     '''Converts a protocol version number, such as "1.0" to a tuple (1, 0).
# 
#     If the version number is bad, (0, ) indicating version 0 is returned.'''
#     try:
#         return tuple(int(part) for part in s.split('.'))
#     except (TypeError, ValueError, AttributeError):
#         return (0, )
# 
# def version_string(ptuple):
#     '''Convert a version tuple such as (1, 2) to "1.2".
#     There is always at least one dot, so (1, ) becomes "1.0".'''
#     while len(ptuple) < 2:
#         ptuple += (0, )
#     return '.'.join(str(p) for p in ptuple)


# Path: electrumx/lib/peer.py
from ipaddress import ip_address, IPv4Address, IPv6Address, IPv4Network, IPv6Network
from socket import AF_INET, AF_INET6
from aiorpcx import is_valid_hostname
from electrumx.lib.util import cachedproperty, protocol_tuple, version_string


    @cachedproperty
    def tcp_port(self):
        '''Returns None if no TCP port, otherwise the port as an integer.'''
        return self._port('tcp_port')

    @cachedproperty
    def server_version(self):
        '''Returns the server version as a string if known, otherwise None.'''
        return self._string('server_version')

    @cachedproperty
    def pruning(self):
        '''Returns the pruning level as an integer.  None indicates no
        pruning.'''
        pruning = self._integer('pruning')
        if pruning and pruning > 0:
            return pruning
        return None

    def _protocol_version_string(self, key):
        version_str = self.features.get(key)
        ptuple = protocol_tuple(version_str)
        return version_string(ptuple)

    @cachedproperty
    def protocol_min(self):
        '''Minimum protocol version as a string, e.g., 1.0'''
        return self._protocol_version_string('protocol_min')


    @cachedproperty