python3 updates

This commit is contained in:
ThomasV 2017-08-13 12:00:33 +02:00
parent d8e37644d3
commit e02687bcf2
6 changed files with 25 additions and 31 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)
@ -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
@ -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
}

View File

@ -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))

View File

@ -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
@ -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):
@ -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:
@ -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
@ -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
@ -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

View File

@ -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(