/ docs / lifecycle.md
lifecycle.md
 1  # What is a transaction
 2  
 3  - A [`Transaction`](https://github.com/fedimint/fedimint/blob/a1f57e3c6ff860a9c4a998bf88ebad73ebdb67c9/fedimint-core/src/transaction.rs#L12) Consists of inputs and outputs
 4    - Each input and output belongs to a certain module (e.g. Mint, Wallet, …)
 5    - All inputs have to add up to the same sum as all outputs
 6  - Also contains a signature
 7    - Each input has an associated secret/public key pair
 8    - The signature is a MuSig2 multi signature with all these input keys signing the entire transaction
 9  
10  ```rust
11  pub struct Transaction {
12      pub inputs: Vec<Input>,
13      pub outputs: Vec<Output>,
14      pub signature: Option<schnorr::Signature>,
15  }
1617  pub enum Input {
18      Mint(<fedimint_mint::Mint as FederationModule>::TxInput),
19      Wallet(<fedimint_wallet::Wallet as FederationModule>::TxInput),
20      LN(<fedimint_ln::LightningModule as FederationModule>::TxInput),
21  }
22  ```
23  
24  # Transaction Creation
25  
26  - One client module for each federation module
27  - There are specialized user and gateway clients that use these to construct transactions
28  - [E.g. deposit](https://github.com/fedimint/fedimint/blob/a1f57e3c6ff860a9c4a998bf88ebad73ebdb67c9/client/client-lib/src/lib.rs#L190)
29  
30  # Transaction processing
31  
32  - [Submit transaction](https://github.com/fedimint/fedimint/blob/a1f57e3c6ff860a9c4a998bf88ebad73ebdb67c9/fedimint/src/consensus/mod.rs#L105), first validation
33  - [Save to DB](https://github.com/fedimint/fedimint/blob/a1f57e3c6ff860a9c4a998bf88ebad73ebdb67c9/fedimint/src/consensus/mod.rs#L115)
34  - [Generate consensus proposal](https://github.com/fedimint/fedimint/blob/a1f57e3c6ff860a9c4a998bf88ebad73ebdb67c9/fedimint/src/consensus/mod.rs#L386) with all transactions submitted in the meantime
35  - [Propose to AlephBFT](https://github.com/fedimint/fedimint/blob/a1f57e3c6ff860a9c4a998bf88ebad73ebdb67c9/fedimint/src/lib.rs#L132)
36  - [Process all transactions that were agreed on](https://github.com/fedimint/fedimint/blob/a1f57e3c6ff860a9c4a998bf88ebad73ebdb67c9/fedimint/src/consensus/mod.rs#L436)
37  - [Each input](https://github.com/fedimint/fedimint/blob/a1f57e3c6ff860a9c4a998bf88ebad73ebdb67c9/fedimint/src/consensus/mod.rs#L447) and output are processed by its respective module, e.g. for the [Mint module](https://github.com/fedimint/fedimint/blob/a1f57e3c6ff860a9c4a998bf88ebad73ebdb67c9/modules/fedimint-mint/src/lib.rs#L194)
38  - Some operations need a second round to submit signature shares, they are submitted via [per-module consensus items](https://github.com/fedimint/fedimint/blob/a1f57e3c6ff860a9c4a998bf88ebad73ebdb67c9/fedimint-api/src/module/mod.rs#L141) (see also [Generate consensus proposal](https://github.com/fedimint/fedimint/blob/a1f57e3c6ff860a9c4a998bf88ebad73ebdb67c9/fedimint/src/consensus/mod.rs#L386))
39  - These are also [processed by their respective module](https://github.com/fedimint/fedimint/blob/a1f57e3c6ff860a9c4a998bf88ebad73ebdb67c9/modules/fedimint-mint/src/lib.rs#L119)
40  
41  # Modules
42  
43  - [For more details, look at the docs, they are great (at least for modules)!](https://github.com/fedimint/fedimint/blob/a1f57e3c6ff860a9c4a998bf88ebad73ebdb67c9/fedimint-api/src/module/mod.rs#L129)