|
@ -27,11 +27,12 @@ DEFAULT_SERVERS = ['ecdsa.org','electrum.novit.ro'] # list of default servers |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Interface: |
|
|
class Interface: |
|
|
def __init__(self, host, port, address_callback, history_callback): |
|
|
def __init__(self, host, port, address_callback=None, history_callback=None, newblock_callback=None): |
|
|
self.host = host |
|
|
self.host = host |
|
|
self.port = port |
|
|
self.port = port |
|
|
self.address_callback = address_callback |
|
|
self.address_callback = address_callback |
|
|
self.history_callback = history_callback |
|
|
self.history_callback = history_callback |
|
|
|
|
|
self.newblock_callback = newblock_callback |
|
|
|
|
|
|
|
|
self.servers = DEFAULT_SERVERS # actual list from IRC |
|
|
self.servers = DEFAULT_SERVERS # actual list from IRC |
|
|
self.rtime = 0 |
|
|
self.rtime = 0 |
|
@ -212,8 +213,8 @@ import threading |
|
|
class TCPInterface(Interface): |
|
|
class TCPInterface(Interface): |
|
|
"""json-rpc over persistent TCP connection, asynchronous""" |
|
|
"""json-rpc over persistent TCP connection, asynchronous""" |
|
|
|
|
|
|
|
|
def __init__(self, host, port, acb, hcb): |
|
|
def __init__(self, host, port, address_callback=None, history_callback=None, newblock_callback=None): |
|
|
Interface.__init__(self, host, port, acb, hcb) |
|
|
Interface.__init__(self, host, port, address_callback, history_callback, newblock_callback) |
|
|
self.message_id = 0 |
|
|
self.message_id = 0 |
|
|
self.messages = {} |
|
|
self.messages = {} |
|
|
|
|
|
|
|
@ -286,7 +287,7 @@ class TCPInterface(Interface): |
|
|
|
|
|
|
|
|
elif method == 'numblocks.subscribe': |
|
|
elif method == 'numblocks.subscribe': |
|
|
self.blocks = result |
|
|
self.blocks = result |
|
|
|
|
|
apply(self.newblock_callback,(result,)) |
|
|
else: |
|
|
else: |
|
|
print "received message:", c |
|
|
print "received message:", c |
|
|
|
|
|
|
|
@ -354,7 +355,7 @@ def new_interface(wallet): |
|
|
interface = HttpInterface(host, port, address_cb, history_cb) |
|
|
interface = HttpInterface(host, port, address_cb, history_cb) |
|
|
else: |
|
|
else: |
|
|
print "unknown port number: %d. using native protocol."%port |
|
|
print "unknown port number: %d. using native protocol."%port |
|
|
interface = NativeInterface(host,port) |
|
|
interface = NativeInterface(host, port, address_cb, history_cb) |
|
|
|
|
|
|
|
|
return interface |
|
|
return interface |
|
|
|
|
|
|
|
|