Update views_api.py
This commit is contained in:
parent
768f0427e7
commit
e65c0a47bb
1 changed files with 51 additions and 28 deletions
|
|
@ -1,35 +1,58 @@
|
||||||
#views_api.py is for you API endpoints that could be hit by another service
|
from flask import g, jsonify, request
|
||||||
|
|
||||||
#add your dependencies here
|
from lnbits.core.crud import get_user
|
||||||
|
from lnbits.decorators import api_check_wallet_macaroon, api_validate_post_request
|
||||||
|
from lnbits.helpers import Status
|
||||||
|
|
||||||
import json
|
|
||||||
import requests
|
|
||||||
from flask import jsonify, render_template, request, redirect, url_for
|
|
||||||
from lnbits.db import open_db, open_ext_db
|
|
||||||
from lnbits.extensions.tpos import tpos_ext
|
from lnbits.extensions.tpos import tpos_ext
|
||||||
|
from .crud import create_tpos, get_tpos, get_tposs, delete_tpos
|
||||||
|
|
||||||
#add your endpoints here
|
|
||||||
|
|
||||||
@tpos_ext.route("/api/v1/fetch", methods=["GET","POST"])
|
@tpos_ext.route("/api/v1/tposs", methods=["GET"])
|
||||||
def api_tpos():
|
@api_check_wallet_macaroon(key_type="invoice")
|
||||||
"""Try to add descriptions for others."""
|
def api_tposs():
|
||||||
|
|
||||||
data = request.json
|
|
||||||
sats = data["sats"]
|
|
||||||
pos = data["pos"]
|
|
||||||
|
|
||||||
with open_ext_db("tpos") as events_ext_db:
|
wallet_ids = [g.wallet.id]
|
||||||
user_pos = events_ext_db.fetchall("SELECT * FROM tpos WHERE uni = ?", (pos,))
|
|
||||||
if not user_pos:
|
if "all_wallets" in request.args:
|
||||||
return jsonify({"status": "ERROR", "reason":"NO POS"}), 400
|
wallet_ids = get_user(g.wallet.user).wallet_ids
|
||||||
print(user_pos[0][4])
|
|
||||||
header = {"Content-Type": "application/json", "Grpc-Metadata-macaroon": user_pos[0][4]}
|
return jsonify([tpos._asdict() for tpos in get_tposs(wallet_ids)]), Status.OK
|
||||||
data = {"value": sats, "memo": "TPOS"}
|
|
||||||
print(url_for("api_invoices", _external=True))
|
|
||||||
r = requests.post(url=url_for("api_invoices", _external=True), headers=header, data=json.dumps(data))
|
@tpos_ext.route("/api/v1/tposs", methods=["POST"])
|
||||||
r_json = r.json()
|
@api_check_wallet_macaroon(key_type="invoice")
|
||||||
|
@api_validate_post_request(required_params=["name", "currency"])
|
||||||
if "ERROR" in r_json:
|
def api_tpos_create():
|
||||||
return jsonify({"status": "ERROR", "reason": r_json["ERROR"]}), 400
|
print("poo")
|
||||||
|
|
||||||
|
tpos = create_tpos(wallet_id=g.wallet.id, name=g.data["name"], currency=g.data["currency"])
|
||||||
|
|
||||||
|
return jsonify(tpos._asdict()), Status.CREATED
|
||||||
|
|
||||||
|
@tpos_ext.route("/api/v1/tposs/<tpos_id>", methods=["DELETE"])
|
||||||
|
@api_check_wallet_macaroon(key_type="invoice")
|
||||||
|
def api_tpos_delete(tpos_id):
|
||||||
|
tpos = get_tpos(tpos_id)
|
||||||
|
|
||||||
|
if not tpos:
|
||||||
|
return jsonify({"message": "TPoS does not exist."}), Status.NOT_FOUND
|
||||||
|
|
||||||
|
if tpos.wallet != g.wallet.id:
|
||||||
|
return jsonify({"message": "Not your tpos."}), Status.FORBIDDEN
|
||||||
|
|
||||||
|
delete_tpos(tpos_id)
|
||||||
|
|
||||||
|
return '', Status.NO_CONTENT
|
||||||
|
|
||||||
|
@tpos_ext.route("/api/v1/tposs/invoice/<tpos_id>", methods=["POST"])
|
||||||
|
@api_validate_post_request(required_params=["amount"])
|
||||||
|
def api_tpos_create_invoice(tpos_id):
|
||||||
|
r = get_tpos(tpos_id)
|
||||||
|
print(r)
|
||||||
|
rr = get_wallet(tpos_id.id)
|
||||||
|
print(rr)
|
||||||
|
# api_payments_create_invoice(memo=tpos_id.id, amount=amount, )
|
||||||
|
|
||||||
|
return jsonify(rr), Status.CREATED
|
||||||
|
|
||||||
return jsonify({"status": "TRUE","pay_req": r_json["pay_req"] ,"payment_hash": r_json["payment_hash"] }), 200
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue