From 2d48c3116c55e4372d1c0e8ea430ca5dd3c44b1d Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Wed, 5 Oct 2022 22:26:57 +0200 Subject: [PATCH 1/4] request fee from mint --- cashu/core/base.py | 6 +++++- cashu/core/helpers.py | 4 +++- cashu/lightning/lnbits.py | 2 ++ cashu/mint/ledger.py | 24 +++++++++++++++++------- cashu/mint/router.py | 8 ++++++++ cashu/wallet/cli.py | 8 +++++--- cashu/wallet/wallet.py | 9 ++++----- 7 files changed, 44 insertions(+), 17 deletions(-) diff --git a/cashu/core/base.py b/cashu/core/base.py index e30168b..0aa0244 100644 --- a/cashu/core/base.py +++ b/cashu/core/base.py @@ -153,10 +153,14 @@ class CheckRequest(BaseModel): proofs: List[Proof] -class CheckInternalRequest(BaseModel): +class CheckFeesRequest(BaseModel): pr: str +class CheckFeesResponse(BaseModel): + fee: Union[int, None] + + class MeltRequest(BaseModel): proofs: List[Proof] amount: int = None # deprecated diff --git a/cashu/core/helpers.py b/cashu/core/helpers.py index 0f8c885..cbc1dc5 100644 --- a/cashu/core/helpers.py +++ b/cashu/core/helpers.py @@ -28,8 +28,10 @@ def async_unwrap(to_await): return async_response[0] -def fee_reserve(amount_msat: int) -> int: +def fee_reserve(amount_msat: int, internal=False) -> int: """Function for calculating the Lightning fee reserve""" + if internal: + return 0 return max( int(LIGHTNING_RESERVE_FEE_MIN), int(amount_msat * LIGHTNING_FEE_PERCENT / 100.0) ) diff --git a/cashu/lightning/lnbits.py b/cashu/lightning/lnbits.py index ed655bf..97f8907 100644 --- a/cashu/lightning/lnbits.py +++ b/cashu/lightning/lnbits.py @@ -116,6 +116,8 @@ class LNbitsWallet(Wallet): ) except: return PaymentStatus(None) + if r.json().get("detail"): + return PaymentStatus(None) return PaymentStatus(r.json()["paid"]) async def get_payment_status(self, checking_id: str) -> PaymentStatus: diff --git a/cashu/mint/ledger.py b/cashu/mint/ledger.py index 97c621f..501eaa4 100644 --- a/cashu/mint/ledger.py +++ b/cashu/mint/ledger.py @@ -197,13 +197,13 @@ class Ledger: await update_lightning_invoice(payment_hash, issued=True, db=self.db) return status.paid - async def _pay_lightning_invoice(self, invoice: str, amount: int): + async def _pay_lightning_invoice(self, invoice: str, fees_msat: int): """Returns an invoice from the Lightning backend.""" error, _ = await WALLET.status() if error: raise Exception(f"Lightning wallet not responding: {error}") ok, checking_id, fee_msat, preimage, error_message = await WALLET.pay_invoice( - invoice, fee_limit_msat=fee_reserve(amount * 1000) + invoice, fee_limit_msat=fees_msat ) return ok, preimage @@ -258,16 +258,15 @@ class Ledger: if not all([self._verify_proof(p) for p in proofs]): raise Exception("could not verify proofs.") - total = sum([p["amount"] for p in proofs]) + total_provided = sum([p["amount"] for p in proofs]) invoice_obj = bolt11.decode(invoice) amount = math.ceil(invoice_obj.amount_msat / 1000) - - # check that lightning fees are included - assert total + fee_reserve(amount * 1000) >= amount, Exception( + fees_msat = await self.check_fees(invoice) + assert total_provided >= amount + fees_msat / 1000, Exception( "provided proofs not enough for Lightning payment." ) - status, preimage = await self._pay_lightning_invoice(invoice, amount) + status, preimage = await self._pay_lightning_invoice(invoice, fees_msat) if status == True: await self._invalidate_proofs(proofs) return status, preimage @@ -276,6 +275,17 @@ class Ledger: """Checks if all provided proofs are valid and still spendable (i.e. have not been spent).""" return {i: self._check_spendable(p) for i, p in enumerate(proofs)} + async def check_fees(self, pr: str): + """Returns the fees (in msat) required to pay this pr.""" + decoded_invoice = bolt11.decode(pr) + amount = math.ceil(decoded_invoice.amount_msat / 1000) + # hack: check if it's internal, if it exists, it will return paid = False, + # if id does not exist (not internal), it returns paid = None + paid = await WALLET.get_invoice_status(decoded_invoice.payment_hash) + internal = paid.paid == False + fees_msat = fee_reserve(amount * 1000, internal) + return fees_msat + async def split( self, proofs: List[Proof], amount: int, outputs: List[BlindedMessage] ): diff --git a/cashu/mint/router.py b/cashu/mint/router.py index 7a0378c..3888514 100644 --- a/cashu/mint/router.py +++ b/cashu/mint/router.py @@ -5,7 +5,9 @@ from secp256k1 import PublicKey from cashu.core.base import ( CashuError, + CheckFeesResponse, CheckRequest, + CheckFeesRequest, GetMeltResponse, GetMintResponse, MeltRequest, @@ -72,6 +74,12 @@ async def check_spendable(payload: CheckRequest): return await ledger.check_spendable(payload.proofs) +@router.post("/checkfees") +async def check_fees(payload: CheckFeesRequest): + fees_msat = await ledger.check_fees(payload.pr) + return CheckFeesResponse(fee=fees_msat / 1000) + + @router.post("/split") async def split(payload: SplitRequest): """ diff --git a/cashu/wallet/cli.py b/cashu/wallet/cli.py index f53eb78..39086ac 100755 --- a/cashu/wallet/cli.py +++ b/cashu/wallet/cli.py @@ -17,7 +17,7 @@ from loguru import logger import cashu.core.bolt11 as bolt11 from cashu.core.base import Proof -from cashu.core.bolt11 import Invoice +from cashu.core.bolt11 import Invoice, decode from cashu.core.helpers import fee_reserve from cashu.core.migrations import migrate_databases from cashu.core.settings import CASHU_DIR, DEBUG, ENV_FILE, LIGHTNING, MINT_URL, VERSION @@ -125,11 +125,13 @@ async def pay(ctx, invoice: str): wallet.load_mint() wallet.status() decoded_invoice: Invoice = bolt11.decode(invoice) + # check if it's an internal payment + fees = (await wallet.check_fees(invoice))["fee"] amount = math.ceil( - (decoded_invoice.amount_msat + fee_reserve(decoded_invoice.amount_msat)) / 1000 + (decoded_invoice.amount_msat + fees * 1000) / 1000 ) # 1% fee for Lightning print( - f"Paying Lightning invoice of {decoded_invoice.amount_msat // 1000} sat ({amount} sat incl. fees)" + f"Paying Lightning invoice of {decoded_invoice.amount_msat//1000} sat ({amount} sat incl. fees)" ) assert amount > 0, "amount is not positive" if wallet.available_balance < amount: diff --git a/cashu/wallet/wallet.py b/cashu/wallet/wallet.py index cfd6a3a..719ffee 100644 --- a/cashu/wallet/wallet.py +++ b/cashu/wallet/wallet.py @@ -11,7 +11,7 @@ import cashu.core.b_dhke as b_dhke from cashu.core.base import ( BlindedMessage, BlindedSignature, - CheckInternalRequest, + CheckFeesRequest, CheckRequest, MeltRequest, MintRequest, @@ -211,14 +211,13 @@ class LedgerAPI: return return_dict - async def check_internal(self, payment_request: str): + async def check_fees(self, payment_request: str): """Checks whether the Lightning payment is internal.""" - payload = CheckInternalRequest(pr=payment_request) + payload = CheckFeesRequest(pr=payment_request) return_dict = requests.post( - self.url + "/checkinternal", + self.url + "/checkfees", json=payload.dict(), ).json() - return return_dict async def pay_lightning(self, proofs: List[Proof], invoice: str): From c3ff644b22c9f1542107a25e3cb9b9908365c94f Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Wed, 5 Oct 2022 22:30:37 +0200 Subject: [PATCH 2/4] check fee via GET /checkfee --- docs/specs/cashu_client_spec.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/specs/cashu_client_spec.md b/docs/specs/cashu_client_spec.md index fc65024..24f6968 100644 --- a/docs/specs/cashu_client_spec.md +++ b/docs/specs/cashu_client_spec.md @@ -103,12 +103,13 @@ Here we describe how `Alice` checks with the mint whether the tokens she sent `C - If `` is `False`, `Alice` removes the proof [NOTE: consistent name?] from her list of spendable proofs. ## 6 - Pay a Lightning invoice -Here we describe how `Alice` can request from `Bob` to make a Lightning payment for her and burn an appropriate amount of tokens in return. `Alice` wants to pay a bolt11 invoice with the amount ``. She has to add a predefined fee to the request to account for the possible Lightning fees which results in a request with tokens with the total amount of ``. [NOTE: there is no way to do this dynamically as for now. We simply include a amount-dependent fee with the request and the mint essentially keeps the difference if it can find a cheaper-than-expected route. The mint refuses to pay the invoice if the fees included are not high-enough.] +Here we describe how `Alice` can request from `Bob` to make a Lightning payment for her and burn an appropriate amount of tokens in return. `Alice` wants to pay a bolt11 invoice with the amount ``. She has to add a fee to the request to account for the possible Lightning fees which results in a request with tokens with the total amount of ``. - `Alice` wants to pay the bolt11 invoice ``. -- `Alice` calculates the fees for the Lightning payments upfront with the function `max(, * *)` with `` currently being `4` Satoshis and `` being `0.01` (or 1% of ``). `Alice` then adds this fee to `` and rounds it up to the next higher integer which results in ``. -- `Alice` now performs the same set of instructions as in Step 3.1 and 3.2 and splits her spendable tokens into a set `` that she keeps and and a set `` that she can send for making the Lightning payment. -- `Alice` constructs the JSON `MeltRequest` of the form `{"proofs" : , "amount" : , "invoice" : }` [NOTE: Maybe use notation List[Proof] everywhere. Used MeltRequest here, maybe define each payload at the beginning of each section.] +- `Alice` asks `Bob` for the Lightning fee via `GET /checkfee` with the body being the json `{pr : }` +- `Alice` receives the `CheckFeeResponse` in the form of the json `{"fee" : }` resulting in ` = + `. +- `Alice` now performs the same set of instructions as in Step 3.1 and 3.2 and splits her spendable tokens into a set `` that she keeps and and a set `` with a sum of at least `` that she can send for making the Lightning payment. +- `Alice` constructs the JSON `MeltRequest` of the form `{"proofs" : , "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" : }` with `` being `True` if the payment was successful and `False` otherwise. - If ` == True`, `Alice` removes `` from her database of spendable tokens [NOTE: called it tokens again] From a042ee8327671707e440d6e25c85c3fad4be8ecd Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Wed, 5 Oct 2022 22:31:28 +0200 Subject: [PATCH 3/4] bump version and make format --- cashu/core/settings.py | 2 +- cashu/mint/router.py | 2 +- pyproject.toml | 2 +- setup.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cashu/core/settings.py b/cashu/core/settings.py index 377e88a..5a95fbf 100644 --- a/cashu/core/settings.py +++ b/cashu/core/settings.py @@ -46,4 +46,4 @@ LNBITS_ENDPOINT = env.str("LNBITS_ENDPOINT", default=None) LNBITS_KEY = env.str("LNBITS_KEY", default=None) MAX_ORDER = 64 -VERSION = "0.2.4" +VERSION = "0.2.5" diff --git a/cashu/mint/router.py b/cashu/mint/router.py index 3888514..fec009f 100644 --- a/cashu/mint/router.py +++ b/cashu/mint/router.py @@ -5,9 +5,9 @@ from secp256k1 import PublicKey from cashu.core.base import ( CashuError, + CheckFeesRequest, CheckFeesResponse, CheckRequest, - CheckFeesRequest, GetMeltResponse, GetMintResponse, MeltRequest, diff --git a/pyproject.toml b/pyproject.toml index c16d54e..e20d5f0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cashu" -version = "0.2.4" +version = "0.2.5" description = "Ecash wallet and mint." authors = ["calle "] license = "MIT" diff --git a/setup.py b/setup.py index 050b1d5..27918cc 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ entry_points = {"console_scripts": ["cashu = cashu.wallet.cli:cli"]} setuptools.setup( name="cashu", - version="0.2.4", + version="0.2.5", description="Ecash wallet and mint with Bitcoin Lightning support", long_description=long_description, long_description_content_type="text/markdown", From 008bfd06632886abed9b4b695b6f9b5913dbf347 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Wed, 5 Oct 2022 22:35:54 +0200 Subject: [PATCH 4/4] format --- docs/specs/cashu_client_spec.md | 34 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/specs/cashu_client_spec.md b/docs/specs/cashu_client_spec.md index 24f6968..d449804 100644 --- a/docs/specs/cashu_client_spec.md +++ b/docs/specs/cashu_client_spec.md @@ -39,11 +39,11 @@ Mint: `Bob` ### Step 2: Request tokens - To request tokens of value `amount : int`, `Alice` decomposes `amount` into a sum of values of `2^n`, e.g. `13` is `amounts : List[int] = [1, 4, 8]`. This can be easily done by representing `amount` as binary and using each binary digit that is `1` as part of the sum, e.g. `8` would be `1101` wich is `2^0 + 2^2 + 2^3`. In this example, `Alice` will request `N = len(amounts) = 3` tokens. -- `Alice` generates a random secret string `x_i` of `128` random bits with `i \in [0,..,N-1]`for each of the `N` requested tokens and encodes them in `base64`. [TODO: remove index i] +- `Alice` generates a random secret string `x_i` of `128` random bits with `i \in [0,..,N-1]`for each of the `N` requested tokens and encodes them in `base64`. [*TODO: remove index i*] - `Alice` remembers `x` for the construction of the proof in Step 5. ### Step 3: Generate blinded message -Here we see how `Alice` generates `N` blinded messages `T_i`. The following steps are executed for each of the `N` tokens that `Alice` requests. The index `i` is dropped for simplicity. [TODO: either write everything independent of i or not, don't mix] +Here we see how `Alice` generates `N` blinded messages `T_i`. The following steps are executed for each of the `N` tokens that `Alice` requests. The index `i` is dropped for simplicity. [*TODO: either write everything independent of i or not, don't mix*] - `Alice` generates a point `Y` on the elliptic curve from the secret `x` using the deterministic function `Y = hash_to_curve(hash(x : string)) : Point`. - `h = hash(x : string) : string` can be the `SHA256` hash function. - `Y = hash_to_curve(h : string) : Point` verifies that `Y` is an element of the elliptic curve. @@ -55,7 +55,7 @@ Here we see how `Alice` generates `N` blinded messages `T_i`. The following step - `Alice` constructs JSON `MintRequest = {"blinded_messages" : ["amount" : , "B_" : ] }` [NOTE: rename "blinded_messages", rename "B_", rename "MintRequest"] - `Alice` requests tokens via `POST /mint?payment_hash=` with body `MintRequest` [NOTE: rename MintRequest] - `Alice` receives from `Bob` a list of blinded signatures `List[BlindedSignature]`, one for each token, e.g. `[{"amount" : , "C_" : }, ...]` [NOTE: rename C_] -- If an error occured, `Alice` receives JSON `{"error" : }}`[TODO: Specify case of error] +- If an error occured, `Alice` receives JSON `{"error" : }}`[*TODO: Specify case of error*] ### Step 5: Construct proofs Here, `Alice` construct proofs for each token using the tuple `(blinded_signature, r, s)`. Again, all steps are repeated for each token separately but we show it here for only one token. @@ -67,13 +67,13 @@ Here we describe how `Alice` sends tokens to `Carol`. ### 3.1 – Split tokens to desired amount `Alice` wants to send tokens of total value `` to `Carol` but doesn't necessarily have a set of tokens that sum to ``. Say `Alice` has tokens of the amount `` which is greater than `` in here database. Note that `` does not need to include all of `Alice`'s tokens but only at least tokens of a total amount of ``. Therefore, `Alice` sends tokens of amount `` to `Bob` asks `Bob` to issue two new sets of tokens of value `` and `-` each. -- `Alice` performs a split on the amounts `` and `-` separately as in 2.2 - Request tokens. [TODO: fix reference] -- `Alice` constructs two new sets of blinded messages like in 2.3 - Generate blind messages [TODO: fix reference], one for each of the two amounts `` and `-`. -- `Alice` concatenates both sets of blinded messages into the list `` [TODO: list?] -- `Alice` constructs a JSON out of multiple tokens from her database that sum to `` of the form `{"amount" : , "proofs" : [{"amount" : , "secret" : s, "C" : Z}, ...], "outputs" : ["amount" : , "B_" : ]}`. The blinded messages in `"outputs"` are the list of concatenated blinded message from the previous step. [TODO: refer to this as BlindMessages or something and reuse in Section 4 and 2] +- `Alice` performs a split on the amounts `` and `-` separately as in 2.2 - Request tokens. [*TODO: fix reference*] +- `Alice` constructs two new sets of blinded messages like in 2.3 - Generate blind messages [*TODO: fix reference*], one for each of the two amounts `` and `-`. +- `Alice` concatenates both sets of blinded messages into the list `` [*TODO: list?*] +- `Alice` constructs a JSON out of multiple tokens from her database that sum to `` of the form `{"amount" : , "proofs" : [{"amount" : , "secret" : s, "C" : Z}, ...], "outputs" : ["amount" : , "B_" : ]}`. The blinded messages in `"outputs"` are the list of concatenated blinded message from the previous step. [*TODO: refer to this as BlindMessages or something and reuse in Section 4 and 2*] ### 3.2 - Request new tokens for sending -- `Alice` constructs a JSON out of multiple tokens of the form `[{"amount" : , "secret" : s, "C" : Z}, ...]` and serializes is as a Base64 string `TOKEN` which is then sent to `Carol` as a payment of value `sum()`. [NOTE: rename C, rewrite sum, find consistency in writing labels, values, TOKEN, in code this is called `Proof`] +- `Alice` constructs a JSON out of multiple tokens of the form `[{"amount" : , "secret" : s, "C" : Z}, ...]` and serializes is as a Base64 string `TOKEN` which is then sent to `Carol` as a payment of value `sum()`. [*NOTE: rename C, rewrite sum, find consistency in writing labels, values, TOKEN, in code this is called `Proof`*] - `Alice` requests new tokens via `POST /mint` with the JSON as the body of the request. - `Alice` receives a JSON of the form `{"fst" : }, "snd" : ` with both entries being of the type `List[BlindedSignature]`. `Alice` constructs proofs `` and `` from both of these entries like in Step 2.5 [TODO: fix reference]. - `Alice` stores the proofs `` and `` in her database and flags `` as `pending` (for example in a separate column). @@ -81,38 +81,38 @@ Here we describe how `Alice` sends tokens to `Carol`. ### 3.3 - Serialize tokens for sending Here, `Alice` serializes the proofs from the set `` for sending to `Carol`. -- `Alice` constructs a JSON of the form `[{"amount" : , "secret" : s, "C" : Z}, ...]` from `` and encodes it as a Base64 string using url-safe Base64 encoder. [NOTE: it probably doesn't need to be url-safe, maybe it shouldn't if this is not widespread or consistent across languages] +- `Alice` constructs a JSON of the form `[{"amount" : , "secret" : s, "C" : Z}, ...]` from `` and encodes it as a Base64 string using url-safe Base64 encoder. [*NOTE: it probably doesn't need to be url-safe, maybe it shouldn't if this is not widespread or consistent across languages*] - `Alice` sends the resulting `TOKEN` as the string `W3siYW1vdW50IjogMiwgInNlY3...` to `Carol`. ## 4 - Receive new tokens -Here we describe how `Carol` can redeem new tokens from `Bob` that she previously received from `Alice`. `Carol` receives tokens as a url-safe [NOTE: remove url-safe?] base64-encoded string `TOKEN` that, when decoded, is a JSON of the form `[{"amount" : , "secret" : s, "C" : Z}, ...]`. In the following, we will refer to the tuple `(, Z, s)` as a single token. [NOTE: clarify whether a TOKEN is a single token or a list of tokens] To redeem a token, `Carol` sends it to `Bob` and receives a one of the same value. +Here we describe how `Carol` can redeem new tokens from `Bob` that she previously received from `Alice`. `Carol` receives tokens as a url-safe [*NOTE: remove url-safe?*] base64-encoded string `TOKEN` that, when decoded, is a JSON of the form `[{"amount" : , "secret" : s, "C" : Z}, ...]`. In the following, we will refer to the tuple `(, Z, s)` as a single token. [*NOTE: clarify whether a TOKEN is a single token or a list of tokens*] To redeem a token, `Carol` sends it to `Bob` and receives a one of the same value. `Carol` essentially performs the same procedure to receive tokens as `Alice` did earlier when she prepared her tokens for sending: She sends constructs new blinded messages and sends them together with the tokens she received in order to receive a newly-issued set of tokens which settles the transaction between `Alice` and `Carol`. Note that the following steps can also be performed by `Alice` herself if she wants to cancel the pending token transfer and claim them for herself. -- `Carol` constructs a list of ``'s each with the same amount as the list list of tokens that she received. This can be done by the same procedure as during the minting of new tokens in Section 2 [TODO: update ref] or during sending in Section 3 [TODO: update ref] since the splitting into amounts is deterministic. -- `Carol` performs the same steps as `Alice` when she split the tokens before sending it to her and calls the endpoint `POIT /split` with the JSON `SplitRequests` as the body of the request [TODO: rename SplitRequests?] +- `Carol` constructs a list of ``'s each with the same amount as the list list of tokens that she received. This can be done by the same procedure as during the minting of new tokens in Section 2 [*TODO: update ref*] or during sending in Section 3 [*TODO: update ref*] since the splitting into amounts is deterministic. +- `Carol` performs the same steps as `Alice` when she split the tokens before sending it to her and calls the endpoint `POIT /split` with the JSON `SplitRequests` as the body of the request. ## 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 `` with `pending=True` from her database and might group them by the `send_id`. -- `Alice` constructs a JSON of the form `{"proofs" : [{"amount" : , "secret" : s, "C" : Z}, ...]}` from these (grouped) tokens. [TODO: this object is called CheckRequest] +- `Alice` constructs a JSON of the form `{"proofs" : [{"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" : , "2" : ...}` where `"1"` is the index of the proof she sent to the mint before and `` 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 `` is `False`, `Alice` removes the proof [NOTE: consistent name?] from her list of spendable proofs. +- If `` is `False`, `Alice` removes the proof [*NOTE: consistent name?*] from her list of spendable proofs. ## 6 - Pay a Lightning invoice Here we describe how `Alice` can request from `Bob` to make a Lightning payment for her and burn an appropriate amount of tokens in return. `Alice` wants to pay a bolt11 invoice with the amount ``. She has to add a fee to the request to account for the possible Lightning fees which results in a request with tokens with the total amount of ``. - `Alice` wants to pay the bolt11 invoice ``. -- `Alice` asks `Bob` for the Lightning fee via `GET /checkfee` with the body being the json `{pr : }` +- `Alice` asks `Bob` for the Lightning fee via `GET /checkfee` with the body `CheckFeeRequest` being the json `{pr : }` - `Alice` receives the `CheckFeeResponse` in the form of the json `{"fee" : }` resulting in ` = + `. - `Alice` now performs the same set of instructions as in Step 3.1 and 3.2 and splits her spendable tokens into a set `` that she keeps and and a set `` with a sum of at least `` that she can send for making the Lightning payment. -- `Alice` constructs the JSON `MeltRequest` of the form `{"proofs" : , "invoice" : }` [NOTE: Maybe use notation List[Proof] everywhere. Used MeltRequest here, maybe define each payload at the beginning of each section.] +- `Alice` constructs the JSON `MeltRequest` of the form `{"proofs" : , "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" : }` with `` being `True` if the payment was successful and `False` otherwise. -- If ` == True`, `Alice` removes `` from her database of spendable tokens [NOTE: called it tokens again] +- If ` == True`, `Alice` removes `` from her database of spendable tokens [*NOTE: called it tokens again*]