Merge the network and network_proxy
This commit is contained in:
@@ -7,8 +7,7 @@ import electrum
|
||||
|
||||
# start network
|
||||
c = electrum.SimpleConfig()
|
||||
s = electrum.daemon.get_daemon(c,True)
|
||||
network = electrum.NetworkProxy(s,c)
|
||||
network = electrum.Network(c)
|
||||
network.start()
|
||||
|
||||
# wait until connected
|
||||
@@ -26,4 +25,3 @@ network.send([('blockchain.headers.subscribe',[])], callback)
|
||||
# 3. wait for results
|
||||
while network.is_connected():
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from electrum import NetworkProxy, print_json
|
||||
from electrum import Network, print_json
|
||||
|
||||
try:
|
||||
addr = sys.argv[1]
|
||||
@@ -9,8 +9,7 @@ except Exception:
|
||||
print "usage: get_history <bitcoin_address>"
|
||||
sys.exit(1)
|
||||
|
||||
n = NetworkProxy()
|
||||
n.start(start_daemon=True)
|
||||
h = n.synchronous_get([ ('blockchain.address.get_history',[addr]) ])[0]
|
||||
n = Network()
|
||||
n.start()
|
||||
h = n.synchronous_get(('blockchain.address.get_history',[addr]))
|
||||
print_json(h)
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ def check_create_table(conn):
|
||||
c = conn.cursor()
|
||||
c.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='electrum_payments';")
|
||||
data = c.fetchall()
|
||||
if not data:
|
||||
if not data:
|
||||
c.execute("""CREATE TABLE electrum_payments (address VARCHAR(40), amount FLOAT, confirmations INT(8), received_at TIMESTAMP, expires_at TIMESTAMP, paid INT(1), processed INT(1));""")
|
||||
conn.commit()
|
||||
|
||||
@@ -95,7 +95,7 @@ def on_wallet_update():
|
||||
|
||||
s = (value)/1.e8
|
||||
print "balance for %s:"%addr, s, requested_amount
|
||||
if s>= requested_amount:
|
||||
if s>= requested_amount:
|
||||
print "payment accepted", addr
|
||||
out_queue.put( ('payment', addr))
|
||||
|
||||
@@ -162,7 +162,7 @@ def send_command(cmd, params):
|
||||
except socket.error:
|
||||
print "Server not running"
|
||||
return 1
|
||||
|
||||
|
||||
try:
|
||||
out = f(*params)
|
||||
except socket.error:
|
||||
@@ -186,9 +186,9 @@ def db_thread():
|
||||
data = cur.fetchall()
|
||||
|
||||
# add pending requests to the wallet
|
||||
for item in data:
|
||||
for item in data:
|
||||
addr, amount, confirmations = item
|
||||
if addr in pending_requests:
|
||||
if addr in pending_requests:
|
||||
continue
|
||||
else:
|
||||
with wallet.lock:
|
||||
@@ -216,7 +216,7 @@ def db_thread():
|
||||
print sql
|
||||
cur.execute(sql)
|
||||
|
||||
# set paid=0 for expired requests
|
||||
# set paid=0 for expired requests
|
||||
cur.execute("""UPDATE electrum_payments set paid=0 WHERE expires_at < CURRENT_TIMESTAMP and paid is NULL;""")
|
||||
|
||||
# do callback for addresses that received payment or expired
|
||||
@@ -241,7 +241,7 @@ def db_thread():
|
||||
except ValueError, e:
|
||||
print e
|
||||
print "cannot do callback", data_json
|
||||
|
||||
|
||||
conn.commit()
|
||||
|
||||
conn.close()
|
||||
@@ -259,8 +259,7 @@ if __name__ == '__main__':
|
||||
|
||||
# start network
|
||||
c = electrum.SimpleConfig({'wallet_path':wallet_path})
|
||||
daemon_socket = electrum.daemon.get_daemon(c, True)
|
||||
network = electrum.NetworkProxy(daemon_socket, config)
|
||||
network = electrum.Network(config)
|
||||
network.start()
|
||||
|
||||
# wait until connected
|
||||
@@ -284,7 +283,7 @@ if __name__ == '__main__':
|
||||
network.register_callback('updated', on_wallet_update)
|
||||
|
||||
threading.Thread(target=db_thread, args=()).start()
|
||||
|
||||
|
||||
out_queue = Queue.Queue()
|
||||
# server thread
|
||||
from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer
|
||||
@@ -299,4 +298,3 @@ if __name__ == '__main__':
|
||||
server.handle_request()
|
||||
except socket.timeout:
|
||||
continue
|
||||
|
||||
|
||||
@@ -12,8 +12,7 @@ except Exception:
|
||||
|
||||
# start network
|
||||
c = electrum.SimpleConfig()
|
||||
s = electrum.daemon.get_daemon(c,True)
|
||||
network = electrum.NetworkProxy(s,c)
|
||||
network = electrum.Network(c)
|
||||
network.start()
|
||||
|
||||
# wait until connected
|
||||
@@ -31,4 +30,3 @@ network.send([('blockchain.address.subscribe',[addr])], callback)
|
||||
# 3. wait for results
|
||||
while network.is_connected():
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user