support for payment requests in the gui
This commit is contained in:
parent
2642b7e126
commit
87fa402c34
@ -150,21 +150,38 @@ class ElectrumGui:
|
|||||||
def set_url(self, url):
|
def set_url(self, url):
|
||||||
from electrum import util
|
from electrum import util
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
try:
|
try:
|
||||||
address, amount, label, message, url = util.parse_url(url)
|
address, amount, label, message, request_url, url = util.parse_url(url)
|
||||||
except Exception:
|
except Exception:
|
||||||
QMessageBox.warning(self.main_window, _('Error'), _('Invalid bitcoin URL'), _('OK'))
|
QMessageBox.warning(self.main_window, _('Error'), _('Invalid bitcoin URL'), _('OK'))
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
if amount:
|
||||||
if amount and self.main_window.base_unit() == 'mBTC':
|
try:
|
||||||
amount = str( 1000* Decimal(amount))
|
if self.main_window.base_unit() == 'mBTC':
|
||||||
elif amount:
|
amount = str( 1000* Decimal(amount))
|
||||||
amount = str(Decimal(amount))
|
else:
|
||||||
except Exception:
|
amount = str(Decimal(amount))
|
||||||
amount = "0.0"
|
except Exception:
|
||||||
QMessageBox.warning(self.main_window, _('Error'), _('Invalid Amount'), _('OK'))
|
amount = "0.0"
|
||||||
|
QMessageBox.warning(self.main_window, _('Error'), _('Invalid Amount'), _('OK'))
|
||||||
|
|
||||||
|
if request_url:
|
||||||
|
try:
|
||||||
|
from electrum import paymentrequest
|
||||||
|
except:
|
||||||
|
print "cannot import paymentrequest"
|
||||||
|
return
|
||||||
|
def payment_request():
|
||||||
|
pr = paymentrequest.PaymentRequest(request_url)
|
||||||
|
if pr.verify() or 1:
|
||||||
|
self.main_window.payment_request = pr
|
||||||
|
self.main_window.emit(SIGNAL('payment_request_ok'))
|
||||||
|
else:
|
||||||
|
self.main_window.emit(SIGNAL('payment_request_failed'))
|
||||||
|
|
||||||
|
threading.Thread(target=payment_request).start()
|
||||||
|
|
||||||
self.main_window.set_send(address, amount, label, message)
|
self.main_window.set_send(address, amount, label, message)
|
||||||
if self.lite_window:
|
if self.lite_window:
|
||||||
|
|||||||
@ -120,6 +120,7 @@ class ElectrumWindow(QMainWindow):
|
|||||||
set_language(config.get('language'))
|
set_language(config.get('language'))
|
||||||
|
|
||||||
self.funds_error = False
|
self.funds_error = False
|
||||||
|
self.payment_request = None
|
||||||
self.completions = QStringListModel()
|
self.completions = QStringListModel()
|
||||||
|
|
||||||
self.tabs = tabs = QTabWidget(self)
|
self.tabs = tabs = QTabWidget(self)
|
||||||
@ -155,6 +156,7 @@ class ElectrumWindow(QMainWindow):
|
|||||||
self.connect(self, QtCore.SIGNAL('transaction_signal'), lambda: self.notify_transactions() )
|
self.connect(self, QtCore.SIGNAL('transaction_signal'), lambda: self.notify_transactions() )
|
||||||
self.connect(self, QtCore.SIGNAL('send_tx2'), self.send_tx2)
|
self.connect(self, QtCore.SIGNAL('send_tx2'), self.send_tx2)
|
||||||
self.connect(self, QtCore.SIGNAL('send_tx3'), self.send_tx3)
|
self.connect(self, QtCore.SIGNAL('send_tx3'), self.send_tx3)
|
||||||
|
self.connect(self, QtCore.SIGNAL('payment_request_ok'), self.payment_request_ok)
|
||||||
|
|
||||||
self.history_list.setFocus(True)
|
self.history_list.setFocus(True)
|
||||||
|
|
||||||
@ -203,7 +205,7 @@ class ElectrumWindow(QMainWindow):
|
|||||||
self.password_menu.setEnabled(not self.wallet.is_watching_only())
|
self.password_menu.setEnabled(not self.wallet.is_watching_only())
|
||||||
self.seed_menu.setEnabled(self.wallet.has_seed())
|
self.seed_menu.setEnabled(self.wallet.has_seed())
|
||||||
self.mpk_menu.setEnabled(self.wallet.is_deterministic())
|
self.mpk_menu.setEnabled(self.wallet.is_deterministic())
|
||||||
self.import_menu.setEnabled(self.wallet.can_create_accounts() or not self.wallet.is_deterministic())
|
self.import_menu.setEnabled(self.wallet.can_import())
|
||||||
|
|
||||||
self.update_lock_icon()
|
self.update_lock_icon()
|
||||||
self.update_buttons_on_seed()
|
self.update_buttons_on_seed()
|
||||||
@ -767,24 +769,31 @@ class ElectrumWindow(QMainWindow):
|
|||||||
|
|
||||||
|
|
||||||
def do_send(self):
|
def do_send(self):
|
||||||
|
|
||||||
label = unicode( self.message_e.text() )
|
label = unicode( self.message_e.text() )
|
||||||
r = unicode( self.payto_e.text() )
|
|
||||||
r = r.strip()
|
|
||||||
|
|
||||||
# label or alias, with address in brackets
|
if self.payment_request:
|
||||||
m = re.match('(.*?)\s*\<([1-9A-HJ-NP-Za-km-z]{26,})\>', r)
|
outputs = self.payment_request.outputs
|
||||||
to_address = m.group(2) if m else r
|
amount = self.payment_request.get_amount()
|
||||||
|
|
||||||
if not is_valid(to_address):
|
else:
|
||||||
QMessageBox.warning(self, _('Error'), _('Invalid Bitcoin Address') + ':\n' + to_address, _('OK'))
|
r = unicode( self.payto_e.text() )
|
||||||
return
|
r = r.strip()
|
||||||
|
|
||||||
|
# label or alias, with address in brackets
|
||||||
|
m = re.match('(.*?)\s*\<([1-9A-HJ-NP-Za-km-z]{26,})\>', r)
|
||||||
|
to_address = m.group(2) if m else r
|
||||||
|
if not is_valid(to_address):
|
||||||
|
QMessageBox.warning(self, _('Error'), _('Invalid Bitcoin Address') + ':\n' + to_address, _('OK'))
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
amount = self.read_amount(unicode( self.amount_e.text()))
|
||||||
|
except Exception:
|
||||||
|
QMessageBox.warning(self, _('Error'), _('Invalid Amount'), _('OK'))
|
||||||
|
return
|
||||||
|
|
||||||
|
outputs = [(to_address, amount)]
|
||||||
|
|
||||||
try:
|
|
||||||
amount = self.read_amount(unicode( self.amount_e.text()))
|
|
||||||
except Exception:
|
|
||||||
QMessageBox.warning(self, _('Error'), _('Invalid Amount'), _('OK'))
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
fee = self.read_amount(unicode( self.fee_e.text()))
|
fee = self.read_amount(unicode( self.fee_e.text()))
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -801,7 +810,7 @@ class ElectrumWindow(QMainWindow):
|
|||||||
if not self.question(_("The fee for this transaction seems unusually high.\nAre you really sure you want to pay %(fee)s in fees?")%{ 'fee' : self.format_amount(fee) + ' '+ self.base_unit()}):
|
if not self.question(_("The fee for this transaction seems unusually high.\nAre you really sure you want to pay %(fee)s in fees?")%{ 'fee' : self.format_amount(fee) + ' '+ self.base_unit()}):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.send_tx(to_address, amount, fee, label)
|
self.send_tx(outputs, fee, label)
|
||||||
|
|
||||||
|
|
||||||
def waiting_dialog(self, message):
|
def waiting_dialog(self, message):
|
||||||
@ -815,11 +824,10 @@ class ElectrumWindow(QMainWindow):
|
|||||||
|
|
||||||
|
|
||||||
@protected
|
@protected
|
||||||
def send_tx(self, to_address, amount, fee, label, password):
|
def send_tx(self, outputs, fee, label, password):
|
||||||
|
|
||||||
# first, create an unsigned tx
|
# first, create an unsigned tx
|
||||||
domain = self.get_payment_sources()
|
domain = self.get_payment_sources()
|
||||||
outputs = [(to_address, amount)]
|
|
||||||
try:
|
try:
|
||||||
tx = self.wallet.make_unsigned_transaction(outputs, fee, None, domain)
|
tx = self.wallet.make_unsigned_transaction(outputs, fee, None, domain)
|
||||||
tx.error = None
|
tx.error = None
|
||||||
@ -842,9 +850,6 @@ class ElectrumWindow(QMainWindow):
|
|||||||
self.tx_wait_dialog = self.waiting_dialog('Signing..')
|
self.tx_wait_dialog = self.waiting_dialog('Signing..')
|
||||||
threading.Thread(target=sign_thread).start()
|
threading.Thread(target=sign_thread).start()
|
||||||
|
|
||||||
# add recipient to addressbook
|
|
||||||
if to_address not in self.wallet.addressbook and not self.wallet.is_mine(to_address):
|
|
||||||
self.wallet.addressbook.append(to_address)
|
|
||||||
|
|
||||||
|
|
||||||
def send_tx2(self):
|
def send_tx2(self):
|
||||||
@ -866,28 +871,36 @@ class ElectrumWindow(QMainWindow):
|
|||||||
self.show_transaction(tx)
|
self.show_transaction(tx)
|
||||||
return
|
return
|
||||||
|
|
||||||
# broadcast the tx
|
|
||||||
def broadcast_thread():
|
def broadcast_thread():
|
||||||
|
if self.payment_request:
|
||||||
|
refund_address = self.wallet.addresses()[0]
|
||||||
|
self.payment_request.send_ack(str(tx), refund_address)
|
||||||
|
self.payment_request = None
|
||||||
|
# note: BIP 70 recommends not broadcasting the tx to the network and letting the merchant do that
|
||||||
self.tx_broadcast_result = self.wallet.sendtx(tx)
|
self.tx_broadcast_result = self.wallet.sendtx(tx)
|
||||||
self.emit(SIGNAL('send_tx3'))
|
self.emit(SIGNAL('send_tx3'))
|
||||||
|
|
||||||
self.tx_broadcast_dialog = self.waiting_dialog('Broadcasting..')
|
self.tx_broadcast_dialog = self.waiting_dialog('Broadcasting..')
|
||||||
threading.Thread(target=broadcast_thread).start()
|
threading.Thread(target=broadcast_thread).start()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def send_tx3(self):
|
def send_tx3(self):
|
||||||
self.tx_broadcast_dialog.accept()
|
self.tx_broadcast_dialog.accept()
|
||||||
status, msg = self.tx_broadcast_result
|
status, msg = self.tx_broadcast_result
|
||||||
if status:
|
if status:
|
||||||
QMessageBox.information(self, '', _('Payment sent.') + '\n' + msg, _('OK'))
|
QMessageBox.information(self, '', _('Payment sent.') + '\n' + msg, _('OK'))
|
||||||
self.do_clear()
|
self.do_clear()
|
||||||
self.update_contacts_tab()
|
|
||||||
else:
|
else:
|
||||||
QMessageBox.warning(self, _('Error'), msg, _('OK'))
|
QMessageBox.warning(self, _('Error'), msg, _('OK'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def payment_request_ok(self):
|
||||||
|
self.payto_e.setText(self.payment_request.domain)
|
||||||
|
self.payto_e.setReadOnly(True)
|
||||||
|
self.amount_e.setText(self.format_amount(self.payment_request.get_amount()))
|
||||||
|
self.amount_e.setReadOnly(True)
|
||||||
|
|
||||||
|
|
||||||
def set_send(self, address, amount, label, message):
|
def set_send(self, address, amount, label, message):
|
||||||
|
|||||||
@ -12,7 +12,7 @@ try:
|
|||||||
import paymentrequest_pb2
|
import paymentrequest_pb2
|
||||||
except:
|
except:
|
||||||
print "protoc --proto_path=lib/ --python_out=lib/ lib/paymentrequest.proto"
|
print "protoc --proto_path=lib/ --python_out=lib/ lib/paymentrequest.proto"
|
||||||
sys.exit(1)
|
raise Exception()
|
||||||
|
|
||||||
import urlparse
|
import urlparse
|
||||||
import requests
|
import requests
|
||||||
@ -21,38 +21,47 @@ from M2Crypto import X509
|
|||||||
from bitcoin import is_valid
|
from bitcoin import is_valid
|
||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
|
|
||||||
|
import util
|
||||||
import transaction
|
import transaction
|
||||||
|
|
||||||
|
|
||||||
REQUEST_HEADERS = {'Accept': 'application/bitcoin-paymentrequest', 'User-Agent': 'Electrum'}
|
REQUEST_HEADERS = {'Accept': 'application/bitcoin-paymentrequest', 'User-Agent': 'Electrum'}
|
||||||
ACK_HEADERS = {'Content-Type':'application/bitcoin-payment','Accept':'application/bitcoin-paymentack','User-Agent':'Electrum'}
|
ACK_HEADERS = {'Content-Type':'application/bitcoin-payment','Accept':'application/bitcoin-paymentack','User-Agent':'Electrum'}
|
||||||
|
|
||||||
|
ca_path = os.path.expanduser("~/.electrum/ca/ca-bundle.crt")
|
||||||
|
ca_list = {}
|
||||||
|
try:
|
||||||
|
with open(ca_path, 'r') as ca_f:
|
||||||
|
c = ""
|
||||||
|
for line in ca_f:
|
||||||
|
if line == "-----BEGIN CERTIFICATE-----\n":
|
||||||
|
c = line
|
||||||
|
else:
|
||||||
|
c += line
|
||||||
|
if line == "-----END CERTIFICATE-----\n":
|
||||||
|
x = X509.load_cert_string(c)
|
||||||
|
ca_list[x.get_fingerprint()] = x
|
||||||
|
except Exception:
|
||||||
|
print "ERROR: Could not open %s"%ca_path
|
||||||
|
print "ca-bundle.crt file should be placed in ~/.electrum/ca/ca-bundle.crt"
|
||||||
|
print "Documentation on how to download or create the file here: http://curl.haxx.se/docs/caextract.html"
|
||||||
|
print "Payment will continue with manual verification."
|
||||||
|
raise Exception()
|
||||||
|
|
||||||
|
|
||||||
class PaymentRequest:
|
class PaymentRequest:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, url):
|
||||||
self.ca_path = os.path.expanduser("~/.electrum/ca/ca-bundle.crt")
|
self.url = url
|
||||||
self.ca_list = {}
|
self.outputs = []
|
||||||
try:
|
|
||||||
with open(self.ca_path, 'r') as ca_f:
|
def get_amount(self):
|
||||||
c = ""
|
return sum(map(lambda x:x[1], self.outputs))
|
||||||
for line in ca_f:
|
|
||||||
if line == "-----BEGIN CERTIFICATE-----\n":
|
|
||||||
c = line
|
|
||||||
else:
|
|
||||||
c += line
|
|
||||||
if line == "-----END CERTIFICATE-----\n":
|
|
||||||
x = X509.load_cert_string(c)
|
|
||||||
self.ca_list[x.get_fingerprint()] = x
|
|
||||||
except Exception:
|
|
||||||
print "ERROR: Could not open %s"%self.ca_path
|
|
||||||
print "ca-bundle.crt file should be placed in ~/.electrum/ca/ca-bundle.crt"
|
|
||||||
print "Documentation on how to download or create the file here: http://curl.haxx.se/docs/caextract.html"
|
|
||||||
print "Payment will continue with manual verification."
|
|
||||||
|
|
||||||
|
|
||||||
|
def verify(self):
|
||||||
def verify(self, url):
|
u = urlparse.urlparse(self.url)
|
||||||
|
|
||||||
u = urlparse.urlparse(urllib2.unquote(url))
|
|
||||||
self.domain = u.netloc
|
self.domain = u.netloc
|
||||||
|
|
||||||
connection = httplib.HTTPConnection(u.netloc) if u.scheme == 'http' else httplib.HTTPSConnection(u.netloc)
|
connection = httplib.HTTPConnection(u.netloc) if u.scheme == 'http' else httplib.HTTPSConnection(u.netloc)
|
||||||
@ -64,6 +73,9 @@ class PaymentRequest:
|
|||||||
paymntreq.ParseFromString(r)
|
paymntreq.ParseFromString(r)
|
||||||
|
|
||||||
sig = paymntreq.signature
|
sig = paymntreq.signature
|
||||||
|
if not sig:
|
||||||
|
print "No signature"
|
||||||
|
return
|
||||||
|
|
||||||
cert = paymentrequest_pb2.X509Certificates()
|
cert = paymentrequest_pb2.X509Certificates()
|
||||||
cert.ParseFromString(paymntreq.pki_data)
|
cert.ParseFromString(paymntreq.pki_data)
|
||||||
@ -116,7 +128,7 @@ class PaymentRequest:
|
|||||||
supplied_CA_CN = x509[cert_num-2].get_subject().CN
|
supplied_CA_CN = x509[cert_num-2].get_subject().CN
|
||||||
CA_match = False
|
CA_match = False
|
||||||
|
|
||||||
x = self.ca_list.get(supplied_CA_fingerprint)
|
x = ca_list.get(supplied_CA_fingerprint)
|
||||||
if x:
|
if x:
|
||||||
CA_OU = x.get_subject().OU
|
CA_OU = x.get_subject().OU
|
||||||
CA_match = True
|
CA_match = True
|
||||||
@ -155,9 +167,8 @@ class PaymentRequest:
|
|||||||
|
|
||||||
if pay_det.expires and pay_det.expires < int(time.time()):
|
if pay_det.expires and pay_det.expires < int(time.time()):
|
||||||
print "ERROR: Payment Request has Expired."
|
print "ERROR: Payment Request has Expired."
|
||||||
return False
|
#return False
|
||||||
|
|
||||||
self.outputs = []
|
|
||||||
for o in pay_det.outputs:
|
for o in pay_det.outputs:
|
||||||
addr = transaction.get_address_from_output_script(o.script)[1]
|
addr = transaction.get_address_from_output_script(o.script)[1]
|
||||||
self.outputs.append( (addr, o.amount) )
|
self.outputs.append( (addr, o.amount) )
|
||||||
@ -165,7 +176,7 @@ class PaymentRequest:
|
|||||||
if CA_match:
|
if CA_match:
|
||||||
print 'Signed By Trusted CA: ', CA_OU
|
print 'Signed By Trusted CA: ', CA_OU
|
||||||
|
|
||||||
return True
|
return pay_det
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -185,7 +196,7 @@ class PaymentRequest:
|
|||||||
|
|
||||||
payurl = urlparse.urlparse(pay_det.payment_url)
|
payurl = urlparse.urlparse(pay_det.payment_url)
|
||||||
try:
|
try:
|
||||||
r = requests.post(payurl.geturl(), data=pm, headers=ACK_HEADERS, verify=self.ca_path)
|
r = requests.post(payurl.geturl(), data=pm, headers=ACK_HEADERS, verify=ca_path)
|
||||||
except requests.exceptions.SSLError:
|
except requests.exceptions.SSLError:
|
||||||
print "Payment Message/PaymentACK verify Failed"
|
print "Payment Message/PaymentACK verify Failed"
|
||||||
try:
|
try:
|
||||||
@ -202,17 +213,20 @@ class PaymentRequest:
|
|||||||
print "PaymentACK could not be processed. Payment was sent; please manually verify that payment was received."
|
print "PaymentACK could not be processed. Payment was sent; please manually verify that payment was received."
|
||||||
|
|
||||||
|
|
||||||
uri = "bitcoin:mpu3yTLdqA1BgGtFUwkVJmhnU3q5afaFkf?r=https%3A%2F%2Fbitcoincore.org%2F%7Egavin%2Ff.php%3Fh%3D26c19879d44c3891214e7897797b9160&amount=1"
|
|
||||||
url = "https%3A%2F%2Fbitcoincore.org%2F%7Egavin%2Ff.php%3Fh%3D26c19879d44c3891214e7897797b9160"
|
|
||||||
|
|
||||||
#uri = "bitcoin:1m9Lw2pFCe6Hs7xUuo9fMJCzEwQNdCo5e?amount=0.0012&r=https%3A%2F%2Fbitpay.com%2Fi%2F8XNDiQU92H2whNG4j8hZ5M"
|
|
||||||
#url = "https%3A%2F%2Fbitpay.com%2Fi%2F8XNDiQU92H2whNG4j8hZ5M"
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
pr = PaymentRequest()
|
try:
|
||||||
if not pr.verify(url):
|
uri = sys.argv[1]
|
||||||
|
except:
|
||||||
|
print "usage: %s url"%sys.argv[0]
|
||||||
|
print "example url: \"bitcoin:mpu3yTLdqA1BgGtFUwkVJmhnU3q5afaFkf?r=https%3A%2F%2Fbitcoincore.org%2F%7Egavin%2Ff.php%3Fh%3D2a828c05b8b80dc440c80a5d58890298&amount=1\""
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
address, amount, label, message, request_url, url = util.parse_url(uri)
|
||||||
|
pr = PaymentRequest(request_url)
|
||||||
|
if not pr.verify():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
print 'Payment Request Verified Domain: ', pr.domain
|
print 'Payment Request Verified Domain: ', pr.domain
|
||||||
@ -220,5 +234,5 @@ if __name__ == "__main__":
|
|||||||
print 'Payment Memo: ', pr.payment_details.memo
|
print 'Payment Memo: ', pr.payment_details.memo
|
||||||
|
|
||||||
tx = "blah"
|
tx = "blah"
|
||||||
pr.send_ack(tx, "1vXAXUnGitimzinpXrqDWVU4tyAAQ34RA")
|
pr.send_ack(tx, refund_addr = "1vXAXUnGitimzinpXrqDWVU4tyAAQ34RA")
|
||||||
|
|
||||||
|
|||||||
49
lib/util.py
49
lib/util.py
@ -153,46 +153,43 @@ def age(from_date, since_date = None, target_tz=None, include_seconds=False):
|
|||||||
return "over %d years ago" % (round(distance_in_minutes / 525600))
|
return "over %d years ago" % (round(distance_in_minutes / 525600))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# URL decode
|
# URL decode
|
||||||
_ud = re.compile('%([0-9a-hA-H]{2})', re.MULTILINE)
|
#_ud = re.compile('%([0-9a-hA-H]{2})', re.MULTILINE)
|
||||||
urldecode = lambda x: _ud.sub(lambda m: chr(int(m.group(1), 16)), x)
|
#urldecode = lambda x: _ud.sub(lambda m: chr(int(m.group(1), 16)), x)
|
||||||
|
|
||||||
def parse_url(url):
|
def parse_url(url):
|
||||||
|
import urlparse
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
url = str(url)
|
|
||||||
o = url[8:].split('?')
|
|
||||||
address = o[0]
|
|
||||||
if len(o)>1:
|
|
||||||
params = o[1].split('&')
|
|
||||||
else:
|
|
||||||
params = []
|
|
||||||
|
|
||||||
kv = {}
|
u = urlparse.urlparse(url)
|
||||||
|
assert u.scheme == 'bitcoin'
|
||||||
|
|
||||||
|
address = u.path
|
||||||
|
#assert bitcoin.is_address(address)
|
||||||
|
|
||||||
|
pq = urlparse.parse_qs(u.query)
|
||||||
|
|
||||||
|
for k, v in pq.items():
|
||||||
|
if len(v)!=1:
|
||||||
|
raise Exception('Duplicate Key', k)
|
||||||
|
|
||||||
amount = label = message = ''
|
amount = label = message = ''
|
||||||
for p in params:
|
if 'amount' in pq:
|
||||||
k,v = p.split('=')
|
am = pq['amount'][0]
|
||||||
uv = urldecode(v)
|
|
||||||
if k in kv:
|
|
||||||
raise Exception('Duplicate Keys')
|
|
||||||
kv[k] = uv
|
|
||||||
|
|
||||||
if 'amount' in kv:
|
|
||||||
am = kv['amount']
|
|
||||||
m = re.match('([0-9\.]+)X([0-9])', am)
|
m = re.match('([0-9\.]+)X([0-9])', am)
|
||||||
if m:
|
if m:
|
||||||
k = int(m.group(2)) - 8
|
k = int(m.group(2)) - 8
|
||||||
amount = Decimal(m.group(1)) * pow( Decimal(10) , k)
|
amount = Decimal(m.group(1)) * pow( Decimal(10) , k)
|
||||||
else:
|
else:
|
||||||
amount = Decimal(am)
|
amount = Decimal(am)
|
||||||
if 'message' in kv:
|
if 'message' in pq:
|
||||||
message = kv['message']
|
message = pq['message'][0]
|
||||||
if 'label' in kv:
|
if 'label' in pq:
|
||||||
label = kv['label']
|
label = pq['label'][0]
|
||||||
|
if 'r' in pq:
|
||||||
|
request_url = pq['r'][0]
|
||||||
|
|
||||||
return address, amount, label, message, url
|
return address, amount, label, message, request_url, url
|
||||||
|
|
||||||
|
|
||||||
# Python bug (http://bugs.python.org/issue1927) causes raw_input
|
# Python bug (http://bugs.python.org/issue1927) causes raw_input
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user