Browse Source

possibly fix #1403

283
ThomasV 9 years ago
parent
commit
2ffd419e66
  1. 23
      gui/qt/paytoedit.py

23
gui/qt/paytoedit.py

@ -75,39 +75,34 @@ class PayToEdit(ScanQRTextEdit):
x, y = line.split(',') x, y = line.split(',')
n = re.match('^SCRIPT\s+([0-9a-fA-F]+)$', x.strip()) n = re.match('^SCRIPT\s+([0-9a-fA-F]+)$', x.strip())
if n: if n:
_type = 'script' script = str(n.group(1)).decode('hex')
address = n.group(1).decode('hex')
amount = self.parse_amount(y) amount = self.parse_amount(y)
return 'script', script, amount
else: else:
_type = 'address'
address = self.parse_address(x) address = self.parse_address(x)
amount = self.parse_amount(y) amount = self.parse_amount(y)
return _type, address, amount return 'address', address, amount
def parse_amount(self, x): def parse_amount(self, x):
p = pow(10, self.amount_edit.decimal_point()) p = pow(10, self.amount_edit.decimal_point())
return int( p * Decimal(x.strip())) return int(p * Decimal(x.strip()))
def parse_address(self, line): def parse_address(self, line):
r = line.strip() r = line.strip()
m = re.match('^'+RE_ALIAS+'$', r) m = re.match('^'+RE_ALIAS+'$', r)
address = m.group(2) if m else r address = str(m.group(2)) if m else r
assert bitcoin.is_address(address) assert bitcoin.is_address(address)
return address return address
def check_text(self): def check_text(self):
self.errors = [] self.errors = []
if self.is_pr: if self.is_pr:
return return
# filter out empty lines # filter out empty lines
lines = filter( lambda x: x, self.lines()) lines = filter(lambda x: x, self.lines())
outputs = [] outputs = []
total = 0 total = 0
self.payto_address = None self.payto_address = None
if len(lines) == 1: if len(lines) == 1:
data = lines[0] data = lines[0]
if data.startswith("bitcoin:"): if data.startswith("bitcoin:"):
@ -123,12 +118,12 @@ class PayToEdit(ScanQRTextEdit):
for i, line in enumerate(lines): for i, line in enumerate(lines):
try: try:
type, to_address, amount = self.parse_address_and_amount(line) _type, to_address, amount = self.parse_address_and_amount(line)
except: except:
self.errors.append((i, line.strip())) self.errors.append((i, line.strip()))
continue continue
outputs.append((type, to_address, amount)) outputs.append((_type, to_address, amount))
total += amount total += amount
self.outputs = outputs self.outputs = outputs
@ -158,11 +153,9 @@ class PayToEdit(ScanQRTextEdit):
return self.outputs[:] return self.outputs[:]
def lines(self): def lines(self):
return unicode(self.toPlainText()).split('\n') return unicode(self.toPlainText()).split('\n')
def is_multiline(self): def is_multiline(self):
return len(self.lines()) > 1 return len(self.lines()) > 1

Loading…
Cancel
Save