-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from UnitapApp/fix/lnpay
Fix/lnpay
- Loading branch information
Showing
13 changed files
with
585 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,40 @@ | ||
import logging | ||
import json | ||
import lnpay_py | ||
from lnpay_py.wallet import LNPayWallet | ||
from lnpay_py.lntx import LNPayLnTx | ||
from lnpay_py.utility_helpers import get_request | ||
from .lnpay_manager.lnpay_main import initialize | ||
from .lnpay_manager.wallet import LNPayWallet | ||
from .lnpay_manager.lntx import LNPayLnTx | ||
from .lnpay_manager.utility_helpers import get_request | ||
|
||
|
||
class LNPayClient: | ||
def __init__(self, api_url: str, api_key: str, wallet: str) -> None: | ||
self.api_key = api_key | ||
self.wallet_address = wallet | ||
|
||
lnpay_py.initialize(api_key, params={ | ||
'endpoint_url': api_url | ||
}) | ||
|
||
initialize(api_key, params={"endpoint_url": api_url}) | ||
|
||
@property | ||
def wallet(self): | ||
return LNPayWallet(self.wallet_address) | ||
|
||
def pay_invoice(self, invoice: str) -> json: | ||
invoice_params = { | ||
'payment_request': invoice | ||
} | ||
invoice_params = {"payment_request": invoice} | ||
pay_result = self.wallet.pay_invoice(invoice_params) | ||
if 'lnTx' not in pay_result: | ||
logging.error(pay_result['message']) | ||
if "lnTx" not in pay_result: | ||
logging.error(pay_result["message"]) | ||
return False | ||
return pay_result | ||
|
||
def decode_invoice(self, invoice: str) -> json: | ||
return get_request( | ||
f"node/default/payments/decodeinvoice?payment_request={invoice}") | ||
|
||
f"node/default/payments/decodeinvoice?payment_request={invoice}" | ||
) | ||
|
||
def get_balance(self): | ||
info = self.wallet.get_info() | ||
return info['balance'] | ||
return info["balance"] | ||
|
||
def get_invoice_status(self, lntx_id): | ||
ln_tx = LNPayLnTx(lntx_id) | ||
invoice_result = ln_tx.get_info() | ||
return invoice_result | ||
return invoice_result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# from .utility_helpers import post_request | ||
|
||
__version__ = "0.1.1" | ||
|
||
__VERSION__ = "py" + __version__ | ||
__ENDPOINT_URL__ = "https://api.lnpay.co/v1/" | ||
__DEFAULT_WAK__ = "" | ||
__PUBLIC_API_KEY__ = "" | ||
|
||
|
||
def initialize(public_api_key, default_wak=None, params=None): | ||
""" | ||
LNPay module initialization function required for interacting with the LNPay API. | ||
Parameters | ||
---------- | ||
public_api_key (str): Account public key from https://lnpay.co/dashboard/developers | ||
default_wak (str, optional): Default Wallet Access Key to use for a specific wallet when creating a `LNPayWallet`. | ||
params (Object): Object representing additional parameters to set globally. Example: {'endpoint_url': 'https://lnpay.co/v1/'} | ||
""" | ||
|
||
if params is None: | ||
params = {} | ||
|
||
print("initializing lnpay..") | ||
|
||
global __VERSION__ | ||
global __PUBLIC_API_KEY__ | ||
global __ENDPOINT_URL__ | ||
global __DEFAULT_WAK__ | ||
|
||
__VERSION__ = "py" + __version__ | ||
__PUBLIC_API_KEY__ = public_api_key | ||
__ENDPOINT_URL__ = params.get("endpoint_url", __ENDPOINT_URL__) | ||
__DEFAULT_WAK__ = default_wak | ||
|
||
|
||
# def create_wallet(params): | ||
# return post_request('wallet', params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from .utility_helpers import get_request | ||
|
||
|
||
class LNPayLnTx: | ||
""" | ||
A class used for LnTx API Functions | ||
Learn more at https://docs.lnpay.co | ||
""" | ||
|
||
def __init__(self, tx_id): | ||
""" | ||
Parameters | ||
---------- | ||
tx_id (str) : The LNPay transaction id (ex. lntx_tVompfuizfryXznKhc38J8) | ||
""" | ||
|
||
self.tx_id = tx_id | ||
|
||
def get_info(self): | ||
""" | ||
Gets the invoice information for the `tx_id` set in the `__init__` of this class. | ||
Returns | ||
------- | ||
LnTx (Lightning Invoice) Object | ||
https://docs.lnpay.co/lntx/ | ||
Example: | ||
``` | ||
{ | ||
"id": "lntx_IaWG3yS6FB3ZQJDRjXkkkkk", | ||
"created_at": 1577600922, | ||
"updated_at": 1577600922, | ||
"dest_pubkey": "033868c219bdb51a33560d854d500fe7d3898a1ad9e05dd89d0007e11313588500", | ||
"payment_request": "lnbc10n1pw7l9l3pp5pr2sr8pdt2yjm04am0wktr7cphkt8c3gtlvq8qlgaqw9jsh3d6qsdpj2pshjampd3kzunrfde4jq3npw43k2ap6ypgx7mmjgesh2cm9wscqzpgxqrrss4z9zac6gtpskjkhtdsxjd0m4are599k4ya9al0ktqqf7y70xqt5xs3as53va424nsh2dxumdln3ymm2048550hrj5sw8nw2ajzc9p9l3s97", | ||
"r_hash_decoded": "f646ff04116d16b7a70e953034b1c7c475c771847eb43e66892039ff5589863b", | ||
"description_hash": null, | ||
"memo": "This is a memo", | ||
"num_satoshis": 11, | ||
"expiry": 86400, | ||
"expires_at": 1578992143, | ||
"payment_preimage": "71566c546f304e70507a486b7561356177426a7535716345713670482f45582b4e4262337a654mmmmm6d673d", | ||
"settled": 1, | ||
"settled_at": 1575992143 | ||
} | ||
``` | ||
""" | ||
return get_request('lntx/{}'.format(self.tx_id)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import pprint | ||
import requests | ||
import json | ||
|
||
|
||
def get_request(location): | ||
from .lnpay_main import __ENDPOINT_URL__, __PUBLIC_API_KEY__, __VERSION__ | ||
|
||
""" | ||
Network utility method for making a GET call to a LNPay endpoint | ||
Parameters | ||
---------- | ||
location (str): URL path requested | ||
Returns | ||
------- | ||
Network response as a JSON Object. | ||
""" | ||
endpoint = __ENDPOINT_URL__ + location | ||
headers = { | ||
"X-Api-Key": __PUBLIC_API_KEY__, | ||
"X-LNPay-sdk": __VERSION__, | ||
} | ||
|
||
r = requests.get(url=endpoint, headers=headers) | ||
return r.json() | ||
|
||
|
||
def post_request(location, params): | ||
from .lnpay_main import __ENDPOINT_URL__, __PUBLIC_API_KEY__, __VERSION__ | ||
|
||
""" | ||
Network utility method for making a POST call to a LNPay endpoint | ||
Parameters | ||
---------- | ||
location (str): URL path requested | ||
params (object): the `data` to be POSTed in the network request | ||
Returns | ||
------- | ||
Network response as a JSON Object. | ||
""" | ||
|
||
endpoint = __ENDPOINT_URL__ + location | ||
headers = { | ||
"Content-Type": "application/json", | ||
"X-Api-Key": __PUBLIC_API_KEY__, | ||
"X-LNPay-sdk": __VERSION__, | ||
} | ||
|
||
data = json.dumps(params) | ||
|
||
r = requests.post(url=endpoint, data=data, headers=headers) | ||
print("salam", r.text) | ||
return r.json() |
Oops, something went wrong.