You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/CODING_STANDARDS.md
+28-1Lines changed: 28 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,62 +5,83 @@ This document outlines the coding standards and best practices for the Mostro CL
5
5
## Core Principles
6
6
7
7
### 1. Readability and Reuse
8
+
8
9
**Priority**: Code should be written for humans first, machines second.
10
+
9
11
-**Clear naming**: Use descriptive names for functions, variables, and modules (e.g., `parse_dm_events` vs `pde`).
10
12
-**Function reuse**: Extract common logic into reusable functions. Place shared utilities in appropriate modules (`src/util/`, `src/parser/`, etc.).
11
13
-**Module organization**: Group related functionality together (CLI commands in `src/cli/`, Protocol parsing in `src/parser/`, Utilities in `src/util/`).
12
14
13
15
### 2. Avoid Code Duplication (DRY Principle)
16
+
14
17
**Don't Repeat Yourself**: If the same logic appears in multiple places, extract it.
18
+
15
19
-**Extract common patterns**: Create helper functions for repeated operations like DM sending.
16
20
-**Centralize constants**: Import from `mostro-core::prelude` instead of hardcoding values.
17
21
18
22
### 3. Simplicity
23
+
19
24
**Keep It Simple**: Prefer straightforward solutions over clever ones.
25
+
20
26
-**Avoid premature optimization**: Write clear code first, optimize only when needed.
21
27
-**Prefer explicit over implicit**: Use `Option` and `Result` types explicitly rather than hiding errors with `unwrap()`.
22
28
23
29
### 4. Function Length Limit
30
+
24
31
**Maximum 300 lines per function**: If a function exceeds this limit, split it into smaller, single-responsibility functions.
25
32
26
33
## Rust-Specific Guidelines
27
34
28
35
### Error Handling
36
+
29
37
-**Use `Result<T, E>`**: Functions that can fail should return `Result`.
30
38
-**Use `anyhow::Result`**: For application-level errors, use `anyhow::Result<T>`.
31
39
-**Propagate errors**: Use the `?` operator to propagate errors up the call stack.
32
40
-**Add context**: Use `.context("...")` from `anyhow` to add meaningful error messages.
33
41
34
42
### Type Safety
43
+
35
44
-**Use strong types**: Prefer newtypes or enums (`Action`, `Status`) over primitive types.
36
45
-**Leverage enums**: Use enums for state machines and role management.
37
46
38
47
### Async/Await
48
+
39
49
-**Prefer async/await**: Use `async fn` for I/O and network operations.
40
50
-**Handle timeouts**: Use `tokio::time::timeout` for network operations.
41
51
42
52
### Documentation
53
+
43
54
-**Document public APIs**: Use `///` doc comments for public functions and types.
44
55
-**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.
45
62
46
63
## Nostr and Mostro-Specific Guidelines
47
64
48
65
### Event Kinds
66
+
49
67
-**Use constants**: Always use constants from `mostro-core::prelude` (e.g., `NOSTR_ORDER_EVENT_KIND`).
50
68
-**Never hardcode**: Avoid hardcoding event kind numbers like 38383.
51
69
52
70
### Message Handling
71
+
53
72
-**Parse DMs consistently**: Use `parse_dm_events` for all DM parsing.
54
73
-**Support multiple message types**: Handle both GiftWrap (NIP-59) and PrivateDirectMessage (NIP-17).
55
74
56
75
### Key Management
57
-
-**Identity vs Trade Keys**:
76
+
77
+
-**Identity vs Trade Keys**:
58
78
-**Identity keys** (index 0): User's main identity, used for signing.
59
79
-**Trade keys** (index 1+): Ephemeral keys for each trade, ensuring privacy.
60
80
61
81
## Code Organization Patterns
62
82
63
83
### Module Structure
84
+
64
85
```text
65
86
src/
66
87
├── main.rs # Entry point
@@ -72,14 +93,18 @@ src/
72
93
```
73
94
74
95
### Re-export Pattern
96
+
75
97
Use `mod.rs` files to re-export commonly used items from submodules to keep imports clean.
76
98
77
99
## Database Patterns
100
+
78
101
-**User Model**: Use chainable setters and the `.save()` pattern.
79
102
-**Order Management**: Use `Order::new()` to handle both insertion and updates.
80
103
81
104
## CLI Command Pattern
105
+
82
106
All CLI commands follow a standard flow:
107
+
83
108
1. Validate inputs.
84
109
2. Get required keys (Identity/Trade).
85
110
3. Build the Mostro message.
@@ -88,12 +113,14 @@ All CLI commands follow a standard flow:
88
113
6. Parse and display results.
89
114
90
115
## Summary Checklist
116
+
91
117
-[ ] Code is readable and well-named.
92
118
-[ ] No code duplication (DRY).
93
119
-[ ] Functions are under 300 lines.
94
120
-[ ] Errors are handled properly (`Result`, `?`).
95
121
-[ ] Event kinds use constants from `mostro-core`.
96
122
-[ ] Both GiftWrap and PrivateDirectMessage are supported.
97
123
-[ ] Public APIs are documented.
124
+
-[ ] All markdown documentation passes linter checks with no errors.
Copy file name to clipboardExpand all lines: docs/DISPUTE_MANAGEMENT.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,37 +7,47 @@ This document covers how disputes are handled in Mostro CLI by both users and ad
7
7
When a trade goes wrong (e.g., fiat sent but Bitcoin not released), either party can initiate a dispute.
8
8
9
9
### Initiate a Dispute
10
+
10
11
```bash
11
12
mostro-cli dispute -o <order-id>
12
13
```
14
+
13
15
Mostro changes the order status to `Dispute`. This prevents any further automated transitions and flags the trade for manual intervention.
14
16
15
17
## Admin/Solver Flow
16
18
17
19
Admins or designated solvers use special commands to resolve conflicts. These commands require the `ADMIN_NSEC` environment variable to be set.
18
20
19
21
### 1. List Active Disputes
22
+
20
23
```bash
21
24
mostro-cli listdisputes
22
25
```
23
26
24
27
### 2. Take a Dispute
28
+
25
29
Before resolving, an admin must "take" the dispute to indicate they are handling it.
30
+
26
31
```bash
27
32
mostro-cli admtakedispute -d <dispute-id>
28
33
```
29
34
30
35
### 3. Settle (Pay Buyer)
36
+
31
37
If the buyer proved they sent fiat, the admin settles the hold invoice to pay the buyer.
38
+
32
39
```bash
33
40
mostro-cli admsettle -o <order-id>
34
41
```
35
42
36
43
### 4. Cancel (Refund Seller)
44
+
37
45
If the buyer failed to pay, the admin cancels the order to refund the locked Bitcoin to the seller.
46
+
38
47
```bash
39
48
mostro-cli admcancel -o <order-id>
40
49
```
41
50
42
51
## Security
52
+
43
53
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.
0 commit comments