From 6304e81c525a23248748bf3f10619f925794cf04 Mon Sep 17 00:00:00 2001 From: BhaagBodeDK Date: Thu, 25 Aug 2022 15:51:45 +0000 Subject: [PATCH 1/3] #124 Show inflight htlc route --- gui/templates/pending_htlcs.html | 4 ++-- gui/views.py | 11 +++++++++-- jobs.py | 8 ++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/gui/templates/pending_htlcs.html b/gui/templates/pending_htlcs.html index babce0e5..b32b572a 100644 --- a/gui/templates/pending_htlcs.html +++ b/gui/templates/pending_htlcs.html @@ -23,7 +23,7 @@

Outgoing HTLCs

{% if htlc.forwarding_alias == '' %}---{% else %}{{ htlc.forwarding_alias }}{% endif %} {{ htlc.amount|intcomma }} {{ htlc.hours_til_expiration }} hours - {{ htlc.hash_lock }} + {{ htlc.hash_lock }} {% endfor %} @@ -50,7 +50,7 @@

Incoming HTLCs

{% if htlc.forwarding_alias == '' %}---{% else %}{{ htlc.forwarding_alias }}{% endif %} {{ htlc.amount|intcomma }} {{ htlc.hours_til_expiration }} hours - {{ htlc.hash_lock }} + {{ htlc.hash_lock }} {% endfor %} diff --git a/gui/views.py b/gui/views.py index 559c504d..910ba1d8 100644 --- a/gui/views.py +++ b/gui/views.py @@ -1259,7 +1259,14 @@ def channel(request): 'graph_links': graph_links(), 'network_links': network_links() } - return render(request, 'channel.html', context) + try: + return render(request, 'channel.html', context) + except Exception as e: + try: + error = str(e.code()) + except: + error = str(e) + return render(request, 'error.html', {'error': error}) else: return redirect('home') @@ -1369,7 +1376,7 @@ def failed_htlcs(request): def payments(request): if request.method == 'GET': context = { - 'payments': Payments.objects.filter(status=2).annotate(ppm=Round((Sum('fee')*1000000)/Sum('value'), output_field=IntegerField())).order_by('-creation_date')[:150], + 'payments': Payments.objects.exclude(status=3).annotate(ppm=Round((Sum('fee')*1000000)/Sum('value'), output_field=IntegerField())).order_by('-creation_date')[:150], } return render(request, 'payments.html', context) else: diff --git a/jobs.py b/jobs.py index 987099f8..49091015 100644 --- a/jobs.py +++ b/jobs.py @@ -31,9 +31,9 @@ def update_payments(stub): try: new_payment = Payments(creation_date=datetime.fromtimestamp(payment.creation_date), payment_hash=payment.payment_hash, value=round(payment.value_msat/1000, 3), fee=round(payment.fee_msat/1000, 3), status=payment.status, index=payment.payment_index) new_payment.save() - if payment.status == 2: + if payment.status == 2 or payment.status == 1: for attempt in payment.htlcs: - if attempt.status == 1: + if attempt.status == 1 or attempt.status == 0: hops = attempt.route.hops hop_count = 0 cost_to = 0 @@ -74,10 +74,10 @@ def update_payment(stub, payment, self_pubkey): db_payment.status = payment.status db_payment.index = payment.payment_index db_payment.save() - if payment.status == 2: + if payment.status == 2 or payment.status == 1: PaymentHops.objects.filter(payment_hash=db_payment).delete() for attempt in payment.htlcs: - if attempt.status == 1: + if attempt.status == 1 or attempt.status == 0: hops = attempt.route.hops hop_count = 0 cost_to = 0 From 9438791b5cc411cc8a4eaac2a2a46c62575e640f Mon Sep 17 00:00:00 2001 From: BhaagBodeDK Date: Thu, 25 Aug 2022 16:52:01 +0000 Subject: [PATCH 2/3] 124 Ignore inflight payments before 30 days --- jobs.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jobs.py b/jobs.py index 49091015..24f73a61 100644 --- a/jobs.py +++ b/jobs.py @@ -20,7 +20,8 @@ def update_payments(stub): inflight_payments = Payments.objects.filter(status=1).order_by('index') for payment in inflight_payments: payment_data = stub.ListPayments(ln.ListPaymentsRequest(include_incomplete=True, index_offset=payment.index-1, max_payments=1)).payments - if len(payment_data) > 0 and payment.payment_hash == payment_data[0].payment_hash: + #Ignore inflight payments before 30 days + if len(payment_data) > 0 and payment.payment_hash == payment_data[0].payment_hash and payment.creation_date > (datetime.now() - timedelta(days=30)): update_payment(stub, payment_data[0], self_pubkey) else: payment.status = 3 From 13a6ef48ef6901b5fb0e70e7ae4177e35fb5bf28 Mon Sep 17 00:00:00 2001 From: BhaagBodeDK Date: Mon, 22 Aug 2022 07:59:34 +0000 Subject: [PATCH 3/3] Add route link to payment/invoice hash --- gui/templates/channel.html | 4 ++-- gui/templates/home.html | 4 ++-- gui/templates/invoices.html | 2 +- gui/templates/payments.html | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gui/templates/channel.html b/gui/templates/channel.html index 62601208..63a2003f 100644 --- a/gui/templates/channel.html +++ b/gui/templates/channel.html @@ -280,7 +280,7 @@

Last 5 Payments Sent

{% for payment in payments %} {{ payment.creation_date|naturaltime }} - {{ payment.payment_hash }} + {{ payment.payment_hash }} {{ payment.value|add:"0"|intcomma }} {{ payment.fee|intcomma }} {{ payment.ppm|intcomma }} @@ -313,7 +313,7 @@

Last 5 Payments Received

{{ invoice.creation_date|naturaltime }} {% if invoice.state == 1 %}{{ invoice.settle_date|naturaltime }}{% else %}---{% endif %} - {{ invoice.r_hash }} + {{ invoice.r_hash }} {{ invoice.value|add:"0"|intcomma }} {% if invoice.state == 1 %}{{ invoice.amt_paid|intcomma }}{% else %}---{% endif %} {% if invoice.state == 0 %}Open{% elif invoice.state == 1 %}Settled{% elif invoice.state == 2 %}Canceled{% else %}{{ invoice.state }}{% endif %} diff --git a/gui/templates/home.html b/gui/templates/home.html index 0c0ebcd6..1d4345d1 100644 --- a/gui/templates/home.html +++ b/gui/templates/home.html @@ -491,7 +491,7 @@

Last 5 Payments Sent

{% for payment in payments %} {{ payment.creation_date|naturaltime }} - {{ payment.payment_hash }} + {{ payment.payment_hash }} {{ payment.value|add:"0"|intcomma }} {{ payment.fee|intcomma }} {{ payment.ppm|intcomma }} @@ -524,7 +524,7 @@

Last 5 Payments Received

{{ invoice.creation_date|naturaltime }} {% if invoice.state == 1 %}{{ invoice.settle_date|naturaltime }}{% else %}---{% endif %} - {{ invoice.r_hash }} + {{ invoice.r_hash }} {{ invoice.value|add:"0"|intcomma }} {% if invoice.state == 1 %}{{ invoice.amt_paid|intcomma }}{% else %}---{% endif %} {% if invoice.state == 0 %}Open{% elif invoice.state == 1 %}Settled{% elif invoice.state == 2 %}Canceled{% else %}{{ invoice.state }}{% endif %} diff --git a/gui/templates/invoices.html b/gui/templates/invoices.html index fa799aa2..08109181 100644 --- a/gui/templates/invoices.html +++ b/gui/templates/invoices.html @@ -21,7 +21,7 @@

Last 150 Invoices

{{ invoice.creation_date|naturaltime }} {% if invoice.state == 1 %}{{ invoice.settle_date|naturaltime }}{% else %}---{% endif %} - {{ invoice.r_hash }} +
{{ invoice.r_hash }} {{ invoice.value|add:"0"|intcomma }} {% if invoice.state == 1 %}{{ invoice.amt_paid|intcomma }}{% else %}---{% endif %} {% if invoice.state == 0 %}Open{% elif invoice.state == 1 %}Settled{% elif invoice.state == 2 %}Canceled{% else %}{{ invoice.state }}{% endif %} diff --git a/gui/templates/payments.html b/gui/templates/payments.html index bf7ad3de..42f0f244 100644 --- a/gui/templates/payments.html +++ b/gui/templates/payments.html @@ -21,7 +21,7 @@

Last 150 Payments

{% for payment in payments %} {{ payment.creation_date|naturaltime }} - {{ payment.payment_hash }} +
{{ payment.payment_hash }} {{ payment.value|add:"0"|intcomma }} {{ payment.fee|intcomma }} {{ payment.ppm|intcomma }}