electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 557b2c189654975019468a2af8e41edab9a07bb2
parent 216e9403be1a2a5be9c0df6a4cfb4ce443677459
Author: ThomasV <thomasv@electrum.org>
Date:   Tue,  5 Sep 2017 15:27:08 +0200

update scripts for python3

Diffstat:
Mscripts/bip70 | 3++-
Mscripts/get_history | 4++--
Mscripts/peers | 9+++++----
Mscripts/servers | 16+++++++---------
Mscripts/txradar | 8++++----
Mscripts/util.py | 22++++++++++++----------
Mscripts/watch_address | 4++--
7 files changed, 34 insertions(+), 32 deletions(-)

diff --git a/scripts/bip70 b/scripts/bip70 @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # create a BIP70 payment request signed with a certificate import tlslite @@ -35,4 +36,4 @@ pr_string = paymentrequest.make_payment_request(amount, script, memo, rsakey) with open(out_file,'wb') as f: f.write(pr_string) -print "Payment request was written to file '%s'"%out_file +print("Payment request was written to file '%s'"%out_file) diff --git a/scripts/get_history b/scripts/get_history @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import sys from electrum import Network @@ -7,7 +7,7 @@ from electrum.util import json_encode, print_msg try: addr = sys.argv[1] except Exception: - print "usage: get_history <bitcoin_address>" + print("usage: get_history <bitcoin_address>") sys.exit(1) n = Network() diff --git a/scripts/peers b/scripts/peers @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import util, json from collections import defaultdict @@ -16,9 +16,10 @@ def analyze(results): dd[merkle] = d refs = {} for merkle, d in dd.items(): - v = d.values() + v = list(d.values()) m = max(v) - ref = d.keys()[v.index(m)] + dkeys = list(d.keys()) + ref = dkeys[v.index(m)] refs[merkle] = ref, m for k, v in results.items(): height = v.get('block_height') @@ -36,4 +37,4 @@ results = util.send_request(peers, 'blockchain.headers.subscribe', []) errors = analyze(results).keys() for n,v in sorted(results.items(), key=lambda x:x[1].get('block_height')): - print "%40s"%n, v.get('block_height'), v.get('utxo_root'), "error" if n in errors else "ok" + print("%40s"%n, v.get('block_height'), v.get('utxo_root'), "error" if n in errors else "ok") diff --git a/scripts/servers b/scripts/servers @@ -1,15 +1,14 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from electrum import SimpleConfig, set_verbosity from electrum.network import filter_protocol -import time, Queue from collections import defaultdict import util, json set_verbosity(False) config = SimpleConfig() -servers = filter_protocol(protocol = 't') +servers = util.get_peers() results = util.send_request(servers, 'blockchain.headers.subscribe', []) d = defaultdict(int) @@ -18,11 +17,10 @@ for k, r in results.items(): blocks = r.get('block_height') d[blocks] += 1 - - for k, v in results.items(): - print k, v.get('block_height') + print(k, v.get('block_height')) -v = d.values() -numblocks = d.keys()[v.index(max(v))] -print "blocks:",numblocks +v = list(d.values()) +k = list(d.keys()) +numblocks = k[v.index(max(v))] +print("blocks:", numblocks) diff --git a/scripts/txradar b/scripts/txradar @@ -1,9 +1,9 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import util, sys try: tx = sys.argv[1] except: - print "usage: txradar txid" + print("usage: txradar txid") sys.exit(1) peers = util.get_peers() @@ -15,5 +15,5 @@ r2 = [] for k, v in results.items(): (r1 if v else r2).append(k) -print "Received %d answers"%len(results) -print "Propagation rate: %.1f percent" % (len(r1) *100./(len(r1)+ len(r2))) +print("Received %d answers"%len(results)) +print("Propagation rate: %.1f percent" % (len(r1) *100./(len(r1)+ len(r2)))) diff --git a/scripts/util.py b/scripts/util.py @@ -1,4 +1,4 @@ -import select, time, electrum, Queue +import select, time, electrum, queue from electrum import Connection, Interface, SimpleConfig from electrum.network import filter_protocol, parse_servers from collections import defaultdict @@ -8,7 +8,7 @@ def get_interfaces(servers, timeout=10): '''Returns a map of servers to connected interfaces. If any connections fail or timeout, they will be missing from the map. ''' - socket_queue = Queue.Queue() + socket_queue = queue.Queue() config = SimpleConfig() connecting = {} for server in servers: @@ -20,7 +20,7 @@ def get_interfaces(servers, timeout=10): while time.time() < timeout and count < len(servers): try: server, socket = socket_queue.get(True, 0.3) - except Queue.Empty: + except queue.Empty: continue if socket: interfaces[server] = Interface(server, socket) @@ -47,10 +47,10 @@ def wait_on_interfaces(interfaces, timeout=10): def get_peers(): peers = [] # 1. get connected interfaces - server = 'ecdsa.net:110:s' + server = 'h.1209k.com:50002:s' interfaces = get_interfaces([server]) if not interfaces: - print "No connection to", server + print("No connection to", server) return [] # 2. get list of peers interface = interfaces[server] @@ -60,21 +60,23 @@ def get_peers(): response = responses[0][1] # One response, (req, response) tuple peers = parse_servers(response.get('result')) peers = filter_protocol(peers,'s') + #print(response) return peers + def send_request(peers, method, params): - print "Contacting %d servers"%len(peers) + print("Contacting %d servers"%len(peers)) interfaces = get_interfaces(peers) - print "%d servers could be reached" % len(interfaces) + print("%d servers could be reached" % len(interfaces)) for peer in peers: if not peer in interfaces: - print "Connection failed:", peer + print("Connection failed:", peer) for msg_id, i in enumerate(interfaces.values()): i.queue_request(method, params, msg_id) responses = wait_on_interfaces(interfaces) for peer in interfaces: if not peer in responses: - print peer, "did not answer" + print(peer, "did not answer") results = dict(zip(responses.keys(), [t[0][1].get('result') for t in responses.values()])) - print "%d answers"%len(results) + print("%d answers"%len(results)) return results diff --git a/scripts/watch_address b/scripts/watch_address @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import sys import time @@ -8,7 +8,7 @@ from electrum.util import print_msg, json_encode try: addr = sys.argv[1] except Exception: - print "usage: watch_address <bitcoin_address>" + print("usage: watch_address <bitcoin_address>") sys.exit(1) # start network