"unit" optional on invoice creation, defaults to "sat"

This commit is contained in:
fiatjaf
2021-06-19 09:12:16 -03:00
parent 64c4b97ec9
commit f875dc7b63

View File

@@ -55,7 +55,7 @@ async def api_payments():
"required": True, "required": True,
"excludes": "description_hash", "excludes": "description_hash",
}, },
"unit": {"type": "string", "empty": False, "required": True}, "unit": {"type": "string", "empty": False, "required": False},
"description_hash": { "description_hash": {
"type": "string", "type": "string",
"empty": False, "empty": False,
@@ -76,18 +76,17 @@ async def api_payments_create_invoice():
description_hash = b"" description_hash = b""
memo = g.data["memo"] memo = g.data["memo"]
#convert fiat to satoshis if g.data.get("unit") or "sat" == "sat":
if g.data["unit"] != 'sat': amount = g.data["amount"]
print(g.data["amount"]) else:
price_in_sats = await fiat_amount_as_satoshis(g.data["amount"], g.data["unit"]) price_in_sats = await fiat_amount_as_satoshis(g.data["amount"], g.data["unit"])
g.data["amount"] = price_in_sats amount = price_in_sats
print(g.data["amount"], price_in_sats)
async with db.connect() as conn: async with db.connect() as conn:
try: try:
payment_hash, payment_request = await create_invoice( payment_hash, payment_request = await create_invoice(
wallet_id=g.wallet.id, wallet_id=g.wallet.id,
amount=g.data["amount"], amount=amount,
memo=memo, memo=memo,
description_hash=description_hash, description_hash=description_hash,
extra=g.data.get("extra"), extra=g.data.get("extra"),
@@ -445,6 +444,7 @@ async def api_perform_lnurlauth():
return jsonify({"reason": err.reason}), HTTPStatus.SERVICE_UNAVAILABLE return jsonify({"reason": err.reason}), HTTPStatus.SERVICE_UNAVAILABLE
return "", HTTPStatus.OK return "", HTTPStatus.OK
@core_app.route("/api/v1/currencies", methods=["GET"]) @core_app.route("/api/v1/currencies", methods=["GET"])
async def api_list_currencies_available(): async def api_list_currencies_available():
return jsonify(list(currencies.keys())) return jsonify(list(currencies.keys()))