From 1746851eae173185c3061b4602521fd0f83a7f16 Mon Sep 17 00:00:00 2001 From: "kody.low" Date: Wed, 9 Oct 2024 12:39:26 -0700 Subject: [PATCH] fix: qol --- README.md | 46 +++++++++++------------ curl.md | 34 +++++++++++++++++ fedimint-clientd/src/main.rs | 71 +++++++++++++++++------------------- justfile | 1 + justfile.local.just | 3 ++ scripts/mutinynet-invoice.sh | 21 +++++++++++ 6 files changed, 116 insertions(+), 60 deletions(-) create mode 100644 curl.md create mode 100755 scripts/mutinynet-invoice.sh diff --git a/README.md b/README.md index 5bf19b4..9545ca1 100644 --- a/README.md +++ b/README.md @@ -29,44 +29,44 @@ FEDIMINT_CLIENTD_INVITE_CODE="fed1-fedimint-invite-code" ## Fedimint Clientd Endpoints -`fedimint-clientd` supports the following endpoints (and has naive websocket support at `/fedimint/v2/ws`, see code for details until I improve the interface. PRs welcome!). All the endpoints are authed with a Bearer token from the password (from CLI or env). You can hit the endpoints as such with curl, or use the python/typescript/golang wrappers: +`fedimint-clientd` supports the following endpoints (and has naive websocket support at `/v2/ws`, see code for details until I improve the interface. PRs welcome!). All the endpoints are authed with a Bearer token from the password (from CLI or env). You can hit the endpoints as such with curl, or use the python/typescript/golang wrappers: ``` -curl http://localhost:3333/fedimint/v2/admin/info -H 'Authorization: Bearer some-secure-password-that-becomes-the-bearer-token' +curl http://localhost:3333/v2/admin/info -H 'Authorization: Bearer some-secure-password-that-becomes-the-bearer-token' ``` ### Admin related commands: -- `/fedimint/v2/admin/info`: Display wallet info (holdings, tiers). -- `/fedimint/v2/admin/backup`: Upload the (encrypted) snapshot of mint notes to federation. -- `/fedimint/v2/admin/discover-version`: Discover the common api version to use to communicate with the federation. -- `/fedimint/v2/admin/restore`: Restore the previously created backup of mint notes (with `backup` command). -- `/fedimint/v2/admin/list-operations`: List operations. -- `/fedimint/v2/admin/module`: Call a module subcommand. -- `/fedimint/v2/admin/config`: Returns the client config. +- `/v2/admin/info`: Display wallet info (holdings, tiers). +- `/v2/admin/backup`: Upload the (encrypted) snapshot of mint notes to federation. +- `/v2/admin/discover-version`: Discover the common api version to use to communicate with the federation. +- `/v2/admin/restore`: Restore the previously created backup of mint notes (with `backup` command). +- `/v2/admin/list-operations`: List operations. +- `/v2/admin/module`: Call a module subcommand. +- `/v2/admin/config`: Returns the client config. ### Mint related commands: -- `/fedimint/v2/mint/reissue`: Reissue notes received from a third party to avoid double spends. -- `/fedimint/v2/mint/spend`: Prepare notes to send to a third party as a payment. -- `/fedimint/v2/mint/validate`: Verifies the signatures of e-cash notes, but _not_ if they have been spent already. -- `/fedimint/v2/mint/split`: Splits a string containing multiple e-cash notes (e.g. from the `spend` command) into ones that contain exactly one. -- `/fedimint/v2/mint/combine`: Combines two or more serialized e-cash notes strings. +- `/v2/mint/reissue`: Reissue notes received from a third party to avoid double spends. +- `/v2/mint/spend`: Prepare notes to send to a third party as a payment. +- `/v2/mint/validate`: Verifies the signatures of e-cash notes, but _not_ if they have been spent already. +- `/v2/mint/split`: Splits a string containing multiple e-cash notes (e.g. from the `spend` command) into ones that contain exactly one. +- `/v2/mint/combine`: Combines two or more serialized e-cash notes strings. ### Lightning network related commands: -- `/fedimint/v2/ln/invoice`: Create a lightning invoice to receive payment via gateway. -- `/fedimint/v2/ln/await-invoice`: Wait for incoming invoice to be paid. -- `/fedimint/v2/ln/pay`: Pay a lightning invoice or lnurl via a gateway. -- `/fedimint/v2/ln/await-pay`: Wait for a lightning payment to complete. -- `/fedimint/v2/ln/list-gateways`: List registered gateways. -- `/fedimint/v2/ln/switch-gateway`: Switch active gateway. +- `/v2/ln/invoice`: Create a lightning invoice to receive payment via gateway. +- `/v2/ln/await-invoice`: Wait for incoming invoice to be paid. +- `/v2/ln/pay`: Pay a lightning invoice or lnurl via a gateway. +- `/v2/ln/await-pay`: Wait for a lightning payment to complete. +- `/v2/ln/list-gateways`: List registered gateways. +- `/v2/ln/switch-gateway`: Switch active gateway. ### Onchain related commands: -- `/fedimint/v2/onchain/deposit-address`: Generate a new deposit address, funds sent to it can later be claimed. -- `/fedimint/v2/onchain/await-deposit`: Wait for deposit on previously generated address. -- `/fedimint/v2/onchain/withdraw`: Withdraw funds from the federation. +- `/v2/onchain/deposit-address`: Generate a new deposit address, funds sent to it can later be claimed. +- `/v2/onchain/await-deposit`: Wait for deposit on previously generated address. +- `/v2/onchain/withdraw`: Withdraw funds from the federation. ### Extra endpoints: diff --git a/curl.md b/curl.md new file mode 100644 index 0000000..0880950 --- /dev/null +++ b/curl.md @@ -0,0 +1,34 @@ +# Fedimint Clientd Curl Examples + +## Admin + +Info: + +``` +curl http://localhost:3333/v2/admin/info -H "Authorization: Bearer password" | jq +``` + +List Connected Fedimints and their balances: + +``` +curl http://localhost:3333/v2/admin/info -H "Authorization: Bearer password" | jq 'to_entries | map({id: .key, name: .value.meta.federation_name, totalAmountMsat: .value.totalAmountMsat})' +``` + +## Mint + +## Lightning + +Get a gateway ID for a federation: + +``` +curl -v -X POST http://localhost:3333/v2/ln/list-gateways -H "Authorization: Bearer password" -H "Content-type: application/json" -d '{"federationId" : +"15db8cb4f1ec8e484d73b889372bec94812580f929e8148b7437d359af422cd3"}' +``` + +Create an invoice for a federation (using the gateway ID above): + +``` +curl -v -X POST http://localhost:3333/v2/ln/invoice -H "Authorization: Bearer password" -H "Content-Type: application/json" -d '{"amountMsat": 1000000, "description": "test", "gatewayId": "035f2f7912e0f570841d5c0d8976a40af0dcca5609198436f596e78d2c851ee58a", "federationId": "15db8cb4f1ec8e484d73b889372bec94812580f929e8148b7437d359af422cd3"}' +``` + +## Onchain diff --git a/fedimint-clientd/src/main.rs b/fedimint-clientd/src/main.rs index 2dab478..f405738 100644 --- a/fedimint-clientd/src/main.rs +++ b/fedimint-clientd/src/main.rs @@ -222,49 +222,46 @@ async fn track_metrics(req: Request, next: Next) -> impl IntoResponse { } /// Implements Fedimint V0.2 API Route matching against CLI commands: -/// - `/fedimint/v2/admin/backup`: Upload the (encrypted) snapshot of mint notes -/// to federation. -/// - `/fedimint/v2/admin/discover-version`: Discover the common api version to -/// use to communicate with the federation. -/// - `/fedimint/v2/admin/info`: Display wallet info (holdings, tiers). -/// - `/fedimint/v2/admin/join`: Join a federation with an invite code. -/// - `/fedimint/v2/admin/restore`: Restore the previously created backup of -/// mint notes (with `backup` command). -/// - `/fedimint/v2/admin/list-operations`: List operations. -/// - `/fedimint/v2/admin/module`: Call a module subcommand. -/// - `/fedimint/v2/admin/config`: Returns the client config. +/// - `/v2/admin/backup`: Upload the (encrypted) snapshot of mint notes to +/// federation. +/// - `/v2/admin/discover-version`: Discover the common api version to use to +/// communicate with the federation. +/// - `/v2/admin/info`: Display wallet info (holdings, tiers). +/// - `/v2/admin/join`: Join a federation with an invite code. +/// - `/v2/admin/restore`: Restore the previously created backup of mint notes +/// (with `backup` command). +/// - `/v2/admin/list-operations`: List operations. +/// - `/v2/admin/module`: Call a module subcommand. +/// - `/v2/admin/config`: Returns the client config. /// /// Mint related commands: -/// - `/fedimint/v2/mint/reissue`: Reissue notes received from a third party to -/// avoid double spends. -/// - `/fedimint/v2/mint/spend`: Prepare notes to send to a third party as a -/// payment. -/// - `/fedimint/v2/mint/validate`: Verifies the signatures of e-cash notes, but -/// *not* if they have been spent already. -/// - `/fedimint/v2/mint/split`: Splits a string containing multiple e-cash -/// notes (e.g. from the `spend` command) into ones that contain exactly one. -/// - `/fedimint/v2/mint/combine`: Combines two or more serialized e-cash notes -/// strings. +/// - `/v2/mint/reissue`: Reissue notes received from a third party to avoid +/// double spends. +/// - `/v2/mint/spend`: Prepare notes to send to a third party as a payment. +/// - `/v2/mint/validate`: Verifies the signatures of e-cash notes, but *not* if +/// they have been spent already. +/// - `/v2/mint/split`: Splits a string containing multiple e-cash notes (e.g. +/// from the `spend` command) into ones that contain exactly one. +/// - `/v2/mint/combine`: Combines two or more serialized e-cash notes strings. /// /// Lightning network related commands: -/// - `/fedimint/v2/ln/invoice`: Create a lightning invoice to receive payment -/// via gateway. -/// - `/fedimint/v2/ln/invoice-external-pubkey-tweaked`: Create a lightning -/// invoice to receive payment via gateway with external pubkey. -/// - `/fedimint/v2/ln/await-invoice`: Wait for incoming invoice to be paid. -/// - `/fedimint/v2/ln/claim-external-receive-tweaked`: Claim an external -/// receive. -/// - `/fedimint/v2/ln/pay`: Pay a lightning invoice or lnurl via a gateway. -/// - `/fedimint/v2/ln/await-pay`: Wait for a lightning payment to complete. -/// - `/fedimint/v2/ln/list-gateways`: List registered gateways. -/// - `/fedimint/v2/ln/switch-gateway`: Switch active gateway. +/// - `/v2/ln/invoice`: Create a lightning invoice to receive payment via +/// gateway. +/// - `/v2/ln/invoice-external-pubkey-tweaked`: Create a lightning invoice to +/// receive payment via gateway with external pubkey. +/// - `/v2/ln/await-invoice`: Wait for incoming invoice to be paid. +/// - `/v2/ln/claim-external-receive-tweaked`: Claim an external receive. +/// - `/v2/ln/pay`: Pay a lightning invoice or lnurl via a gateway. +/// - `/v2/ln/await-pay`: Wait for a lightning payment to complete. +/// - `/v2/ln/list-gateways`: List registered gateways. +/// - `/v2/ln/switch-gateway`: Switch active gateway. /// /// Onchain related commands: -/// - `/fedimint/v2/onchain/deposit-address`: Generate a new deposit address, -/// funds sent to it can later be claimed. -/// - `/fedimint/v2/onchain/await-deposit`: Wait for deposit on previously -/// generated address. -/// - `/fedimint/v2/onchain/withdraw`: Withdraw funds from the federation. +/// - `/v2/onchain/deposit-address`: Generate a new deposit address, funds sent +/// to it can later be claimed. +/// - `/v2/onchain/await-deposit`: Wait for deposit on previously generated +/// address. +/// - `/v2/onchain/withdraw`: Withdraw funds from the federation. fn fedimint_v2_rest() -> Router { let mint_router = Router::new() .route("/decode-notes", post(mint::decode_notes::handle_rest)) diff --git a/justfile b/justfile index b04cd88..829df54 100644 --- a/justfile +++ b/justfile @@ -1,3 +1,4 @@ +import "justfile.local.just" # THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION alias b := build diff --git a/justfile.local.just b/justfile.local.just index eda0478..662af8e 100644 --- a/justfile.local.just +++ b/justfile.local.just @@ -29,3 +29,6 @@ wscat: publish: cargo publish -p multimint && cargo publish -p fedimint-clientd && cargo publish -p clientd-stateless + +test-invoice amountMsat: + ./scripts/mutinynet-invoice.sh {{amountMsat}} diff --git a/scripts/mutinynet-invoice.sh b/scripts/mutinynet-invoice.sh new file mode 100755 index 0000000..15e4e60 --- /dev/null +++ b/scripts/mutinynet-invoice.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Check if amount is provided +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +AMOUNT_MSAT=$1 +FEDERATION_ID="15db8cb4f1ec8e484d73b889372bec94812580f929e8148b7437d359af422cd3" +GATEWAY_ID="035f2f7912e0f570841d5c0d8976a40af0dcca5609198436f596e78d2c851ee58a" + +# Create an invoice and capture the response +INVOICE_RESPONSE=$(curl -s -X POST http://localhost:3333/v2/ln/invoice \ + -H "Authorization: Bearer password" \ + -H "Content-Type: application/json" \ + -d "{\"amountMsat\": $AMOUNT_MSAT, \"description\": \"Invoice for amount $AMOUNT_MSAT msat\", \"gatewayId\": \"$GATEWAY_ID\", \"federationId\": \"$FEDERATION_ID\"}") + +# Extract and print just the invoice from the response +INVOICE=$(echo "$INVOICE_RESPONSE" | jq -r '.invoice') +echo "$INVOICE"