Skip to content

Commit 26637eb

Browse files
committed
docs: fixed all markdown linter errors in docs file
1 parent fa03943 commit 26637eb

7 files changed

Lines changed: 87 additions & 11 deletions

docs/CODING_STANDARDS.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,83 @@ This document outlines the coding standards and best practices for the Mostro CL
55
## Core Principles
66

77
### 1. Readability and Reuse
8+
89
**Priority**: Code should be written for humans first, machines second.
10+
911
- **Clear naming**: Use descriptive names for functions, variables, and modules (e.g., `parse_dm_events` vs `pde`).
1012
- **Function reuse**: Extract common logic into reusable functions. Place shared utilities in appropriate modules (`src/util/`, `src/parser/`, etc.).
1113
- **Module organization**: Group related functionality together (CLI commands in `src/cli/`, Protocol parsing in `src/parser/`, Utilities in `src/util/`).
1214

1315
### 2. Avoid Code Duplication (DRY Principle)
16+
1417
**Don't Repeat Yourself**: If the same logic appears in multiple places, extract it.
18+
1519
- **Extract common patterns**: Create helper functions for repeated operations like DM sending.
1620
- **Centralize constants**: Import from `mostro-core::prelude` instead of hardcoding values.
1721

1822
### 3. Simplicity
23+
1924
**Keep It Simple**: Prefer straightforward solutions over clever ones.
25+
2026
- **Avoid premature optimization**: Write clear code first, optimize only when needed.
2127
- **Prefer explicit over implicit**: Use `Option` and `Result` types explicitly rather than hiding errors with `unwrap()`.
2228

2329
### 4. Function Length Limit
30+
2431
**Maximum 300 lines per function**: If a function exceeds this limit, split it into smaller, single-responsibility functions.
2532

2633
## Rust-Specific Guidelines
2734

2835
### Error Handling
36+
2937
- **Use `Result<T, E>`**: Functions that can fail should return `Result`.
3038
- **Use `anyhow::Result`**: For application-level errors, use `anyhow::Result<T>`.
3139
- **Propagate errors**: Use the `?` operator to propagate errors up the call stack.
3240
- **Add context**: Use `.context("...")` from `anyhow` to add meaningful error messages.
3341

3442
### Type Safety
43+
3544
- **Use strong types**: Prefer newtypes or enums (`Action`, `Status`) over primitive types.
3645
- **Leverage enums**: Use enums for state machines and role management.
3746

3847
### Async/Await
48+
3949
- **Prefer async/await**: Use `async fn` for I/O and network operations.
4050
- **Handle timeouts**: Use `tokio::time::timeout` for network operations.
4151

4252
### Documentation
53+
4354
- **Document public APIs**: Use `///` doc comments for public functions and types.
4455
- **Explain "why"**: Document the reasoning behind complex logic, not just "what".
56+
- **Markdown standards**: All markdown documentation must pass linter checks with no errors.
57+
- Run markdown linters to catch formatting issues (MD040, MD060, MD022, MD032, etc.).
58+
- Fix all linter errors before committing documentation changes.
59+
- Use proper table formatting with spaces around pipes.
60+
- Specify language for all fenced code blocks.
61+
- Add blank lines around headings and lists.
4562

4663
## Nostr and Mostro-Specific Guidelines
4764

4865
### Event Kinds
66+
4967
- **Use constants**: Always use constants from `mostro-core::prelude` (e.g., `NOSTR_ORDER_EVENT_KIND`).
5068
- **Never hardcode**: Avoid hardcoding event kind numbers like 38383.
5169

5270
### Message Handling
71+
5372
- **Parse DMs consistently**: Use `parse_dm_events` for all DM parsing.
5473
- **Support multiple message types**: Handle both GiftWrap (NIP-59) and PrivateDirectMessage (NIP-17).
5574

5675
### Key Management
57-
- **Identity vs Trade Keys**:
76+
77+
- **Identity vs Trade Keys**:
5878
- **Identity keys** (index 0): User's main identity, used for signing.
5979
- **Trade keys** (index 1+): Ephemeral keys for each trade, ensuring privacy.
6080

6181
## Code Organization Patterns
6282

6383
### Module Structure
84+
6485
```text
6586
src/
6687
├── main.rs # Entry point
@@ -72,14 +93,18 @@ src/
7293
```
7394

7495
### Re-export Pattern
96+
7597
Use `mod.rs` files to re-export commonly used items from submodules to keep imports clean.
7698

7799
## Database Patterns
100+
78101
- **User Model**: Use chainable setters and the `.save()` pattern.
79102
- **Order Management**: Use `Order::new()` to handle both insertion and updates.
80103

81104
## CLI Command Pattern
105+
82106
All CLI commands follow a standard flow:
107+
83108
1. Validate inputs.
84109
2. Get required keys (Identity/Trade).
85110
3. Build the Mostro message.
@@ -88,12 +113,14 @@ All CLI commands follow a standard flow:
88113
6. Parse and display results.
89114

90115
## Summary Checklist
116+
91117
- [ ] Code is readable and well-named.
92118
- [ ] No code duplication (DRY).
93119
- [ ] Functions are under 300 lines.
94120
- [ ] Errors are handled properly (`Result`, `?`).
95121
- [ ] Event kinds use constants from `mostro-core`.
96122
- [ ] Both GiftWrap and PrivateDirectMessage are supported.
97123
- [ ] Public APIs are documented.
124+
- [ ] All markdown documentation passes linter checks with no errors.
98125
- [ ] Code passes `cargo fmt` and `cargo clippy`.
99126
- [ ] Tests pass (`cargo test`).

docs/CREATING_ORDERS.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This document explains how to create new buy and sell orders using Mostro CLI.
55
## Overview
66

77
Creating an order involves:
8+
89
1. Specifying order parameters (type, amount, currency, etc.)
910
2. Building a Mostro message
1011
3. Sending it to the Mostro coordinator via Nostr
@@ -14,30 +15,36 @@ Creating an order involves:
1415
## Order Types
1516

1617
### Sell Order (Maker sells Bitcoin)
18+
1719
User wants to **sell Bitcoin** for fiat currency.
20+
1821
```bash
1922
mostro-cli neworder -k sell -c USD -f 100 -a 50000 -m "PayPal"
2023
```
2124

2225
### Buy Order (Maker buys Bitcoin)
26+
2327
User wants to **buy Bitcoin** with fiat currency.
28+
2429
```bash
2530
mostro-cli neworder -k buy -c EUR -f 200 -m "Bank Transfer" -i lnbc...
2631
```
2732

2833
## Order Parameters
2934

3035
### Required Parameters
36+
3137
| Parameter | Flag | Description | Example |
32-
|-----------|------|-------------|---------|
38+
| ----------- | ------ | ------------- | --------- |
3339
| Kind | `-k`, `--kind` | "buy" or "sell" | `sell` |
3440
| Fiat Code | `-c`, `--fiat-code` | Currency code | `USD`, `EUR`, `ARS` |
3541
| Fiat Amount | `-f`, `--fiat-amount` | Amount in fiat | `100` or `100-500` (range) |
3642
| Payment Method | `-m`, `--payment-method` | How to pay | `"PayPal"`, `"Bank Transfer"` |
3743

3844
### Optional Parameters
45+
3946
| Parameter | Flag | Description | Default |
40-
|-----------|------|-------------|---------|
47+
| ----------- | ------ | ------------- | --------- |
4148
| Amount | `-a`, `--amount` | Bitcoin in sats | 0 (market price) |
4249
| Premium | `-p`, `--premium` | Price premium % | 0 |
4350
| Invoice | `-i`, `--invoice` | Lightning invoice (buy orders) | None |
@@ -46,16 +53,19 @@ mostro-cli neworder -k buy -c EUR -f 200 -m "Bank Transfer" -i lnbc...
4653
## Order Examples
4754

4855
### 1. Simple Sell Order (Market Price)
56+
4957
```bash
5058
mostro-cli neworder -k sell -c USD -f 100 -m "PayPal"
5159
```
5260

5361
### 2. Range Order (Flexible Amount)
62+
5463
```bash
5564
mostro-cli neworder -k sell -c USD -f 100-500 -m "PayPal,Venmo"
5665
```
5766

5867
### 3. Buy Order with Lightning Invoice
68+
5969
```bash
6070
mostro-cli neworder -k buy -c USD -f 50 -i lnbc500u1p3.... -m "Cash App"
6171
```

docs/DATABASE_SCHEMA.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,41 @@
33
Mostro CLI uses a local SQLite database (`mcli.db`) to store user identity and trade history.
44

55
## Table: `users`
6+
67
Stores the BIP-39 mnemonic and identity information.
78

89
| Column | Type | Description |
9-
|--------|------|-------------|
10+
| -------- | ------ | ------------- |
1011
| `i0_pubkey` | `CHAR(64)` | Primary Key. The user's identity pubkey. |
1112
| `mnemonic` | `TEXT` | The 12-word seed phrase. |
1213
| `last_trade_index` | `INTEGER` | The last derived trade key index. |
1314
| `created_at` | `INTEGER` | Timestamp of creation. |
1415

1516
## Table: `orders`
17+
1618
Stores details of orders created or taken by the user.
1719

1820
| Column | Type | Description |
19-
|--------|------|-------------|
21+
| -------- | ------ | ------------- |
2022
| `id` | `TEXT` | Primary Key. Order UUID. |
2123
| `kind` | `TEXT` | "buy" or "sell". |
2224
| `status` | `TEXT` | Current status (pending, active, etc.). |
23-
| `amount` | `INTEGER` | Satoshis. |
24-
| `fiat_code` | `TEXT` | e.g., "USD". |
25+
| `amount` | `INTEGER` | Satoshis amount. |
26+
| `min_amount` | `INTEGER` | Minimum satoshis for range orders. |
27+
| `max_amount` | `INTEGER` | Maximum satoshis for range orders. |
28+
| `fiat_code` | `TEXT` | Fiat currency code (e.g., "USD"). |
2529
| `fiat_amount` | `INTEGER` | Fiat units. |
30+
| `payment_method` | `TEXT` | Payment method name. |
31+
| `premium` | `INTEGER` | Premium percentage (basis points). |
2632
| `trade_keys` | `TEXT` | Hex-encoded private key for this trade. |
33+
| `counterparty_pubkey` | `TEXT` | Pubkey of the other party in the trade. |
2734
| `is_mine` | `BOOLEAN` | True if the user created the order. |
35+
| `buyer_invoice` | `TEXT` | Lightning invoice for the buyer. |
36+
| `request_id` | `INTEGER` | Request ID for tracking messages. |
2837
| `created_at` | `INTEGER` | Creation timestamp. |
38+
| `expires_at` | `INTEGER` | Expiration timestamp. |
2939

3040
## Implementation Reference
41+
3142
- `src/db.rs`: Contains the `User` and `Order` structs and SQL queries.
3243
- `src/util/storage.rs`: Helper functions for database interaction.

docs/DISPUTE_MANAGEMENT.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,47 @@ This document covers how disputes are handled in Mostro CLI by both users and ad
77
When a trade goes wrong (e.g., fiat sent but Bitcoin not released), either party can initiate a dispute.
88

99
### Initiate a Dispute
10+
1011
```bash
1112
mostro-cli dispute -o <order-id>
1213
```
14+
1315
Mostro changes the order status to `Dispute`. This prevents any further automated transitions and flags the trade for manual intervention.
1416

1517
## Admin/Solver Flow
1618

1719
Admins or designated solvers use special commands to resolve conflicts. These commands require the `ADMIN_NSEC` environment variable to be set.
1820

1921
### 1. List Active Disputes
22+
2023
```bash
2124
mostro-cli listdisputes
2225
```
2326

2427
### 2. Take a Dispute
28+
2529
Before resolving, an admin must "take" the dispute to indicate they are handling it.
30+
2631
```bash
2732
mostro-cli admtakedispute -d <dispute-id>
2833
```
2934

3035
### 3. Settle (Pay Buyer)
36+
3137
If the buyer proved they sent fiat, the admin settles the hold invoice to pay the buyer.
38+
3239
```bash
3340
mostro-cli admsettle -o <order-id>
3441
```
3542

3643
### 4. Cancel (Refund Seller)
44+
3745
If the buyer failed to pay, the admin cancels the order to refund the locked Bitcoin to the seller.
46+
3847
```bash
3948
mostro-cli admcancel -o <order-id>
4049
```
4150

4251
## Security
52+
4353
Admin commands are gated by public key verification on the Mostro coordinator side. The CLI must sign these messages with the private key corresponding to a registered admin pubkey.

docs/KEY_IMPLEMENTATION.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This document provides technical details, code examples, and security practices
55
## Database Storage
66

77
### User Table
8+
89
Stores the root secret and identity info.
910

1011
```sql
@@ -17,6 +18,7 @@ CREATE TABLE users (
1718
```
1819

1920
### Order Table
21+
2022
Stores trade-specific keys.
2123

2224
```sql
@@ -30,6 +32,7 @@ CREATE TABLE orders (
3032
## Implementation Details
3133

3234
### Deriving Identity Keys
35+
3336
```rust
3437
pub async fn get_identity_keys(pool: &SqlitePool) -> Result<Keys> {
3538
let user = User::get(pool).await?;
@@ -46,6 +49,7 @@ pub async fn get_identity_keys(pool: &SqlitePool) -> Result<Keys> {
4649
```
4750

4851
### Deriving Trade Keys
52+
4953
```rust
5054
pub async fn get_trade_keys(pool: &SqlitePool, index: i64) -> Result<Keys> {
5155
let user = User::get(pool).await?;
@@ -64,26 +68,31 @@ pub async fn get_trade_keys(pool: &SqlitePool, index: i64) -> Result<Keys> {
6468
## Security Best Practices
6569

6670
### DO ✅
71+
6772
- **Use unique keys**: Always use `get_next_trade_keys()` for new orders.
6873
- **Sign with identity**: Prove authenticity while maintaining sender privacy.
6974
- **Update indices**: Ensure `last_trade_index` is updated after successful creation.
7075

7176
### DON'T ❌
77+
7278
- **Reuse keys**: Never use the same trade key for two different orders.
7379
- **Author with identity**: Never set the `pubkey` of a public event to your identity key.
7480
- **Lose mnemonic**: Keys cannot be recovered without the seed phrase.
7581

7682
## Key Recovery
7783

7884
If the local database is lost but the mnemonic is saved:
85+
7986
1. **Identity**: Re-deriving index 0 restores the original `npub`.
8087
2. **Trade History**: Re-deriving indices 1, 2, 3... restores access to trade messages.
8188
3. **Session Sync**: Use `mostro-cli restore` to fetch active orders and their associated trade indices from the Mostro coordinator.
8289

8390
## Troubleshooting
8491

8592
### "Cannot decrypt message"
93+
8694
Usually means the CLI is trying to use the wrong trade key. Ensure you are loading the key associated with the specific `order_id` from the database.
8795

8896
### "Trade index mismatch"
97+
8998
Occurs when the local database index is behind Mostro's records. Run `mostro-cli restore` to synchronize.

docs/KEY_MANAGEMENT.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Mostro CLI uses **hierarchical deterministic (HD) keys** following the BIP-32/44
88

99
## Key Hierarchy
1010

11-
```
11+
```text
1212
Master Seed (BIP-39 mnemonic - 12 words)
1313
1414
└─ m/44'/1237'/38383'/0/
@@ -34,6 +34,7 @@ Master Seed (BIP-39 mnemonic - 12 words)
3434
**Purpose**: Represents the user's persistent identity.
3535

3636
**Characteristics**:
37+
3738
- **Permanent**: Never changes, created once at initialization.
3839
- **Used for**: Signing messages to prove authenticity to Mostro.
3940
- **Not used as**: Event author (for privacy).
@@ -44,8 +45,9 @@ Master Seed (BIP-39 mnemonic - 12 words)
4445
**Purpose**: Ephemeral keys used for each individual trade to maintain privacy.
4546

4647
**Characteristics**:
48+
4749
- **Ephemeral**: New key for each trade.
48-
- **Used for**:
50+
- **Used for**:
4951
- Authoring Nostr events (as the sender).
5052
- Receiving encrypted messages.
5153
- Trade-specific communications.
@@ -58,7 +60,7 @@ Master Seed (BIP-39 mnemonic - 12 words)
5860

5961
Without trade keys, all orders would be linked to one identity:
6062

61-
```
63+
```text
6264
❌ Without trade keys (bad for privacy):
6365
Order #1 → User's Identity Key (npub1abc...)
6466
Order #2 → User's Identity Key (npub1abc...)
@@ -69,7 +71,7 @@ Result: Anyone can see all orders from same user!
6971

7072
With trade keys, each order appears independent:
7173

72-
```
74+
```text
7375
✅ With trade keys (good for privacy):
7476
Order #1 → Trade Key #1 (npub1xyz...) + signed by identity
7577
Order #2 → Trade Key #2 (npub1def...) + signed by identity
@@ -81,6 +83,7 @@ Result: Orders appear unrelated! Privacy maintained.
8183
### Authenticity Through Signing
8284

8385
The identity key signs messages to prove they're from the real user. Mostro can verify:
86+
8487
1. ✅ Message came from a legitimate user (signature verification).
8588
2. ✅ User's reputation/history (identity-based).
8689
3. ✅ Each trade maintains privacy (separate trade keys).

0 commit comments

Comments
 (0)