some syntax refactoring

This commit is contained in:
Tiago vasconcelos 2021-08-22 12:16:31 +01:00
parent a9ab41701f
commit 3e0fd39175
7 changed files with 46 additions and 46 deletions

View File

@ -48,7 +48,7 @@ async def api_links():
)
@lnurlp_ext.get("/api/v1/links/<link_id>")
@lnurlp_ext.get("/api/v1/links/{link_id}")
@api_check_wallet_key("invoice")
async def api_link_retrieve(link_id):
link = await get_pay_link(link_id)
@ -65,14 +65,14 @@ class CreateData(BaseModel):
description: str
min: int = Query(0.01, ge=0.01)
max: int = Query(0.01, ge=0.01)
currency: Optional[str]
comment_chars: int = Query(0, ge=0, lt=800)
webhook_url: Optional[str]
success_text: Optional[str]
success_url: Optional[str]
currency: Optional[str]
comment_chars: int = Query(0, ge=0, lt=800)
webhook_url: Optional[str]
success_text: Optional[str]
success_url: Optional[str]
@lnurlp_ext.post("/api/v1/links")
@lnurlp_ext.put("/api/v1/links/<link_id>")
@lnurlp_ext.put("/api/v1/links/{link_id}")
@api_check_wallet_key("invoice")
async def api_link_create_or_update(data: CreateData, link_id=None):
if data.min > data.max:
@ -111,7 +111,7 @@ async def api_link_create_or_update(data: CreateData, link_id=None):
)
@lnurlp_ext.delete("/api/v1/links/<link_id>")
@lnurlp_ext.delete("/api/v1/links/{link_id}")
@api_check_wallet_key("invoice")
async def api_link_delete(link_id):
link = await get_pay_link(link_id)
@ -127,7 +127,7 @@ async def api_link_delete(link_id):
return "", HTTPStatus.NO_CONTENT
@lnurlp_ext.get("/api/v1/rate/<currency>")
@lnurlp_ext.get("/api/v1/rate/{currency}")
async def api_check_fiat_rate(currency):
try:
rate = await get_fiat_rate_satoshis(currency)

View File

@ -53,11 +53,11 @@ class CreateItemsData(BaseModel):
name: str
description: str
image: Optional[str]
price: int
unit: str
price: int
unit: str
@offlineshop_ext.post("/api/v1/offlineshop/items")
@offlineshop_ext.put("/api/v1/offlineshop/items/<item_id>")
@offlineshop_ext.put("/api/v1/offlineshop/items/{item_id}")
@api_check_wallet_key("invoice")
async def api_add_or_update_item(data: CreateItemsData, item_id=None):
shop = await get_or_create_shop_by_wallet(g.wallet.id)
@ -84,7 +84,7 @@ async def api_add_or_update_item(data: CreateItemsData, item_id=None):
return "", HTTPStatus.OK
@offlineshop_ext.delete("/api/v1/offlineshop/items/<item_id>")
@offlineshop_ext.delete("/api/v1/offlineshop/items/{item_id}")
@api_check_wallet_key("invoice")
async def api_delete_item(item_id):
shop = await get_or_create_shop_by_wallet(g.wallet.id)

View File

@ -29,8 +29,8 @@ class CreateData(BaseModel):
url: Optional[str] = Query(...)
memo: Optional[str] = Query(...)
description: str
amount: int
remembers: bool
amount: int
remembers: bool
@paywall_ext.post("/api/v1/paywalls")
@api_check_wallet_key("invoice")
@ -39,7 +39,7 @@ async def api_paywall_create(data: CreateData):
return paywall, HTTPStatus.CREATED
@paywall_ext.delete("/api/v1/paywalls/<paywall_id>")
@paywall_ext.delete("/api/v1/paywalls/{paywall_id}")
@api_check_wallet_key("invoice")
async def api_paywall_delete(paywall_id):
paywall = await get_paywall(paywall_id)
@ -55,7 +55,7 @@ async def api_paywall_delete(paywall_id):
return "", HTTPStatus.NO_CONTENT
@paywall_ext.post("/api/v1/paywalls/<paywall_id>/invoice")
@paywall_ext.post("/api/v1/paywalls/{paywall_id}/invoice")
async def api_paywall_create_invoice(amount: int = Query(..., ge=1), paywall_id = None):
paywall = await get_paywall(paywall_id)
@ -76,26 +76,26 @@ async def api_paywall_create_invoice(amount: int = Query(..., ge=1), paywall_id
extra={"tag": "paywall"},
)
except Exception as e:
return jsonable_encoder({"message": str(e)}), HTTPStatus.INTERNAL_SERVER_ERROR
return {"message": str(e)}, HTTPStatus.INTERNAL_SERVER_ERROR
return (
jsonable_encoder({"payment_hash": payment_hash, "payment_request": payment_request}),
{"payment_hash": payment_hash, "payment_request": payment_request},
HTTPStatus.CREATED,
)
@paywall_ext.post("/api/v1/paywalls/<paywall_id>/check_invoice")
@paywall_ext.post("/api/v1/paywalls/{paywall_id}/check_invoice")
async def api_paywal_check_invoice(payment_hash: str = Query(...), paywall_id = None):
paywall = await get_paywall(paywall_id)
if not paywall:
return jsonable_encoder({"message": "Paywall does not exist."}), HTTPStatus.NOT_FOUND
return {"message": "Paywall does not exist."}, HTTPStatus.NOT_FOUND
try:
status = await check_invoice_status(paywall.wallet, payment_hash)
is_paid = not status.pending
except Exception:
return jsonable_encoder({"paid": False}), HTTPStatus.OK
return {"paid": False}, HTTPStatus.OK
if is_paid:
wallet = await get_wallet(paywall.wallet)
@ -103,8 +103,8 @@ async def api_paywal_check_invoice(payment_hash: str = Query(...), paywall_id =
await payment.set_pending(False)
return (
jsonable_encoder({"paid": True, "url": paywall.url, "remembers": paywall.remembers}),
{"paid": True, "url": paywall.url, "remembers": paywall.remembers},
HTTPStatus.OK,
)
return jsonable_encoder({"paid": False}), HTTPStatus.OK
return {"paid": False}, HTTPStatus.OK

View File

@ -46,7 +46,7 @@ async def api_create_service(data: CreateServicesData):
return service._asdict(), HTTPStatus.CREATED
@streamalerts_ext.get("/api/v1/getaccess/<service_id>")
@streamalerts_ext.get("/api/v1/getaccess/{service_id}")
async def api_get_access(service_id):
"""Redirect to Streamlabs' Approve/Decline page for API access for Service
with service_id
@ -69,7 +69,7 @@ async def api_get_access(service_id):
return ({"message": "Service does not exist!"}, HTTPStatus.BAD_REQUEST)
@streamalerts_ext.get("/api/v1/authenticate/<service_id>")
@streamalerts_ext.get("/api/v1/authenticate/{service_id}")
async def api_authenticate_service(Code: str, State: str, service_id):
"""Endpoint visited via redirect during third party API authentication
@ -183,7 +183,7 @@ async def api_get_donations():
)
@streamalerts_ext.put("/api/v1/donations/<donation_id>")
@streamalerts_ext.put("/api/v1/donations/{donation_id}")
@api_check_wallet_key("invoice")
async def api_update_donation(donation_id=None):
"""Update a donation with the data given in the request"""
@ -208,7 +208,7 @@ async def api_update_donation(donation_id=None):
return donation._asdict(), HTTPStatus.CREATED
@streamalerts_ext.put("/api/v1/services/<service_id>")
@streamalerts_ext.put("/api/v1/services/{service_id}")
@api_check_wallet_key("invoice")
async def api_update_service(service_id=None):
"""Update a service with the data given in the request"""
@ -229,7 +229,7 @@ async def api_update_service(service_id=None):
return service._asdict(), HTTPStatus.CREATED
@streamalerts_ext.delete("/api/v1/donations/<donation_id>")
@streamalerts_ext.delete("/api/v1/donations/{donation_id}")
@api_check_wallet_key("invoice")
async def api_delete_donation(donation_id):
"""Delete the donation with the given donation_id"""
@ -245,7 +245,7 @@ async def api_delete_donation(donation_id):
return "", HTTPStatus.NO_CONTENT
@streamalerts_ext.delete("/api/v1/services/<service_id>")
@streamalerts_ext.delete("/api/v1/services/{service_id}")
@api_check_wallet_key("invoice")
async def api_delete_service(service_id):
"""Delete the service with the given service_id"""

View File

@ -51,7 +51,7 @@ class CreateDomainsData(BaseModel):
allowed_record_types: str
@subdomains_ext.post("/api/v1/domains")
@subdomains_ext.put("/api/v1/domains/<domain_id>")
@subdomains_ext.put("/api/v1/domains/{domain_id}")
@api_check_wallet_key("invoice")
async def api_domain_create(data: CreateDomainsData, domain_id=None):
if domain_id:
@ -66,10 +66,10 @@ async def api_domain_create(data: CreateDomainsData, domain_id=None):
domain = await update_domain(domain_id, **data)
else:
domain = await create_domain(**data)
return jsonify(domain._asdict()), HTTPStatus.CREATED
return domain._asdict(), HTTPStatus.CREATED
@subdomains_ext.delete("/api/v1/domains/<domain_id>")
@subdomains_ext.delete("/api/v1/domains/{domain_id}")
@api_check_wallet_key("invoice")
async def api_domain_delete(domain_id):
domain = await get_domain(domain_id)
@ -110,14 +110,14 @@ class CreateDomainsData(BaseModel):
duration: int
record_type: str
@subdomains_ext.post("/api/v1/subdomains/<domain_id>")
@subdomains_ext.post("/api/v1/subdomains/{domain_id}")
async def api_subdomain_make_subdomain(data: CreateDomainsData, domain_id):
domain = await get_domain(domain_id)
# If the request is coming for the non-existant domain
if not domain:
return jsonify({"message": "LNsubdomain does not exist."}), HTTPStatus.NOT_FOUND
return {"message": "LNsubdomain does not exist."}, HTTPStatus.NOT_FOUND
## If record_type is not one of the allowed ones reject the request
if data.record_type not in domain.allowed_record_types:
@ -184,7 +184,7 @@ async def api_subdomain_make_subdomain(data: CreateDomainsData, domain_id):
)
@subdomains_ext.get("/api/v1/subdomains/<payment_hash>")
@subdomains_ext.get("/api/v1/subdomains/{payment_hash}")
async def api_subdomain_send_subdomain(payment_hash):
subdomain = await get_subdomain(payment_hash)
try:
@ -199,7 +199,7 @@ async def api_subdomain_send_subdomain(payment_hash):
return {"paid": False}, HTTPStatus.OK
@subdomains_ext.delete("/api/v1/subdomains/<subdomain_id>")
@subdomains_ext.delete("/api/v1/subdomains/{subdomain_id}")
@api_check_wallet_key("invoice")
async def api_subdomain_delete(subdomain_id):
subdomain = await get_subdomain(subdomain_id)

View File

@ -37,7 +37,7 @@ async def api_wallets_retrieve():
return ""
@watchonly_ext.get("/api/v1/wallet/<wallet_id>")
@watchonly_ext.get("/api/v1/wallet/{wallet_id}")
@api_check_wallet_key("invoice")
async def api_wallet_retrieve(wallet_id):
wallet = await get_watch_wallet(wallet_id)
@ -63,7 +63,7 @@ async def api_wallet_create_or_update(masterPub: str, Title: str, wallet_id=None
return wallet._asdict(), HTTPStatus.CREATED
@watchonly_ext.delete("/api/v1/wallet/<wallet_id>")
@watchonly_ext.delete("/api/v1/wallet/{wallet_id}")
@api_check_wallet_key("admin")
async def api_wallet_delete(wallet_id):
wallet = await get_watch_wallet(wallet_id)
@ -79,7 +79,7 @@ async def api_wallet_delete(wallet_id):
#############################ADDRESSES##########################
@watchonly_ext.get("/api/v1/address/<wallet_id>")
@watchonly_ext.get("/api/v1/address/{wallet_id}")
@api_check_wallet_key("invoice")
async def api_fresh_address(wallet_id):
await get_fresh_address(wallet_id)
@ -89,7 +89,7 @@ async def api_fresh_address(wallet_id):
return [address._asdict() for address in addresses], HTTPStatus.OK
@watchonly_ext.get("/api/v1/addresses/<wallet_id>")
@watchonly_ext.get("/api/v1/addresses/{wallet_id}")
@api_check_wallet_key("invoice")
async def api_get_addresses(wallet_id):
wallet = await get_watch_wallet(wallet_id)

View File

@ -46,7 +46,7 @@ async def api_links():
)
@withdraw_ext.get("/api/v1/links/<link_id>")
@withdraw_ext.get("/api/v1/links/{link_id}")
@api_check_wallet_key("invoice")
async def api_link_retrieve(link_id):
link = await get_withdraw_link(link_id, 0)
@ -70,7 +70,7 @@ class CreateData(BaseModel):
is_unique: bool
@withdraw_ext.post("/api/v1/links")
@withdraw_ext.put("/api/v1/links/<link_id>")
@withdraw_ext.put("/api/v1/links/{link_id}")
@api_check_wallet_key("admin")
async def api_link_create_or_update(data: CreateData, link_id: str = None):
if data.max_withdrawable < data.min_withdrawable:
@ -97,7 +97,7 @@ async def api_link_create_or_update(data: CreateData, link_id: str = None):
HTTPStatus.NOT_FOUND,
)
if link.wallet != g.wallet.id:
return jsonify({"message": "Not your withdraw link."}), HTTPStatus.FORBIDDEN
return {"message": "Not your withdraw link."}, HTTPStatus.FORBIDDEN
link = await update_withdraw_link(link_id, **data, usescsv=usescsv, used=0)
else:
link = await create_withdraw_link(
@ -109,7 +109,7 @@ async def api_link_create_or_update(data: CreateData, link_id: str = None):
)
@withdraw_ext.delete("/api/v1/links/<link_id>")
@withdraw_ext.delete("/api/v1/links/{link_id}")
@api_check_wallet_key("admin")
async def api_link_delete(link_id):
link = await get_withdraw_link(link_id)
@ -127,7 +127,7 @@ async def api_link_delete(link_id):
return "", HTTPStatus.NO_CONTENT
@withdraw_ext.get("/api/v1/links/<the_hash>/<lnurl_id>")
@withdraw_ext.get("/api/v1/links/{the_hash}/{lnurl_id}")
@api_check_wallet_key("invoice")
async def api_hash_retrieve(the_hash, lnurl_id):
hashCheck = await get_hash_check(the_hash, lnurl_id)