Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Do not broadcast transaction for a payment request (#868)
* Do not broadcast transaction for a payment request

A transaction from a BIP70 invoice should not be broadcasted by the
wallet.
If a valid PaymentACK is received it is up to the merchant to broadcast
the transaction.
This also fixes a nasty race condition where a transaction was
broadcasted before the merchant had ACK'd it which would likley cause
the user to loose money.

Also updated the memo field from "Electrum" to "Electron Cash".

Fixes #812

* Explicitly check for HTTP 200 OK for PaymentACK

A payment processor using BIP70 shall respond with HTTP 200 OK status
response.

* Propagate error message from paymentrequest

* Change send_ack to send_payment in paymentrequest

The function is sending a Payment message and receiving a PaymentACK
message and thus it was incorrectly named.

* Dont save and mark payment req as paid on failure
  • Loading branch information
jonas-lundqvist authored and cculianu committed Oct 3, 2018
1 parent 9a65c0a commit abf57d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 11 additions & 7 deletions gui/qt/main_window.py
Expand Up @@ -1579,19 +1579,23 @@ def broadcast_transaction(self, tx, tx_desc):

def broadcast_thread():
# non-GUI thread
status = False
msg = "Failed"
pr = self.payment_request
if pr and pr.has_expired():
self.payment_request = None
return False, _("Payment request has expired")
status, msg = self.network.broadcast_transaction(tx)
if pr and status is True:
self.invoices.set_paid(pr, tx.txid())
self.invoices.save()
self.payment_request = None
if pr:
refund_address = self.wallet.get_receiving_addresses()[0]
ack_status, ack_msg = pr.send_ack(str(tx), refund_address)
ack_status, ack_msg = pr.send_payment(str(tx), refund_address)
msg = ack_msg
if ack_status:
msg = ack_msg
self.invoices.set_paid(pr, tx.txid())
self.invoices.save()
self.payment_request = None
status = True
else:
status, msg = self.network.broadcast_transaction(tx)
return status, msg

# Capture current TL window; override might be removed on return
Expand Down
6 changes: 3 additions & 3 deletions lib/paymentrequest.py
Expand Up @@ -261,7 +261,7 @@ def get_id(self):
def get_outputs(self):
return self.outputs[:]

def send_ack(self, raw_tx, refund_addr):
def send_payment(self, raw_tx, refund_addr):
pay_det = self.details
if not self.details.payment_url:
return False, "no url"
Expand All @@ -270,7 +270,7 @@ def send_ack(self, raw_tx, refund_addr):
paymnt.transactions.append(bfh(raw_tx))
ref_out = paymnt.refund_to.add()
ref_out.script = bfh(transaction.Transaction.pay_script(refund_addr))
paymnt.memo = "Paid using Electrum"
paymnt.memo = "Paid using Electron Cash"
pm = paymnt.SerializeToString()
payurl = urllib.parse.urlparse(pay_det.payment_url)
try:
Expand All @@ -282,7 +282,7 @@ def send_ack(self, raw_tx, refund_addr):
except Exception as e:
print(e)
return False, "Payment Message/PaymentACK Failed"
if r.status_code >= 500:
if r.status_code != 200:
return False, r.reason
try:
paymntack = pb2.PaymentACK()
Expand Down

0 comments on commit abf57d5

Please sign in to comment.