SatSale

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit efdaec88e6b9dc89152a3c0108064c31671efbde
parent f4f8098f07f94ee6caec44865ffa7aa366d92020
Author: nickfarrow <nick@nickfarrow.com>
Date:   Tue, 25 May 2021 23:24:55 +1000

Removed excessive inheritance, simplified invoices

Diffstat:
Mpay/bitcoind.py | 39+++++++++++++++++++++++++++++----------
Mpay/lnd.py | 30++++++++++++++++++++++++------
Msatsale.py | 2+-
3 files changed, 54 insertions(+), 17 deletions(-)

diff --git a/pay/bitcoind.py b/pay/bitcoind.py @@ -1,14 +1,15 @@ import time +import uuid +import qrcode + import config -from invoice.payment_invoice import invoice +from invoice.price_feed import get_btc_value -class btcd(invoice): - def __init__(self): - # super().__init__(dollar_value, currency, label, test) - # print(self.__dict__) - # self.__dict__ = invoice.__dict__.copy() + +class btcd(): + def __init__(self): from bitcoinrpc.authproxy import AuthServiceProxy connection_str = "http://{}:{}@{}:{}/wallet/{}".format( @@ -20,7 +21,6 @@ class btcd(invoice): try: self.rpc = AuthServiceProxy(connection_str) - # if test: info = self.rpc.getblockchaininfo() print(info) @@ -41,9 +41,28 @@ class btcd(invoice): Check your RPC / port tunneling settings and try again." ) - def invoice(self, dollar_value, currency, label, test=False): - super().__init__(dollar_value, currency, label, test) - print(self.__dict__) + def invoice(self, dollar_value, currency, label): + self.dollar_value = dollar_value + self.currency = currency + self.value = round(get_btc_value(dollar_value, currency), 8) + self.uuid = str(uuid.uuid4()) + self.label = self.uuid + self.status = "Payment initialised." + self.response = "" + self.time_left = config.payment_timeout + self.confirmed_paid = 0 + self.unconfirmed_paid = 0 + self.paid = False + self.txid = "" + return + + def create_qr(self): + qr_str = "{}?amount={}&label={}".format( + self.address.upper(), self.value, self.label + ) + + img = qrcode.make(qr_str) + img.save("static/qr_codes/{}.png".format(self.uuid)) return def check_payment(self): diff --git a/pay/lnd.py b/pay/lnd.py @@ -5,12 +5,14 @@ import os import json from base64 import b64decode from google.protobuf.json_format import MessageToJson +import uuid +import qrcode -import config -from invoice.payment_invoice import invoice +from invoice.price_feed import get_btc_value +import config -class lnd(invoice): +class lnd(): def __init__(self): from lndgrpc import LNDClient @@ -59,9 +61,25 @@ class lnd(invoice): print("Ready for payments requests.") return - def invoice(self, dollar_value, currency, label, test=False): - super().__init__(dollar_value, currency, label, test) - print(self.__dict__) + def invoice(self, dollar_value, currency, label): + self.dollar_value = dollar_value + self.currency = currency + self.value = round(get_btc_value(dollar_value, currency), 8) + self.uuid = str(uuid.uuid4()) + self.label = self.uuid + self.status = "Payment initialised." + self.response = "" + self.time_left = config.payment_timeout + self.confirmed_paid = 0 + self.unconfirmed_paid = 0 + self.paid = False + self.txid = "" + return + + def create_qr(self): + qr_str = "{}".format(self.address.upper()) + img = qrcode.make(qr_str) + img.save("static/qr_codes/{}.png".format(self.uuid)) return # Copy tls and macaroon certs from remote machine. diff --git a/satsale.py b/satsale.py @@ -155,7 +155,7 @@ def create_invoice(dollar_amount, currency, label, payment_method=config.pay_met print("Invalid payment method") return - # Load invoice + # Load invoice information payment.invoice(dollar_amount, currency, label) # Get payment address and generate qr code.