tsk 33c206a310 Swap saga (#1183)
# Implement Saga Pattern for Swap Operations with Recovery Mechanism

## Overview

This PR refactors the swap operation implementation to use the saga pattern - a distributed transaction pattern that provides reliable transaction management through explicit state tracking and compensation-based error handling. The implementation includes a robust recovery mechanism that automatically handles swap operations interrupted by crashes, power loss, or network failures.

## What Changed

**Saga Pattern Implementation:**
- Introduced a strict linear state machine for swaps: `Initial` → `SetupComplete` → `Signed` → `Completed`
- New modular `swap_saga` module with state validation, compensation logic, and saga orchestration
- Automatic rollback of database changes on failure, ensuring atomic swap operations
- Replaced previous swap implementation (`swap.rs`, `blinded_message_writer.rs`) with saga-based approach

**Recovery Mechanism:**
- Added `operation_id` and `operation_kind` columns to database schema for tracking which operation proofs belong to
- New `recover_from_bad_swaps()` method that runs on mint startup to handle incomplete swaps
- For proofs left in `PENDING` state from swap operations:
  - If blind signatures exist: marks proofs as `SPENT` (swap completed but not finalized)
  - If no blind signatures exist: removes proofs from database (swap failed partway through)
- Database migrations included for both PostgreSQL and SQLite
2025-10-22 08:30:33 -05:00
2025-10-22 08:30:33 -05:00
2025-09-09 13:26:03 +01:00
2023-10-22 18:36:52 +01:00
2025-03-24 11:13:22 +00:00
2025-07-26 09:51:28 -04:00
2025-09-27 23:51:24 +01:00
2025-10-09 16:20:06 +01:00
2025-09-23 15:05:16 +01:00
2024-04-10 20:49:35 +01:00
2025-10-02 13:14:58 +01:00
2025-08-31 12:00:04 +01:00
2025-10-12 23:16:52 +01:00
2024-04-15 15:36:15 +01:00
2025-10-08 12:47:52 +01:00
2025-07-08 11:09:20 +01:00
2024-11-10 12:54:09 +00:00
2024-06-29 11:55:19 +01:00

Warning

This project is in early development, it does however work with real sats! Always use amounts you don't mind losing.

crates.io Documentation License

Cashu Development Kit

CDK is a collection of rust crates for Cashu wallets and mints written in Rust.

ALPHA This library is in early development, the api will change and should be used with caution.

Project structure

The project is split up into several crates in the crates/ directory:

Development

For a guide to settings up a development environment see DEVELOPMENT.md

Implemented NUTs:

Mandatory

NUT # Description
00 Cryptography and Models
01 Mint public keys
02 Keysets and fees
03 Swapping tokens
04 Minting tokens
05 Melting tokens
06 Mint info

Optional

# Description Status
07 Token state check ✔️
08 Overpaid Lightning fees ✔️
09 Signature restore ✔️
10 Spending conditions ✔️
11 Pay-To-Pubkey (P2PK) ✔️
12 DLEQ proofs ✔️
13 Deterministic secrets ✔️
14 Hashed Timelock Contracts (HTLCs) ✔️
15 Partial multi-path payments (MPP) ✔️
16 Animated QR codes
17 WebSocket subscriptions ✔️
18 Payment Requests ✔️
19 Cached responses ✔️
20 Signature on Mint Quote ✔️
21 Clear Authentication ✔️
22 Blind Authentication ✔️
23 Payment Method: BOLT11 ✔️
25 Payment Method: BOLT12 ✔️

License

Code is under the MIT License

Contribution

All contributions are welcome.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed as above, without any additional terms or conditions.

Please see the development guide.

Description
No description provided
Readme MIT 8.4 MiB
Languages
Rust 97.1%
Shell 2.1%
Just 0.5%
Nix 0.2%