X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=lib%2Fnetwork.py;h=114edc62ae67a4a37ed17f3fae512c08ba5a9518;hb=HEAD;hp=326281038beb693c19d16e8bfda028d96e595176;hpb=b4bed1ccaa3aca4d29d9d54b042c17912a01ef46;p=electrum-nvc.git diff --git a/lib/network.py b/lib/network.py index 3262810..114edc6 100644 --- a/lib/network.py +++ b/lib/network.py @@ -4,21 +4,12 @@ from bitcoin import * import interface from blockchain import Blockchain -DEFAULT_PORTS = {'t':'50001', 's':'50002', 'h':'8081', 'g':'8082'} +DEFAULT_PORTS = {'t':'40001', 's':'40002', 'h':'7081', 'g':'7082'} DEFAULT_SERVERS = { - #'electrum.coinwallet.me': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'}, - 'electrum.hachre.de': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'}, - 'electrum.novit.ro': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'}, - 'electrum.stepkrav.pw': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'}, - #'ecdsa.org': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'}, - 'electrum.no-ip.org': {'h': '80', 's': '50002', 't': '50001', 'g': '443'}, - 'electrum.drollette.com': {'h': '5000', 's': '50002', 't': '50001', 'g': '8082'}, - 'electrum.random.re': {'h': '80', 's': '110', 't': '50001', 'g': '443'}, - 'btc.medoix.com': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'}, - 'electrum.stupidfoot.com': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'}, - #'electrum.pdmc.net': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'}, - 'electrum.be': {'h': '8081', 's': '50002', 't': '50001', 'g': '8082'} +# '127.0.0.1': DEFAULT_PORTS, + '193.23.181.148': DEFAULT_PORTS, + '91.235.143.61': DEFAULT_PORTS, } @@ -70,7 +61,9 @@ from simple_config import SimpleConfig class Network(threading.Thread): - def __init__(self, config = {}): + def __init__(self, config=None): + if config is None: + config = {} # Do not use mutables as default values! threading.Thread.__init__(self) self.daemon = True self.config = SimpleConfig(config) if type(config) == type({}) else config @@ -109,6 +102,7 @@ class Network(threading.Thread): self.subscriptions = {} self.subscriptions[self.on_banner] = [('server.banner',[])] self.subscriptions[self.on_peers] = [('server.peers.subscribe',[])] + self.pending_transactions_for_notifications = [] def is_connected(self): @@ -182,11 +176,14 @@ class Network(threading.Thread): def get_servers(self): - out = self.irc_servers if self.irc_servers else DEFAULT_SERVERS - for s in self.recent_servers: - host, port, protocol = s.split(':') - if host not in out: - out[host] = { protocol:port } + if self.irc_servers: + out = self.irc_servers + else: + out = DEFAULT_SERVERS + for s in self.recent_servers: + host, port, protocol = s.split(':') + if host not in out: + out[host] = { protocol:port } return out def start_interface(self, server): @@ -365,8 +362,11 @@ class Network(threading.Thread): def on_header(self, i, r): result = r.get('result') - if not result: return + if not result: + return height = result.get('block_height') + if not height: + return self.heights[i.server] = height self.merkle_roots[i.server] = result.get('merkle_root') self.utxo_roots[i.server] = result.get('utxo_root') @@ -406,7 +406,7 @@ class Network(threading.Thread): return self.blockchain.read_header(tx_height) def get_local_height(self): - return self.blockchain.local_height + return self.blockchain.height()