Skip to content

Commit 0b265ef

Browse files
committed
docs: Add documentation for resources, invoices, and messaging traits
1 parent f19e2f2 commit 0b265ef

File tree

3 files changed

+245
-0
lines changed

3 files changed

+245
-0
lines changed

docs/dao/traits/invoices.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Invoices Trait
2+
3+
The invoices trait defines the interface for processing payments for resources defined through the resources trait.
4+
5+
## Interface
6+
7+
```clarity
8+
(define-trait invoices (
9+
(pay-invoice (uint (optional (buff 34))) (response uint uint))
10+
(pay-invoice-by-resource-name ((string-utf8 50) (optional (buff 34))) (response uint uint))
11+
))
12+
```
13+
14+
## Functions
15+
16+
### Payment Processing
17+
18+
#### pay-invoice
19+
Processes payment for a resource by ID.
20+
- Parameters:
21+
- `uint`: Resource ID
22+
- `memo`: Optional payment memo (34 bytes)
23+
- Access: Public
24+
- Returns: Invoice ID on success
25+
26+
#### pay-invoice-by-resource-name
27+
Processes payment for a resource by name.
28+
- Parameters:
29+
- `name`: Resource name
30+
- `memo`: Optional payment memo (34 bytes)
31+
- Access: Public
32+
- Returns: Invoice ID on success
33+
34+
## Implementation Requirements
35+
36+
1. Verify resource exists and is enabled
37+
2. Process payment transfer
38+
3. Generate unique invoice ID
39+
4. Track payment status
40+
5. Handle payment memos
41+
6. Emit payment events
42+
43+
## Usage Pattern
44+
45+
Implementations should:
46+
1. Validate resource status
47+
2. Process payment atomically
48+
3. Generate sequential invoice IDs
49+
4. Log payment details
50+
51+
Example implementation:
52+
```clarity
53+
(define-public (pay-invoice-by-resource-name
54+
(name (string-utf8 50))
55+
(memo (optional (buff 34))))
56+
(let (
57+
(resource (unwrap! (get-resource-by-name name) ERR_NOT_FOUND))
58+
(price (get price resource))
59+
)
60+
;; Verify resource enabled
61+
(asserts! (get enabled resource) ERR_DISABLED)
62+
63+
;; Process payment
64+
(try! (stx-transfer? price tx-sender payment-address))
65+
66+
;; Generate invoice
67+
(let ((invoice-id (generate-invoice-id)))
68+
;; Log payment
69+
(print {
70+
notification: "payment-processed",
71+
payload: {
72+
resource: name,
73+
price: price,
74+
payer: tx-sender,
75+
invoiceId: invoice-id,
76+
memo: memo
77+
}
78+
})
79+
80+
(ok invoice-id)
81+
)
82+
)
83+
)
84+
```

docs/dao/traits/messaging.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Messaging Trait
2+
3+
The messaging trait defines the interface for sending on-chain messages up to 1MB in size.
4+
5+
## Interface
6+
7+
```clarity
8+
(define-trait messaging (
9+
(send ((string-ascii 1048576) bool) (response bool uint))
10+
))
11+
```
12+
13+
## Functions
14+
15+
### send
16+
Sends an on-chain message.
17+
- Parameters:
18+
- `message`: ASCII message content (max 1MB)
19+
- `isFromDao`: Whether message is from DAO
20+
- Access: Public for regular messages, DAO/extension only for DAO messages
21+
- Returns: Success/failure response
22+
23+
## Implementation Requirements
24+
25+
1. Validate message size (≤ 1MB)
26+
2. Enforce DAO authorization for DAO messages
27+
3. Track message history
28+
4. Handle message encoding
29+
5. Emit message events
30+
31+
## Usage Pattern
32+
33+
Implementations should:
34+
1. Verify message size
35+
2. Check authorization for DAO messages
36+
3. Log message details
37+
4. Handle errors gracefully
38+
39+
Example implementation:
40+
```clarity
41+
(define-public (send (message (string-ascii 1048576)) (isFromDao bool))
42+
(begin
43+
;; Check DAO authorization if needed
44+
(if isFromDao
45+
(try! (is-dao-or-extension))
46+
true
47+
)
48+
49+
;; Log message
50+
(print {
51+
notification: "message-sent",
52+
payload: {
53+
sender: tx-sender,
54+
isFromDao: isFromDao,
55+
message: message
56+
}
57+
})
58+
59+
(ok true)
60+
)
61+
)
62+
```

docs/dao/traits/resources.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Resources Trait
2+
3+
The resources trait defines the interface for managing payable resources with configurable pricing and descriptions.
4+
5+
## Interface
6+
7+
```clarity
8+
(define-trait resources (
9+
(set-payment-address (principal) (response bool uint))
10+
(add-resource ((string-utf8 50) (string-utf8 255) uint (optional (string-utf8 255))) (response uint uint))
11+
(toggle-resource (uint) (response bool uint))
12+
(toggle-resource-by-name ((string-utf8 50)) (response bool uint))
13+
))
14+
```
15+
16+
## Functions
17+
18+
### Configuration
19+
20+
#### set-payment-address
21+
Sets the payment recipient for resource invoices.
22+
- Parameters:
23+
- `principal`: Payment recipient address
24+
- Access: DAO/extension only
25+
- Returns: Success/failure response
26+
27+
### Resource Management
28+
29+
#### add-resource
30+
Creates a new payable resource.
31+
- Parameters:
32+
- `name`: Resource name (max 50 chars)
33+
- `description`: Resource description (max 255 chars)
34+
- `price`: Price in microSTX
35+
- `metadata`: Optional additional data (max 255 chars)
36+
- Access: DAO/extension only
37+
- Returns: Resource ID on success
38+
39+
#### toggle-resource
40+
Enables/disables a resource by ID.
41+
- Parameters:
42+
- `uint`: Resource ID
43+
- Access: DAO/extension only
44+
- Returns: Success/failure response
45+
46+
#### toggle-resource-by-name
47+
Enables/disables a resource by name.
48+
- Parameters:
49+
- `name`: Resource name
50+
- Access: DAO/extension only
51+
- Returns: Success/failure response
52+
53+
## Implementation Requirements
54+
55+
1. Maintain unique resource names
56+
2. Track resource enabled/disabled status
57+
3. Validate input parameters
58+
4. Enforce DAO/extension-only access
59+
5. Emit events for state changes
60+
61+
## Usage Pattern
62+
63+
Implementations should:
64+
1. Verify resource name uniqueness
65+
2. Validate price > 0
66+
3. Track resource status
67+
4. Log all changes
68+
69+
Example implementation:
70+
```clarity
71+
(define-public (add-resource (name (string-utf8 50))
72+
(description (string-utf8 255))
73+
(price uint)
74+
(metadata (optional (string-utf8 255))))
75+
(begin
76+
;; Check authorization
77+
(try! (is-dao-or-extension))
78+
79+
;; Validate inputs
80+
(asserts! (> price u0) ERR_INVALID_PRICE)
81+
(asserts! (not (resource-exists name)) ERR_NAME_EXISTS)
82+
83+
;; Save resource
84+
(try! (save-resource name description price metadata))
85+
86+
;; Log creation
87+
(print {
88+
notification: "resource-added",
89+
payload: {
90+
name: name,
91+
price: price,
92+
description: description
93+
}
94+
})
95+
96+
(ok true)
97+
)
98+
)
99+
```

0 commit comments

Comments
 (0)