X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=lib%2Fnetwork.py;h=f07846aa09fe093afc2868229f5ef2348486d952;hb=8997c760a2cdfdc4a78e093c143788938fa68407;hp=aab98acf099d51ed5492c16003e606e25ac6a95a;hpb=3c4fa06c10ab45c0337d97d619fe62ce3bd17407;p=electrum-nvc.git diff --git a/lib/network.py b/lib/network.py index aab98ac..f07846a 100644 --- a/lib/network.py +++ b/lib/network.py @@ -7,18 +7,20 @@ from blockchain import Blockchain DEFAULT_PORTS = {'t':'50001', 's':'50002', 'h':'8081', 'g':'8082'} 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'} + 'ecdsa.org': DEFAULT_PORTS, + 'ecdsa.net': DEFAULT_PORTS, + 'electrum.hachre.de': DEFAULT_PORTS, + 'electrum.novit.ro': DEFAULT_PORTS, + 'electrum.coinwallet.me': DEFAULT_PORTS, + 'cube.l0g.in': DEFAULT_PORTS, + 'bitcoin.epicinet.net': DEFAULT_PORTS, + 'h.1209k.com': DEFAULT_PORTS, + 'electrum.electricnewyear.net': DEFAULT_PORTS, + 'erbium.sytes.net': DEFAULT_PORTS, + 'e2.pdmc.net':DEFAULT_PORTS, + 'electrum.no-ip.org':{'h': '80', 's': '50002', 't': '50001', 'g': '443'}, + 'electrum.thwg.org':DEFAULT_PORTS, + 'electrum.stepkrav.pw':DEFAULT_PORTS, } @@ -70,7 +72,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 +113,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 +187,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 +373,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') @@ -402,6 +413,13 @@ class Network(threading.Thread): return self.interface.synchronous_get(requests) + def get_header(self, tx_height): + return self.blockchain.read_header(tx_height) + + def get_local_height(self): + return self.blockchain.height() + + #def retrieve_transaction(self, tx_hash, tx_height=0): # import transaction @@ -413,24 +431,14 @@ class Network(threading.Thread): -class NetworkProxy: - # interface to the network object. - # handle subscriptions and callbacks - # the network object can be jsonrpc server - def __init__(self, network): - self.network = network - - - - if __name__ == "__main__": - import simple_config - config = simple_config.SimpleConfig({'verbose':True, 'server':'ecdsa.org:50002:s'}) - network = Network(config) + network = NetworkProxy({}) network.start() + print network.get_servers() - while 1: - time.sleep(1) - - + q = Queue.Queue() + network.send([('blockchain.headers.subscribe',[])], q.put) + while True: + r = q.get(timeout=10000) + print r