SatSale

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

commit b77dcb58b39b7b5476bee2dd9382daf16b438545
parent 6a4580483cf47ff9f95377f8f6c80dda47c74756
Author: nickfarrow <nick@nickfarrow.com>
Date:   Sat, 22 May 2021 21:21:53 +1000

Use single RPC connection accross websockets

Diffstat:
Mpay/bitcoind.py | 21+++++++++++++++------
Mpay/lnd.py | 18++++++++++--------
Msatsale.py | 21++++++++++++---------
3 files changed, 37 insertions(+), 23 deletions(-)

diff --git a/pay/bitcoind.py b/pay/bitcoind.py @@ -4,9 +4,9 @@ from invoice.payment_invoice import invoice class btcd(invoice): - def __init__(self, dollar_value, currency, label, test=False): - super().__init__(dollar_value, currency, label, test) - print(self.__dict__) + def __init__(self): + # super().__init__(dollar_value, currency, label, test) + # print(self.__dict__) # self.__dict__ = invoice.__dict__.copy() from bitcoinrpc.authproxy import AuthServiceProxy @@ -20,9 +20,9 @@ class btcd(invoice): try: self.rpc = AuthServiceProxy(connection_str) - if test: - info = self.rpc.getblockchaininfo() - print(info) + # if test: + info = self.rpc.getblockchaininfo() + print(info) print("Successfully contacted bitcoind.") break @@ -41,6 +41,11 @@ 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__) + return + def check_payment(self): transactions = self.rpc.listtransactions() relevant_txs = [tx for tx in transactions if tx["address"] == self.address] @@ -60,6 +65,7 @@ class btcd(invoice): for i in range(config.connection_attempts): try: self.address = self.rpc.getnewaddress(self.label) + return except Exception as e: print(e) print( @@ -67,4 +73,7 @@ class btcd(invoice): i + 1, config.connection_attempts ) ) + if config.connection_attempts - i == 1: + print("Reconnecting...") + self.__init__() return diff --git a/pay/lnd.py b/pay/lnd.py @@ -11,10 +11,7 @@ from invoice.payment_invoice import invoice class lnd(invoice): - def __init__(self, dollar_value, currency, label, test=False): - super().__init__(dollar_value, currency, label, test) - print(self.__dict__) - + def __init__(self): from lndgrpc import LNDClient # Copy admin macaroon and tls cert to local machine @@ -38,10 +35,10 @@ class lnd(invoice): cert_filepath=self.certs['tls'], ) - if test: - print("Getting lnd info...") - info = self.lnd.get_info() - print(info) + + print("Getting lnd info...") + info = self.lnd.get_info() + print(info) print("Successfully contacted lnd.") break @@ -62,6 +59,11 @@ 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__) + return + # Copy tls and macaroon certs from remote machine. def copy_certs(self): self.certs = {'tls' : 'tls.cert', 'macaroon' : 'admin.macaroon'} diff --git a/satsale.py b/satsale.py @@ -148,13 +148,16 @@ def update_status(payment, status, console_status=True): # Initialise the payment via the payment method (bitcoind / lightningc / etc), def create_invoice(dollar_amount, currency, label, payment_method=config.pay_method): if payment_method == "bitcoind": - payment = bitcoind.btcd(dollar_amount, currency, label) + payment = bitcoin_node elif payment_method == "lnd": - payment = lnd.lnd(dollar_amount, currency, label) + payment = lightning_node else: print("Invalid payment method") return + # Load invoice + payment.invoice(dollar_amount, currency, label) + # Get payment address and generate qr code. payment.get_address() payment.create_qr() @@ -208,13 +211,13 @@ def process_payment(payment): return -# Test Bitcoind connection on startup: -print("Checking node connectivity...") -if config.pay_method == "bitcoind": - bitcoind.btcd(1, "USD", "Init test.", test=True) -elif config.pay_method == "lnd": - lnd.lnd(1, "USD", "Init test", test=True) -print("Connection successful.") +# Test connections on startup: +print("Connecting to node...") +bitcoin_node = bitcoind.btcd() +print("Connection to bitcoin node successful.") +if config.pay_method == "lnd": + lightning_node = lnd.lnd() + print("Connection to lightning node successful.") if __name__ == "__main__":