Added countedown

This commit is contained in:
Ben Arc
2021-04-01 02:31:35 +01:00
parent 0db516b6e0
commit 6f42413107
4 changed files with 77 additions and 113 deletions
+15 -62
View File
@@ -13,75 +13,28 @@ from .crud import (
get_charge,
get_charges,
delete_charge,
check_address_balance,
)
###################WALLETS#############################
@satspay_ext.route("/api/v1/wallet", methods=["GET"])
@api_check_wallet_key("invoice")
async def api_wallets_retrieve():
try:
return (
jsonify([wallet._asdict() for wallet in await get_watch_wallets(g.wallet.user)]), HTTPStatus.OK
)
except:
return ""
@satspay_ext.route("/api/v1/wallet/<wallet_id>", methods=["GET"])
@api_check_wallet_key("invoice")
async def api_wallet_retrieve(wallet_id):
wallet = await get_watch_wallet(wallet_id)
if not wallet:
return jsonify({"message": "wallet does not exist"}), HTTPStatus.NOT_FOUND
return jsonify({wallet}), HTTPStatus.OK
@satspay_ext.route("/api/v1/wallet", methods=["POST"])
@satspay_ext.route("/api/v1/wallet/<wallet_id>", methods=["PUT"])
@api_check_wallet_key("invoice")
@api_validate_post_request(
schema={
"masterpub": {"type": "string", "empty": False, "required": True},
"title": {"type": "string", "empty": False, "required": True},
}
)
async def api_wallet_create_or_update(wallet_id=None):
print("g.data")
if not wallet_id:
wallet = await create_watch_wallet(user=g.wallet.user, masterpub=g.data["masterpub"], title=g.data["title"])
mempool = await get_mempool(g.wallet.user)
if not mempool:
create_mempool(user=g.wallet.user)
return jsonify(wallet._asdict()), HTTPStatus.CREATED
else:
wallet = await update_watch_wallet(wallet_id=wallet_id, **g.data)
return jsonify(wallet._asdict()), HTTPStatus.OK
@satspay_ext.route("/api/v1/wallet/<wallet_id>", methods=["DELETE"])
@api_check_wallet_key("invoice")
async def api_wallet_delete(wallet_id):
wallet = await get_watch_wallet(wallet_id)
if not wallet:
return jsonify({"message": "Wallet link does not exist."}), HTTPStatus.NOT_FOUND
await delete_watch_wallet(wallet_id)
return jsonify({"deleted": "true"}), HTTPStatus.NO_CONTENT
#############################CHARGES##########################
@satspay_ext.route("/api/v1/charges/balance/<charge_id>", methods=["GET"])
@api_check_wallet_key("invoice")
async def api_charges_balance(charge_id):
charge = await check_address_balance(charge_id)
if not charge:
return (
jsonify(""),
HTTPStatus.OK
)
else:
return jsonify(charge._asdict()), HTTPStatus.OK
@satspay_ext.route("/api/v1/charges", methods=["GET"])
@api_check_wallet_key("invoice")
async def api_charges_retrieve():
charges = await get_charges(g.wallet.user)
print(charges)
if not charges:
return (
jsonify(""),
@@ -107,8 +60,8 @@ async def api_charge_retrieve(charge_id):
@api_check_wallet_key("invoice")
@api_validate_post_request(
schema={
"onchainwallet": {"type": "string", "empty": False, "required": True},
"lnbitswallet": {"type": "string", "empty": False, "required": True},
"onchainwallet": {"type": "string"},
"lnbitswallet": {"type": "string"},
"description": {"type": "string", "empty": False, "required": True},
"webhook": {"type": "string", "empty": False, "required": True},
"time": {"type": "integer", "min": 1, "required": True},