def lndPayInvoice(lnInvoiceString): try: # call LND GRPC API macaroon = codecs.encode( open(LND_ADMIN_MACAROON_PATH, 'rb').read(), 'hex') os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA' cert = open(LND_TLS_PATH, 'rb').read() ssl_creds = grpc.ssl_channel_credentials(cert) channel = grpc.secure_channel("{0}:10009".format(LND_IP), ssl_creds) stub = rpcstub.LightningStub(channel) request = lnrpc.SendRequest(payment_request=lnInvoiceString, ) response = stub.SendPaymentSync(request, metadata=[('macaroon', macaroon)]) # validate results if len(response.payment_error) > 0: print("error='PAYMENT FAILED'") print("error_detail='{}'".format(response.payment_error)) return except Exception as e: print("error='FAILED LND INVOICE PAYMENT'") return return response
def lndPayInvoice(lnInvoiceString): try: # call LND GRPC API macaroon = codecs.encode(open(LND_ADMIN_MACAROON_PATH, 'rb').read(), 'hex') os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA' cert = open(LND_TLS_PATH, 'rb').read() ssl_creds = grpc.ssl_channel_credentials(cert) channel = grpc.secure_channel("{0}:10009".format(LND_IP), ssl_creds) stub = rpcstub.LightningStub(channel) request = lnrpc.SendRequest( payment_request=lnInvoiceString, ) response = stub.SendPaymentSync(request, metadata=[('macaroon', macaroon)]) # validate results if len(response.payment_error) > 0: raise BlitzError(response.payment_error, {'invoice': lnInvoiceString}) except Exception as e: raise BlitzError("payment failed", {'invoice': lnInvoiceString}, e) return response
def lndDecodeInvoice(lnInvoiceString): try: # call LND GRPC API macaroon = codecs.encode(open(LND_ADMIN_MACAROON_PATH, 'rb').read(), 'hex') os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA' cert = open(LND_TLS_PATH, 'rb').read() ssl_creds = grpc.ssl_channel_credentials(cert) channel = grpc.secure_channel("{0}:10009".format(LND_IP), ssl_creds) stub = rpcstub.LightningStub(channel) request = lnrpc.PayReqString( pay_req=lnInvoiceString, ) response = stub.DecodePayReq(request, metadata=[('macaroon', macaroon)]) # validate results if response.num_msat <= 0: raise BlitzError("zero invoice not allowed", {'invoice': lnInvoiceString}) except Exception as e: raise BlitzError("failed LND invoice decoding", {'invoice': lnInvoiceString}, e) return response
def lndDecodeInvoice(lnInvoiceString): try: # call LND GRPC API macaroon = codecs.encode( open(LND_ADMIN_MACAROON_PATH, 'rb').read(), 'hex') os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA' cert = open(LND_TLS_PATH, 'rb').read() ssl_creds = grpc.ssl_channel_credentials(cert) channel = grpc.secure_channel("{0}:10009".format(LND_IP), ssl_creds) stub = rpcstub.LightningStub(channel) request = lnrpc.PayReqString(pay_req=lnInvoiceString, ) response = stub.DecodePayReq(request, metadata=[('macaroon', macaroon)]) # validate results if response.num_msat <= 0: print("error='ZERO INVOICES NOT ALLOWED'") return except Exception as e: print("error='FAILED LND INVOICE DECODING'") return return response