|
|
|
@ -51,14 +51,24 @@ class PayToEdit(QTextEdit): |
|
|
|
e.setFrame(True) |
|
|
|
e.setFrame(True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse_line(self, line): |
|
|
|
def parse_address_and_amount(self, line): |
|
|
|
recipient, amount = line.split(',') |
|
|
|
x, y = line.split(',') |
|
|
|
amount = Decimal(amount.strip()) |
|
|
|
address = self.parse_address(x) |
|
|
|
recipient = recipient.strip() |
|
|
|
amount = self.parse_amount(y) |
|
|
|
m = re.match(RE_ALIAS, recipient) |
|
|
|
return address, amount |
|
|
|
to_address = m.group(2) if m else recipient |
|
|
|
|
|
|
|
assert bitcoin.is_address(to_address) |
|
|
|
|
|
|
|
return to_address, amount |
|
|
|
def parse_amount(self, x): |
|
|
|
|
|
|
|
p = pow(10, self.amount_edit.decimal_point()) |
|
|
|
|
|
|
|
return int( p * Decimal(x.strip())) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse_address(self, line): |
|
|
|
|
|
|
|
r = line.strip() |
|
|
|
|
|
|
|
m = re.match('^'+RE_ALIAS+'$', r) |
|
|
|
|
|
|
|
address = m.group(2) if m else r |
|
|
|
|
|
|
|
assert bitcoin.is_address(address) |
|
|
|
|
|
|
|
return address |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_text(self): |
|
|
|
def check_text(self): |
|
|
|
@ -67,22 +77,61 @@ class PayToEdit(QTextEdit): |
|
|
|
outputs = [] |
|
|
|
outputs = [] |
|
|
|
total = 0 |
|
|
|
total = 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(lines) == 1: |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
self.payto_address = self.parse_address(lines[0]) |
|
|
|
|
|
|
|
except: |
|
|
|
|
|
|
|
self.payto_address = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.payto_address: |
|
|
|
|
|
|
|
print "unlock", self.payto_address |
|
|
|
|
|
|
|
self.unlock_amount() |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
for line in lines: |
|
|
|
for line in lines: |
|
|
|
try: |
|
|
|
try: |
|
|
|
to_address, amount = self.parse_line(line) |
|
|
|
to_address, amount = self.parse_address_and_amount(line) |
|
|
|
except: |
|
|
|
except: |
|
|
|
continue |
|
|
|
continue |
|
|
|
|
|
|
|
|
|
|
|
outputs.append((to_address, amount)) |
|
|
|
outputs.append((to_address, amount)) |
|
|
|
total += amount |
|
|
|
total += amount |
|
|
|
|
|
|
|
|
|
|
|
self.outputs = outputs |
|
|
|
self.outputs = outputs |
|
|
|
|
|
|
|
self.payto_address = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if total: |
|
|
|
|
|
|
|
self.amount_edit.setAmount(total) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
self.amount_edit.setText("") |
|
|
|
|
|
|
|
|
|
|
|
self.amount_edit.setText(str(total) if total else "") |
|
|
|
|
|
|
|
if total or len(lines)>1: |
|
|
|
if total or len(lines)>1: |
|
|
|
self.lock_amount() |
|
|
|
self.lock_amount() |
|
|
|
else: |
|
|
|
else: |
|
|
|
self.unlock_amount() |
|
|
|
self.unlock_amount() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_outputs(self): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.payto_address: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not bitcoin.is_address(self.payto_address): |
|
|
|
|
|
|
|
QMessageBox.warning(self, _('Error'), _('Invalid Bitcoin Address') + ':\n' + to_address, _('OK')) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
amount = self.amount_edit.get_amount() |
|
|
|
|
|
|
|
except Exception: |
|
|
|
|
|
|
|
QMessageBox.warning(self, _('Error'), _('Invalid Amount'), _('OK')) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
outputs = [(self.payto_address, amount)] |
|
|
|
|
|
|
|
return outputs |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return self.outputs |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def lines(self): |
|
|
|
def lines(self): |
|
|
|
return str(self.toPlainText()).split('\n') |
|
|
|
return str(self.toPlainText()).split('\n') |
|
|
|
|
|
|
|
|
|
|
|
|