Commit Graph

1003 Commits

Author SHA1 Message Date
Cesar Rodas
2e63a631e4 Fixed clippy 2025-08-19 10:38:08 -03:00
C
e31a9b1905 Update crates/cdk/src/wallet/mint_connector/http_client.rs
Co-authored-by: thesimplekid <tsk@thesimplekid.com>
2025-08-19 10:38:08 -03:00
Cesar Rodas
29ce2e4f4d Http retry should only happen at Http Error (which are transport errors)
Fixes #939
2025-08-19 10:38:03 -03:00
thesimplekid
d3a3c30d99 feat(cdk): add Bolt12 mint quote subscription support (#976)
* feat(cdk): add Bolt12 mint quote subscription support

Extends subscription to handle Bolt12 payment method alongside existing Bolt11 support across wallet, mint, and CLI components.
2025-08-19 12:01:01 +01:00
C
28a01398fd Add PostgreSQL support for mint and wallet (#878)
* Add PostgreSQL support for mint and wallet

* Fixed bug to avoid empty calls `get_proofs_states`

* Fixed SQL bug

* Avoid redudant clone()

* Add more tests for the storage layer

* Minor enhacements

* Add a generic function to execute db operations

This function would log slow operations and log errors

* Provision a postgres db for tests

* Update deps for msrv

* Add postgres to pipeline

* feat: add psgl to example and docker

* feat: db url fmt

---------

Co-authored-by: thesimplekid <tsk@thesimplekid.com>
2025-08-18 17:45:11 +01:00
thesimplekid
2e424e629f feat: uuid version (#891)
* feat: uuid version

* feat: rustls version
2025-08-18 16:25:24 +01:00
thesimplekid
0a8a0a6ea5 Repay fake queue (#973)
* feat: implement secondary repayment queue for any-amount invoices

- Keep original immediate payment behavior for ALL invoices (fixed and any-amount)
- Add secondary repayment queue that randomly repays any-amount invoices again
- Secondary repayments occur at random intervals between 30 seconds and 3 minutes
- Only any-amount invoices (amount=0) are added to secondary repayment queue
- Each any-amount invoice gets paid twice: once immediately, once from secondary queue
- Queue has configurable max size with LRU eviction policy
- Add comprehensive tests and update documentation

* test: add test for multiple payment verification

- Add test to verify that secondary repayment system creates multiple payments
- Test checks that immediate payment is received first
- Demonstrates the dual payment system working correctly
2025-08-18 16:17:57 +01:00
thesimplekid
22926f8b21 fix: bolt12 ws on mint (#972)
* fix: bolt12 ws on mint

* fix: bolt12 ws on mint
2025-08-18 14:46:18 +01:00
C
f8d58e419f Merge pull request #963 from crodas/feature/wait-for-invoice
Add `wait_for_payment` function in the wallet
2025-08-18 12:57:45 +01:00
thesimplekid
5ef2be36f2 feat(cdk): allow minting less than paid amount for non-bolt11 payments
For bolt11 payments, enforce exact amount matching between outputs and quote.
For other payment methods, allow minting less than paid amount while preventing overspending.
2025-08-18 11:34:53 +01:00
thesimplekid
0e15904b2f Merge pull request #968 from thesimplekid/remove_unwrap_from_startup
fix: remove unwrap in startup check
2025-08-16 10:43:16 +01:00
thesimplekid
43a13878b1 fix: remove unwrap in startup check 2025-08-15 17:59:23 +01:00
thesimplekid
3104a999e9 Merge pull request #944 from vnprc/keyset_counter_atomic_increment_2
fix: implement atomic keyset counter
2025-08-15 15:43:29 +01:00
thesimplekid
b885c8d78e feat: fake mint bolt12 2025-08-15 12:23:02 +01:00
vnprc
5b30ca546d fix: implement atomic keyset counter
- remove get_keyset_counter
- update increment_keyset_counter to atomically increment and return counter value
- replace get+increment pattern with atomic increment everywhere
2025-08-15 11:50:33 +01:00
thesimplekid
51b26eae62 chore: clippy 2025-08-15 11:49:38 +01:00
gudnuf
325afd75f7 fix: allow paid and issued bolt12 quotes to settle internally 2025-08-13 19:14:43 -07:00
thesimplekid
8578e8532b Merge pull request #957 from thesimplekid/bump_msrv_1.85
feat: bump msrv from 1.75.0 to 1.85.0
2025-08-13 22:13:51 +01:00
thesimplekid
47c5bb7465 fix: fake mint multiple units 2025-08-13 13:59:32 +01:00
C
64f7b07855 Do not perform external calls during a database transaction. (#954)
The codebase was used to correctly perform signatory calls during a database
transaction, as the signatory was previously exclusively in process. However, a
few months ago, it was changed to be a trait that can be either local or
remote. Making external calls to services, adding latency, during an ongoing
database transaction is a bad idea because it will lock the rows until the
service call is finalized, which is unpredictable.

The issue is even worse in our pipeline where the SQLite storage driver is used
with the ":memory:" path, which forces the Database pool to have a size of 1.
Since our tests run in parallel, they would randomly fail.

This issue was failing in the CI, but the error was not making the pipeline
fail. This bug was fixed as well.
2025-08-13 12:25:59 +01:00
thesimplekid
ec9108d69d feat: bump msrv from 1.75.0 to 1.85.0 2025-08-13 10:56:09 +01:00
thesimplekid
12b707ac3d fix: sqlite drop melt request 2025-08-13 09:00:02 +01:00
thesimplekid
5d98fdf353 Keyset counter (#950)
* feat: refresh keysets

* fix(cdk): resolve keyset counter skipping index 0 in deterministic secret generation

- Modified Database::get_keyset_counter to return u32 instead of Option<u32>
- Added database migrations to increment existing keyset counters by 1
- Removed counter increment logic from wallet operations to use actual counter value
- Ensures deterministic secret generation starts from index 0 instead of skipping it
2025-08-13 08:54:45 +01:00
thesimplekid
69d0cf0818 Merge pull request #952 from thesimplekid/add_payment_method
fix: add payment method to quote
2025-08-13 08:38:04 +01:00
thesimplekid
e87d818137 chore: drop unused mint table melt_request 2025-08-12 13:21:33 +01:00
thesimplekid
12452680ac fix: add payment method to quote 2025-08-12 13:13:23 +01:00
C
7af054520e Add explicit rollback. (#947)
The proof_writer implicit rollback on Drop is too slow for our tests causing
race conditions with Postgres.

This commit enhances the rollback logic and makes it explicit
2025-08-11 23:54:37 +01:00
Cesar Rodas
937d9ac43b Introduce run_db_operation_sync and run_db_operation
These functions are designed as a single funnel to talk to the database,
whether it is synchronous or asynchronous.

This single funnel will log SQL queries and slow operations, providing a clear
and unified debug message for the problematic query, so it can be optimized
accordingly (for instance, missing indexes or unbound SQL requests).
2025-08-11 11:55:52 -03:00
Cesar Rodas
2e1099adbe Fixed bug to avoid empty calls get_proofs_states 2025-08-07 22:24:30 -03:00
lollerfirst
25e38701d8 update to spec 2025-08-06 17:01:52 +02:00
C
ad8f1ece5c Working on a better database abstraction (#931)
* Working on a better database abstraction

After [this question in the chat](https://matrix.to/#/!oJFtttFHGfnTGrIjvD:matrix.cashu.space/$oJFtttFHGfnTGrIjvD:matrix.cashu.space/$I5ZtjJtBM0ctltThDYpoCwClZFlM6PHzf8q2Rjqmso8)
regarding a database transaction within the same function, I realized a few
design flaws in our SQL database abstraction, particularly regarding
transactions.

1. Our upper abstraction got it right, where a transaction is bound with `&mut
   self`, so Rust knows how to handle its lifetime with' async/await'.
2. The raw database does not; instead, it returns &self, and beginning a
   transaction takes &self as well, which is problematic for Rust, but that's not
   all. It is fundamentally wrong. A transaction should take &mut self when
   beginning a transaction, as that connection is bound to a transaction and
   should not be returned to the pool. Currently, that responsibility lies with
   the implementor. If a mistake is made, a transaction could be executed in two
   or more connections.
3. The way a database is bound to our store layer is through a single struct,
   which may or may not internally utilize our connection pool. This is also
   another design flow, in this PR, a connection pool is owned, and to use a
   connection, it should be requested, and that connection is reference with
   mutable when beginning a transaction

* Improve the abstraction with fewer generics

As suggested by @thesimplekid

* Add BEGIN IMMEDIATE for SQLite
2025-08-06 07:58:03 +01:00
gudnuf
cceea654fe feat: enhance auth config (#922)
* feat: enhance auth config
2025-08-05 12:55:17 +01:00
thesimplekid
2bd97e4d80 Merge pull request #928 from lollerfirst/new-secret-derivation
New Secret Derivation
2025-08-04 10:08:21 -04:00
thesimplekid
9ed8536cd0 Merge pull request #934 from thesimplekid/doc_tests
chore: stop test from running
2025-08-03 12:51:55 -04:00
thesimplekid
9f9c96577f chore: stop test from running 2025-08-03 10:14:43 -04:00
lollerfirst
92eea181fd new secret derivation
Wallet holds `seed` instead of `xpriv`

fix doctest  errors

update examples

adjustments

fix doctests

fix all doctests

Update crates/cdk/src/wallet/multi_mint_wallet.rs

Co-authored-by: thesimplekid <tsk@thesimplekid.com>

fix

remove clone call
2025-08-02 19:36:20 +02:00
thesimplekid
3c4fce5c45 feat: add keyset u32 mapping migration (#926)
* feat: add keyset u32 mapping migration and duplicate handling

- Add new database migration (version 3) to include u32 representation for keysets
- Implement migration for both redb and SQL databases
- Add duplicate detection and handling for keyset entries
- Create unique index constraint for keyset_u32 column in SQL
- Update keyset storage to include u32 identifiers
- Handle backwards compatibility for existing databases

* chore: clippy

* refactor(cashu): simplify keyset ID verification logic

- Consolidate match expression into a single expression
- Use direct comparison with ensure_cdk macro
- Improve readability of keyset ID validation

* refactor(cdk): rename `fetch_keyset_keys` to `load_keyset_keys` for clarity

- Renamed `fetch_keyset_keys` to `load_keyset_keys` across multiple modules to better reflect its behavior of loading keys from local storage or fetching from mint when missing.
- Added debug logging to indicate when keys are being fetched from the mint.
- Simplified key loading logic in `update_mint_keysets` by removing redundant existence checks.

* chore: remove unused vec
2025-07-31 10:04:38 -04:00
thesimplekid
3a3cd88ee9 Mintd lib (#914)
* feat(cdk-integration-tests): refactor regtest setup and mintd integration

- Replace shell-based regtest setup with Rust binary (start_regtest_mints)
- Add cdk-mintd crate to workspace and integration tests
- Improve environment variable handling for test configurations
- Update integration tests to use proper temp directory management
- Remove deprecated start_regtest.rs binary
- Enhance CLN client connection with retry logic
- Simplify regtest shell script (itests.sh) to use new binary
- Fix tracing filters and improve error handling in setup
- Update dependencies and configurations for integration tests

fix: killing

chore: comment tests for ci debugging

chore: compile

Revert "chore: comment tests for ci debugging"

This reverts commit bfc594c11cf37caeaa6445cb854ae5567d2da6bd.

* chore: sql cipher

* fix: removal of sqlite cipher

* fix: auth password

* refactor(cdk-mintd): improve database password handling and function signatures

- Pass database password as parameter instead of parsing CLI args in setup_database
- Update function signatures for run_mintd and run_mintd_with_shutdown to accept db_password
- Remove direct CLI parsing from database setup logic
- Fix auth database initialization to use correct type when sqlcipher feature enabled
2025-07-31 00:43:43 -04:00
David Caseria
6ebcbba0c4 refactor: update send functionality across wallet components (#925)
* refactor: update send functionality across wallet components

---------
Co-authored-by: thesimplekid <tsk@thesimplekid.com>
2025-07-30 23:37:41 -04:00
thesimplekid
f663a6e41c Merge pull request #923 from thesimplekid/debug_20_auth
feat(cdk): enable NUT-20 support in mint builder configuration
2025-07-30 20:27:49 -04:00
thesimplekid
cb30b092a5 Merge pull request #920 from vnprc/payment_method_unit_tests
test: add PaymentMethod parsing and db read/write tests
2025-07-30 10:20:06 -04:00
thesimplekid
b5fc4a17c3 fix: include axum in swagger 2025-07-30 10:07:22 -04:00
thesimplekid
9a784fbacd feat(cdk): enable NUT-20 support in mint builder configuration 2025-07-30 09:21:01 -04:00
C
8e0c44248b Add NUT-19 support in the wallet (#912)
* Add NUT-19 support in the wallet
2025-07-29 21:45:30 -04:00
vnprc
714022fe14 test: add PaymentMethod parsing and db read/write tests 2025-07-29 21:41:45 -04:00
Cesar Rodas
ed7b64b71a Add missing migrations for wallet and auth db 2025-07-29 20:28:09 -03:00
Cesar Rodas
0041c135f7 Fix get_mint_quote_by_request_lookup_id
Fixes #916

The two functions (read and transaction) got out of sync
2025-07-29 11:31:29 -03:00
Cesar Rodas
659518f241 Improve migrations
Add the namespaced migrations and global migrations
2025-07-29 11:31:29 -03:00
C
99ced01e67 Apply suggestions from code review
Co-authored-by: thesimplekid <tsk@thesimplekid.com>
2025-07-29 11:31:29 -03:00
Cesar Rodas
fb4c470a9a Rename still_active to stale 2025-07-29 11:31:29 -03:00