CheckPayload -> CheckRequest; MeltPayload -> MeltRequest

This commit is contained in:
callebtc
2022-10-05 19:02:19 +02:00
parent 8a5c87d20f
commit f1b95e2331
4 changed files with 11 additions and 11 deletions

View File

@@ -126,11 +126,11 @@ class SplitRequest(BaseModel):
self.output_data = None
class CheckPayload(BaseModel):
class CheckRequest(BaseModel):
proofs: List[Proof]
class MeltPayload(BaseModel):
class MeltRequest(BaseModel):
proofs: List[Proof]
amount: int
invoice: str

View File

@@ -3,7 +3,7 @@ from typing import Union
from fastapi import APIRouter
from secp256k1 import PublicKey
from cashu.core.base import CheckPayload, MeltPayload, MintPayloads, SplitRequest
from cashu.core.base import CheckRequest, MeltRequest, MintPayloads, SplitRequest
from cashu.mint import ledger
router: APIRouter = APIRouter()
@@ -55,7 +55,7 @@ async def mint(payloads: MintPayloads, payment_hash: Union[str, None] = None):
@router.post("/melt")
async def melt(payload: MeltPayload):
async def melt(payload: MeltRequest):
"""
Requests tokens to be destroyed and sent out via Lightning.
"""
@@ -64,7 +64,7 @@ async def melt(payload: MeltPayload):
@router.post("/check")
async def check_spendable(payload: CheckPayload):
async def check_spendable(payload: CheckRequest):
return await ledger.check_spendable(payload.proofs)

View File

@@ -11,8 +11,8 @@ import cashu.core.b_dhke as b_dhke
from cashu.core.base import (
BlindedMessage,
BlindedSignature,
CheckPayload,
MeltPayload,
CheckRequest,
MeltRequest,
MintPayloads,
P2SHScript,
Proof,
@@ -202,7 +202,7 @@ class LedgerAPI:
return fst_proofs, snd_proofs
async def check_spendable(self, proofs: List[Proof]):
payload = CheckPayload(proofs=proofs)
payload = CheckRequest(proofs=proofs)
return_dict = requests.post(
self.url + "/check",
json=payload.dict(),
@@ -211,7 +211,7 @@ class LedgerAPI:
return return_dict
async def pay_lightning(self, proofs: List[Proof], amount: int, invoice: str):
payload = MeltPayload(proofs=proofs, amount=amount, invoice=invoice)
payload = MeltRequest(proofs=proofs, amount=amount, invoice=invoice)
return_dict = requests.post(
self.url + "/melt",
json=payload.dict(),

View File

@@ -97,7 +97,7 @@ Note that the following steps can also be performed by `Alice` herself if she wa
## 5 - Burn sent tokens
Here we describe how `Alice` checks with the mint whether the tokens she sent `Carol` have been redeemed so she can safely delete them from her database. This step is optional but highly recommended so `Alice` can properly account for the tokens and adjust her balance accordingly.
- `Alice` loads all `<send_proofs>` with `pending=True` from her database and might group them by the `send_id`.
- `Alice` constructs a JSON of the form `{"proofs" : [{"amount" : <amount>, "secret" : s, "C" : Z}, ...]}` from these (grouped) tokens. [TODO: this object is called CheckPayload]
- `Alice` constructs a JSON of the form `{"proofs" : [{"amount" : <amount>, "secret" : s, "C" : Z}, ...]}` from these (grouped) tokens. [TODO: this object is called CheckRequest]
- `Alice` sends them to the mint `Bob` via the endpoint `POST /check` with the JSON as the body of the request.
- `Alice` receives a JSON of the form `{"1" : <spendable : bool>, "2" : ...}` where `"1"` is the index of the proof she sent to the mint before and `<spendable>` is a boolean that is `True` if the token has not been claimed yet by `Carol` and `False` if it has already been claimed.
- If `<spendable>` is `False`, `Alice` removes the proof [NOTE: consistent name?] from her list of spendable proofs.
@@ -108,7 +108,7 @@ Here we describe how `Alice` can request from `Bob` to make a Lightning payment
- `Alice` wants to pay the bolt11 invoice `<invoice>`.
- `Alice` calculates the fees for the Lightning payments upfront with the function `max(<MIN_FEE>, <invoice_amount> * <PROPORTIONAL_FEE>*)` with `<MIN_FEE>` currently being `4` Satoshis and `<PROPORTIONAL_FEE>` being `0.01` (or 1% of `<invoice_amount>`). `Alice` then adds this fee to `<invoice_amount>` and rounds it up to the next higher integer which results in `<amount>`.
- `Alice` now performs the same set of instructions as in Step 3.1 and 3.2 and splits her spendable tokens into a set `<keep_proofs>` that she keeps and and a set `<send_proofs>` that she can send for making the Lightning payment.
- `Alice` constructs the JSON `MeltPayload` of the form `{"proofs" : <List[Proof]>, "amount" : <total>, "invoice" : <invoice>}` [NOTE: Maybe use notation List[Proof] everywhere. Used MeltPayload here, maybe define each payload at the beginning of each section.]
- `Alice` constructs the JSON `MeltRequest` of the form `{"proofs" : <List[Proof]>, "amount" : <total>, "invoice" : <invoice>}` [NOTE: Maybe use notation List[Proof] everywhere. Used MeltRequest here, maybe define each payload at the beginning of each section.]
- `Alice` requests a payment from `Bob` via the endpoint `POST /melt` with the JSON as the body of the request.
- `Alice` receives a JSON of the form `{"paid" : <status:bool>}` with `<status>` being `True` if the payment was successful and `False` otherwise.
- If `<status> == True`, `Alice` removes `<send_proofs>` from her database of spendable tokens [NOTE: called it tokens again]