tpython3 updates - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit e02687bcf219dc8d4b49d1b962effaf3b5be5878 DIR parent d8e37644d3d2004d1d7fc909a5f73133062a7cbc HTML Author: ThomasV <thomasv@electrum.org> Date: Sun, 13 Aug 2017 12:00:33 +0200 python3 updates Diffstat: M lib/coinchooser.py | 2 +- M lib/network.py | 2 +- M lib/paymentrequest.py | 11 ++--------- M lib/plugins.py | 2 +- M plugins/ledger/ledger.py | 37 ++++++++++++++++--------------- M plugins/trezor/plugin.py | 2 +- 6 files changed, 25 insertions(+), 31 deletions(-) --- DIR diff --git a/lib/coinchooser.py b/lib/coinchooser.py t@@ -255,7 +255,7 @@ class CoinChooserRandom(CoinChooserBase): # And now some random ones attempts = min(100, (len(buckets) - 1) * 10 + 1) - permutation = range(len(buckets)) + permutation = list(range(len(buckets))) for i in range(attempts): # Get a random permutation of the buckets, and # incrementally combine buckets until sufficient DIR diff --git a/lib/network.py b/lib/network.py t@@ -937,7 +937,7 @@ class Network(util.DaemonThread): self.notify('interfaces') def maintain_requests(self): - for interface in self.interfaces.values(): + for interface in list(self.interfaces.values()): if interface.request and time.time() - interface.request_time > 20: interface.print_error("blockchain request timed out") self.connection_down(interface.server) DIR diff --git a/lib/paymentrequest.py b/lib/paymentrequest.py t@@ -267,20 +267,16 @@ class PaymentRequest: return self.outputs[:] def send_ack(self, raw_tx, refund_addr): - pay_det = self.details if not self.details.payment_url: return False, "no url" - paymnt = pb2.Payment() paymnt.merchant_data = pay_det.merchant_data - paymnt.transactions.append(raw_tx) - + paymnt.transactions.append(bfh(raw_tx)) ref_out = paymnt.refund_to.add() ref_out.script = transaction.Transaction.pay_script(TYPE_ADDRESS, refund_addr) paymnt.memo = "Paid using Electrum" pm = paymnt.SerializeToString() - payurl = urllib_parse.urlparse(pay_det.payment_url) try: r = requests.post(payurl.geturl(), data=pm, headers=ACK_HEADERS, verify=ca_path) t@@ -291,16 +287,13 @@ class PaymentRequest: except Exception as e: print(e) return False, "Payment Message/PaymentACK Failed" - if r.status_code >= 500: return False, r.reason - try: paymntack = pb2.PaymentACK() paymntack.ParseFromString(r.content) except Exception: return False, "PaymentACK could not be processed. Payment was sent; please manually verify that payment was received." - print("PaymentACK message received: %s" % paymntack.memo) return True, paymntack.memo t@@ -495,7 +488,7 @@ class InvoiceStore(object): l = {} for k, pr in self.invoices.items(): l[k] = { - 'hex': bh2u(pr), + 'hex': bh2u(pr.raw), 'requestor': pr.requestor, 'txid': pr.tx } DIR diff --git a/lib/plugins.py b/lib/plugins.py t@@ -508,7 +508,7 @@ class DeviceMgr(ThreadJob, PrintError): usage_page = d['usage_page'] id_ = d['serial_number'] if len(id_) == 0: - id_ = d['path'] + id_ = str(d['path']) id_ += str(interface_number) + str(usage_page) devices.append(Device(d['path'], interface_number, id_, product_key, usage_page)) DIR diff --git a/plugins/ledger/ledger.py b/plugins/ledger/ledger.py t@@ -13,7 +13,7 @@ from electrum.plugins import BasePlugin, hook from electrum.keystore import Hardware_KeyStore, parse_xpubkey from electrum.transaction import push_script, Transaction from ..hw_wallet import HW_PluginBase -from electrum.util import format_satoshis_plain, print_error, is_verbose +from electrum.util import format_satoshis_plain, print_error, is_verbose, bfh, bh2u try: import hid t@@ -80,10 +80,11 @@ class Ledger_Client(): childnum = int(lastChild[0]) else: childnum = 0x80000000 | int(lastChild[0]) - xpub = bitcoin.serialize_xpub(0, str(nodeData['chainCode']), str(publicKey), depth, self.i4b(fingerprint), self.i4b(childnum)) + xpub = bitcoin.serialize_xpub(0, nodeData['chainCode'], publicKey, depth, self.i4b(fingerprint), self.i4b(childnum)) return xpub except Exception as e: - print_error(e) + traceback.print_exc(file=sys.stdout) + #print_error(e) return None def has_detached_pin_support(self, client): t@@ -314,9 +315,9 @@ class Ledger_KeyStore(Hardware_KeyStore): output_type, addr, amount = txout txOutput += int_to_hex(amount, 8) script = tx.pay_script(output_type, addr) - txOutput += var_int(len(script)/2) + txOutput += var_int(len(script)//2) txOutput += script - txOutput = txOutput.decode('hex') + txOutput = bfh(txOutput) # Recognize outputs - only one output and one change is authorized if not p2shTransaction: t@@ -340,23 +341,23 @@ class Ledger_KeyStore(Hardware_KeyStore): for utxo in inputs: sequence = int_to_hex(utxo[5], 4) if segwitTransaction: - txtmp = bitcoinTransaction(bytearray(utxo[0].decode('hex'))) - tmp = utxo[3].decode('hex')[::-1].encode('hex') - tmp += int_to_hex(utxo[1], 4) - tmp += str(txtmp.outputs[utxo[1]].amount).encode('hex') - chipInputs.append({'value' : tmp.decode('hex'), 'witness' : True, 'sequence' : sequence}) - redeemScripts.append(bytearray(utxo[2].decode('hex'))) + txtmp = bitcoinTransaction(bfh(utxo[0])) + tmp = bfh(utxo[3])[::-1] + tmp += bfh(int_to_hex(utxo[1], 4)) + tmp += str(txtmp.outputs[utxo[1]].amount) + chipInputs.append({'value' : tmp, 'witness' : True, 'sequence' : sequence}) + redeemScripts.append(bfh(utxo[2])) elif not p2shTransaction: - txtmp = bitcoinTransaction(bytearray(utxo[0].decode('hex'))) + txtmp = bitcoinTransaction(bfh(utxo[0])) trustedInput = self.get_client().getTrustedInput(txtmp, utxo[1]) trustedInput['sequence'] = sequence chipInputs.append(trustedInput) redeemScripts.append(txtmp.outputs[utxo[1]].script) else: - tmp = utxo[3].decode('hex')[::-1].encode('hex') - tmp += int_to_hex(utxo[1], 4) - chipInputs.append({'value' : tmp.decode('hex'), 'sequence' : sequence}) - redeemScripts.append(bytearray(utxo[2].decode('hex'))) + tmp = bfh(utxo[3])[::-1] + tmp += bfh(int_to_hex(utxo[1], 4)) + chipInputs.append({'value' : tmp, 'sequence' : sequence}) + redeemScripts.append(bfh(utxo[2])) # Sign all inputs firstTransaction = True t@@ -391,7 +392,7 @@ class Ledger_KeyStore(Hardware_KeyStore): chipInputs, redeemScripts[inputIndex]) if not p2shTransaction: outputData = self.get_client().finalizeInput(output, format_satoshis_plain(outputAmount), - format_satoshis_plain(tx.get_fee()), changePath, bytearray(rawTx.decode('hex'))) + format_satoshis_plain(tx.get_fee()), changePath, bfh(rawTx)) else: outputData = self.get_client().finalizeInputFull(txOutput) outputData['outputData'] = txOutput t@@ -425,7 +426,7 @@ class Ledger_KeyStore(Hardware_KeyStore): for i, txin in enumerate(tx.inputs()): signingPos = inputs[i][4] - txin['signatures'][signingPos] = str(signatures[i]).encode('hex') + txin['signatures'][signingPos] = bh2u(signatures[i]) tx.raw = tx.serialize() self.signing = False DIR diff --git a/plugins/trezor/plugin.py b/plugins/trezor/plugin.py t@@ -285,7 +285,7 @@ class TrezorCompatiblePlugin(HW_PluginBase): pubkeys = map(f, x_pubkeys) multisig = self.types.MultisigRedeemScriptType( pubkeys=pubkeys, - signatures=map(lambda x: bfh(x)[:-1] if x else '', txin.get('signatures')), + signatures=map(lambda x: bfh(x)[:-1] if x else b'', txin.get('signatures')), m=txin.get('num_sig'), ) txinputtype = self.types.TxInputType(