Skip to content

feat: batch minting#878

Open
a1denvalu3 wants to merge 12 commits intomainfrom
feat/nut-20-batch-mint
Open

feat: batch minting#878
a1denvalu3 wants to merge 12 commits intomainfrom
feat/nut-20-batch-mint

Conversation

@a1denvalu3
Copy link
Collaborator

Summary

Implemented NUT-XX Batch Minting specification.

This PR adds support for:

  • POST /v1/mint/quote/{method}/check: Batch checking of quote states.
  • POST /v1/mint/{method}/batch: Atomic batch minting of multiple quotes.
  • NUT-20 signature verification for batched quotes.

The implementation ensures that all quotes in a batch are processed atomically. If any verification fails or any quote cannot be minted, the entire batch is rejected.

@github-project-automation github-project-automation bot moved this to Backlog in nutshell Jan 26, 2026
@a1denvalu3 a1denvalu3 marked this pull request as draft January 26, 2026 16:35
@a1denvalu3 a1denvalu3 force-pushed the feat/nut-20-batch-mint branch 2 times, most recently from 580e2a9 to 7e34ab2 Compare January 26, 2026 22:25
@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 66.29834% with 61 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.71%. Comparing base (8748b99) to head (cdc8485).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
cashu/mint/ledger.py 67.07% 27 Missing ⚠️
cashu/mint/router.py 0.00% 17 Missing ⚠️
cashu/mint/features.py 11.11% 8 Missing ⚠️
cashu/core/errors.py 50.00% 4 Missing ⚠️
cashu/mint/db/write.py 91.66% 3 Missing ⚠️
cashu/mint/crud.py 88.88% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #878       +/-   ##
===========================================
+ Coverage   50.02%   65.71%   +15.68%     
===========================================
  Files          89       92        +3     
  Lines       10545    11123      +578     
===========================================
+ Hits         5275     7309     +2034     
+ Misses       5270     3814     -1456     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@a1denvalu3 a1denvalu3 changed the title Batch Minting feat: batch minting Jan 27, 2026
@a1denvalu3 a1denvalu3 force-pushed the feat/nut-20-batch-mint branch from 01ea43f to 983aa3f Compare February 1, 2026 20:20
@a1denvalu3 a1denvalu3 marked this pull request as ready for review February 4, 2026 10:35
CLEAR_AUTH_NUT = 21
BLIND_AUTH_NUT = 22
METHOD_BOLT11_NUT = 23
BATCH_NUT = 333
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm guessing this '333' is a placeholder as the nut says 'xx'... can we document that this is a placeholder so i remember to come back and update it ?

@KvngMikey
Copy link
Contributor

just the little doc update to clarify on otherwise LGTM.

- Add BATCH_NUT (333) constant
- Update LedgerFeatures to advertise batch support
- Add PostMintQuoteCheckRequest, PostMintBatchRequest, PostMintBatchResponse models
- Implement batch DB operations in LedgerCrud and DbWriteHelper
- Implement check_mint_quotes and mint_batch in Ledger with atomic transaction support
- Add /v1/mint/quote/{method}/check and /v1/mint/{method}/batch endpoints
- Add comprehensive tests in tests/mint/test_mint_batch.py
- Add tests for get_mint_quotes
- Add tests for update_mint_quotes_state
- Add tests for _set_mint_quotes_pending (success/failure)
- Add tests for _unset_mint_quotes_pending (success/failure)
- Add QuoteNotFoundError (code 20010) for unknown quotes
- Implement all-or-nothing error handling in check_mint_quotes
- Preserve quote order with ORDER BY CASE in get_mint_quotes
- Add mint_max_batch_size setting for operator configuration
- Add max batch size validation in both check and mint endpoints
- Use settings.mint_max_batch_size in mint info instead of hardcoded 100
@a1denvalu3 a1denvalu3 force-pushed the feat/nut-20-batch-mint branch from cf3cba0 to 1a51605 Compare February 16, 2026 13:59
The ORDER BY CASE with parameters doesn't work properly with PostgreSQL.
Now we fetch quotes and sort them in Python to preserve request order.
Per NUT-333 spec, the order of quotes in the request MUST be preserved in the response.
- Add supports_batch_mint() and get_max_batch_size() to MintInfo
- Add check_mint_quotes() and mint_batch() to V1API
- Add Wallet.check_mint_quotes() and Wallet.mint_batch() wrappers
- Update NpubCash.mint_quotes() to use batch when mint supports it
- Add fallback to sequential minting if batch fails
- Add tests for MintInfo.supports_batch_mint() and get_max_batch_size()
- Add tests for NpubCash batch vs sequential mint selection
- Add test for sequential fallback on batch failure
- Move MintInfo batch tests to test_mint_batch.py
- Move wallet batch tests to test_mint_batch.py
- Delete separate test files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants