Skip to content

Commit

Permalink
fix: qol
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodylow committed Oct 9, 2024
1 parent 62823ea commit 1746851
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 60 deletions.
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
34 changes: 34 additions & 0 deletions curl.md
Original file line number Diff line number Diff line change
@@ -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
71 changes: 34 additions & 37 deletions fedimint-clientd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppState> {
let mint_router = Router::new()
.route("/decode-notes", post(mint::decode_notes::handle_rest))
Expand Down
1 change: 1 addition & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "justfile.local.just"
# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION

alias b := build
Expand Down
3 changes: 3 additions & 0 deletions justfile.local.just
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
21 changes: 21 additions & 0 deletions scripts/mutinynet-invoice.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Check if amount is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <amountMsat>"
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"

0 comments on commit 1746851

Please sign in to comment.