Add currencies. Fix info view

This commit is contained in:
Reckless_Satoshi 2022-01-12 06:26:26 -08:00
parent 2523e5ef09
commit bd7c82fc11
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
5 changed files with 83 additions and 19 deletions

View File

@ -28,6 +28,14 @@ class LNNode():
invoicesstub = invoicesstub.InvoicesStub(channel) invoicesstub = invoicesstub.InvoicesStub(channel)
routerstub = routerstub.RouterStub(channel) routerstub = routerstub.RouterStub(channel)
payment_failure_context = {
0: "Payment isn't failed (yet)",
1: "There are more routes to try, but the payment timeout was exceeded.",
2: "All possible routes were tried and failed permanently. Or were no routes to the destination at all.",
3: "A non-recoverable error has occured.",
4: "Payment details incorrect (unknown hash, invalid amt or invalid final cltv delta)",
5: "Insufficient local balance."}
@classmethod @classmethod
def decode_payreq(cls, invoice): def decode_payreq(cls, invoice):
'''Decodes a lightning payment request (invoice)''' '''Decodes a lightning payment request (invoice)'''
@ -85,7 +93,18 @@ class LNNode():
response = cls.invoicesstub.LookupInvoiceV2(request, metadata=[('macaroon', MACAROON.hex())]) response = cls.invoicesstub.LookupInvoiceV2(request, metadata=[('macaroon', MACAROON.hex())])
print('status here') print('status here')
print(response.state) print(response.state)
return response.state == 3 # True if hold invoice is accepted.
# TODO ERROR HANDLING
if response.state == 0: # OPEN
print('STATUS: OPEN')
pass
if response.state == 1: # SETTLED
pass
if response.state == 2: # CANCELLED
pass
if response.state == 3: # ACCEPTED (LOCKED)
print('STATUS: ACCEPTED')
return True
@classmethod @classmethod
def check_until_invoice_locked(cls, payment_hash, expiration): def check_until_invoice_locked(cls, payment_hash, expiration):
@ -100,7 +119,7 @@ class LNNode():
print(invoice) print(invoice)
if timezone.now > expiration: if timezone.now > expiration:
break break
if invoice.state == 'ACCEPTED': if invoice.state == 3: # True if hold invoice is accepted.
return True return True
return False return False
@ -160,13 +179,26 @@ class LNNode():
for response in cls.routerstub.SendPaymentV2(request, metadata=[('macaroon', MACAROON.hex())]): for response in cls.routerstub.SendPaymentV2(request, metadata=[('macaroon', MACAROON.hex())]):
print(response) print(response)
print(response.status) print(response.status)
print(response.grpc_status)
# TODO ERROR HANDLING
if response.status == 0 : # Status 0 'UNKNOWN'
pass
if response.status == 1 : # Status 1 'IN_FLIGHT' if response.status == 1 : # Status 1 'IN_FLIGHT'
pass # LIVE UPDATE THE order.lnpayment.status pass
if response.status == 'FAILED': if response.status == 3 : # 4 'FAILED' ??
pass # LIVE UPDATE THE order.lnpayment.status '''0 Payment isn't failed (yet).
1 There are more routes to try, but the payment timeout was exceeded.
2 All possible routes were tried and failed permanently. Or were no routes to the destination at all.
3 A non-recoverable error has occured.
4 Payment details incorrect (unknown hash, invalid amt or invalid final cltv delta)
5 Insufficient local balance.
'''
context = cls.payment_failure_context[response.failure_reason]
pass
if response.status == 2 : # STATUS 'SUCCEEDED' if response.status == 2 : # STATUS 'SUCCEEDED'
return True return True
# How to catch the errors like:"grpc_message":"invoice is already paid","grpc_status":6} # How to catch the errors like:"grpc_message":"invoice is already paid","grpc_status":6}
# These are not in the response only printed to commandline # These are not in the response only printed to commandline

View File

@ -1,4 +1,4 @@
from datetime import timedelta from datetime import time, timedelta
from django.utils import timezone from django.utils import timezone
from .lightning.node import LNNode from .lightning.node import LNNode
@ -345,6 +345,10 @@ class Logics():
order.last_satoshis = cls.satoshis_now(order) order.last_satoshis = cls.satoshis_now(order)
order.taker_bond.status = LNPayment.Status.LOCKED order.taker_bond.status = LNPayment.Status.LOCKED
order.taker_bond.save() order.taker_bond.save()
# Log a market tick
MarketTick.log_a_tick(order)
# With the bond confirmation the order is extended 'public_order_duration' hours # With the bond confirmation the order is extended 'public_order_duration' hours
order.expires_at = timezone.now() + timedelta(minutes=INVOICE_AND_ESCROW_DURATION) order.expires_at = timezone.now() + timedelta(minutes=INVOICE_AND_ESCROW_DURATION)
order.status = Order.Status.WF2 order.status = Order.Status.WF2
@ -512,13 +516,19 @@ class Logics():
# Double check the escrow is settled. # Double check the escrow is settled.
if LNNode.double_check_htlc_is_settled(order.trade_escrow.payment_hash): if LNNode.double_check_htlc_is_settled(order.trade_escrow.payment_hash):
if cls.pay_buyer_invoice(order): ##### !!! KEY LINE - PAYS THE BUYER INVOICE !!! is_payed, context = cls.pay_buyer_invoice(order) ##### !!! KEY LINE - PAYS THE BUYER INVOICE !!!
order.status = Order.Status.PAY if is_payed:
order.buyer_invoice.status = LNPayment.Status.SETLED order.status = Order.Status.SUC
order.buyer_invoice.status = LNPayment.Status.SUCCED
order.expires_at = timezone.now() + timedelta(days=1) # One day to rate / see this order.
order.save()
# RETURN THE BONDS # RETURN THE BONDS
cls.return_bond(order.taker_bond) cls.return_bond(order.taker_bond)
cls.return_bond(order.maker_bond) cls.return_bond(order.maker_bond)
else:
# error handling here
pass
else: else:
return False, {'bad_request':'You cannot confirm the fiat payment at this stage'} return False, {'bad_request':'You cannot confirm the fiat payment at this stage'}

View File

@ -227,7 +227,6 @@ class OrderView(viewsets.ViewSet):
# 2) If action is 'update invoice' # 2) If action is 'update invoice'
if action == 'update_invoice' and invoice: if action == 'update_invoice' and invoice:
print('AAAAAAAAAAAAAAAAAAAAAAAAAAAA')
valid, context = Logics.update_invoice(order,request.user,invoice) valid, context = Logics.update_invoice(order,request.user,invoice)
if not valid: return Response(context, status.HTTP_400_BAD_REQUEST) if not valid: return Response(context, status.HTTP_400_BAD_REQUEST)
@ -407,7 +406,7 @@ class InfoView(ListAPIView):
context = {} context = {}
context['num_public_buy_orders'] = len(Order.objects.filter(type=Order.Types.BUY, status=Order.Status.PUB)) context['num_public_buy_orders'] = len(Order.objects.filter(type=Order.Types.BUY, status=Order.Status.PUB))
context['num_public_sell_orders'] = len(Order.objects.filter(type=Order.Types.BUY, status=Order.Status.PUB)) context['num_public_sell_orders'] = len(Order.objects.filter(type=Order.Types.SELL, status=Order.Status.PUB))
# Number of active users (logged in in last 30 minutes) # Number of active users (logged in in last 30 minutes)
active_user_time_range = (timezone.now() - timedelta(minutes=30), timezone.now()) active_user_time_range = (timezone.now() - timedelta(minutes=30), timezone.now())

View File

@ -435,8 +435,8 @@ handleRatingChange=(e)=>{
{this.props.data.isSeller & this.props.data.statusCode == 10 ? this.showChat(false,true,true) : ""} {this.props.data.isSeller & this.props.data.statusCode == 10 ? this.showChat(false,true,true) : ""}
{/* Trade Finished */} {/* Trade Finished */}
{this.props.data.isSeller & this.props.data.statusCode > 12 & this.props.data.statusCode < 15 ? this.showRateSelect() : ""} {(this.props.data.isSeller & this.props.data.statusCode > 12 & this.props.data.statusCode < 15) ? this.showRateSelect() : ""}
{this.props.data.isBuyer & this.props.data.statusCode == 14 ? this.showRateSelect() : ""} {(this.props.data.isBuyer & this.props.data.statusCode == 14) ? this.showRateSelect() : ""}
{/* Trade Finished - Payment Routing Failed */} {/* Trade Finished - Payment Routing Failed */}
{this.props.data.isBuyer & this.props.data.statusCode == 15 ? this.showUpdateInvoice() : ""} {this.props.data.isBuyer & this.props.data.statusCode == 15 ? this.showUpdateInvoice() : ""}

View File

@ -1,8 +1,31 @@
{ {
"1":"USD", "1":"USD",
"2":"EUR", "2":"EUR",
"3":"ETH", "3":"JPY",
"4":"AUD", "4":"GBP",
"5":"BRL", "5":"AUD",
"6":"CAD" "6":"CAD",
} "7":"CHF",
"8":"CNY",
"9":"HKD",
"10":"NZD",
"11":"SEK",
"12":"KRW",
"13":"SGD",
"14":"NOK",
"15":"MXN",
"16":"KRW",
"17":"RUB",
"18":"ZAR",
"19":"TRY",
"20":"BRL",
"21": "CLP",
"22": "CZK",
"23": "DKK",
"24": "HKR",
"25": "HUF",
"26": "INR",
"27": "ISK",
"28": "PLN",
"29": "RON"
}