mintbot 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mintbot-0.1.0/PKG-INFO +297 -0
- mintbot-0.1.0/README.md +269 -0
- mintbot-0.1.0/mintbot/__init__.py +61 -0
- mintbot-0.1.0/mintbot/exceptions.py +57 -0
- mintbot-0.1.0/mintbot/models.py +121 -0
- mintbot-0.1.0/mintbot/wallet.py +760 -0
- mintbot-0.1.0/mintbot.egg-info/PKG-INFO +297 -0
- mintbot-0.1.0/mintbot.egg-info/SOURCES.txt +12 -0
- mintbot-0.1.0/mintbot.egg-info/dependency_links.txt +1 -0
- mintbot-0.1.0/mintbot.egg-info/requires.txt +6 -0
- mintbot-0.1.0/mintbot.egg-info/top_level.txt +1 -0
- mintbot-0.1.0/pyproject.toml +49 -0
- mintbot-0.1.0/setup.cfg +4 -0
- mintbot-0.1.0/tests/test_wallet.py +370 -0
mintbot-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mintbot
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for Mintbot — Lightning-native payments for AI agents
|
|
5
|
+
Author-email: Mintbot <dev@mintbot.cash>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://mintbot.cash
|
|
8
|
+
Project-URL: Documentation, https://mintbot.cash/docs
|
|
9
|
+
Project-URL: Repository, https://github.com/mintbot/mintbot-python
|
|
10
|
+
Project-URL: Issues, https://github.com/mintbot/mintbot-python/issues
|
|
11
|
+
Keywords: lightning,bitcoin,cashu,ai,agents,payments,mintbot
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
20
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
Requires-Dist: httpx>=0.27.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
27
|
+
Requires-Dist: respx>=0.21; extra == "dev"
|
|
28
|
+
|
|
29
|
+
# mintbot
|
|
30
|
+
|
|
31
|
+
> Lightning-native payments for AI agents. Powered by [Mintbot](https://mintbot.cash).
|
|
32
|
+
|
|
33
|
+
`mintbot` is a Python SDK for the Mintbot Agent Pay API — a zero-setup payment layer for AI agents using Bitcoin Lightning and Cashu.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install mintbot
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Requires Python 3.10+.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from mintbot import AgentWallet
|
|
51
|
+
|
|
52
|
+
# 1. Create a new wallet (one-time setup)
|
|
53
|
+
wallet = AgentWallet.create(agent_name="my-bot")
|
|
54
|
+
print(wallet.api_key) # vf_live_... — SAVE THIS, shown only once!
|
|
55
|
+
|
|
56
|
+
# 2. Load an existing wallet
|
|
57
|
+
wallet = AgentWallet(api_key="vf_live_...")
|
|
58
|
+
|
|
59
|
+
# 3. Check balance
|
|
60
|
+
print(wallet.balance) # 950 (satoshis)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## API Reference
|
|
66
|
+
|
|
67
|
+
### `AgentWallet.create()`
|
|
68
|
+
|
|
69
|
+
Create a new agent wallet. Returns an authenticated `AgentWallet` instance.
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
wallet = AgentWallet.create(
|
|
73
|
+
agent_name="translator-bot", # optional label
|
|
74
|
+
budget_sats=10_000, # optional spending cap
|
|
75
|
+
base_url="https://api.visionfusen.org",
|
|
76
|
+
)
|
|
77
|
+
print(wallet.api_key) # vf_live_... — store securely!
|
|
78
|
+
print(wallet._wallet_info.wallet_id) # w_abc123
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
### `AgentWallet(api_key=...)`
|
|
84
|
+
|
|
85
|
+
Load an existing wallet by API key.
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
wallet = AgentWallet(api_key="vf_live_...", base_url="https://api.visionfusen.org")
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
### `wallet.balance` (property)
|
|
94
|
+
|
|
95
|
+
Live balance in satoshis.
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
sats = wallet.balance # int
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### `wallet.get_balance_info()`
|
|
102
|
+
|
|
103
|
+
Full balance info with metadata.
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
info = wallet.get_balance_info()
|
|
107
|
+
print(info.balance_sats) # 950
|
|
108
|
+
print(info.agent_name) # "my-bot"
|
|
109
|
+
print(info.budget_limit_sats) # None or int
|
|
110
|
+
print(info.last_active) # datetime
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
### `wallet.create_invoice(amount)`
|
|
116
|
+
|
|
117
|
+
Create a Lightning invoice to fund the wallet.
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
invoice = wallet.create_invoice(amount=1000) # satoshis
|
|
121
|
+
print(invoice.bolt11) # lnbc1000n1...
|
|
122
|
+
print(invoice.quote_id) # for status polling
|
|
123
|
+
print(invoice.status) # "UNPAID"
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Balance credits automatically when the invoice is paid.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
### `wallet.pay(to_wallet, amount, memo=None)`
|
|
131
|
+
|
|
132
|
+
Internal payment — instant, zero fee, wallet-to-wallet.
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
result = wallet.pay(
|
|
136
|
+
to_wallet="w_xyz789",
|
|
137
|
+
amount=50,
|
|
138
|
+
memo="translation service",
|
|
139
|
+
)
|
|
140
|
+
print(result.status) # "completed"
|
|
141
|
+
print(result.new_balance_sats) # updated balance
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
### `wallet.pay_invoice(bolt11, memo=None)`
|
|
147
|
+
|
|
148
|
+
Pay a BOLT11 Lightning invoice (external payment via Cashu melt).
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
result = wallet.pay_invoice("lnbc500n1...")
|
|
152
|
+
print(result.amount_sats) # 500
|
|
153
|
+
print(result.fee_sats) # actual routing fee
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
For explicit pre-flight balance checking:
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
result = wallet.pay_invoice_amount("lnbc500n1...", amount=500)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
### `wallet.pay_address(lightning_address, amount, memo=None)`
|
|
165
|
+
|
|
166
|
+
Pay a Lightning address — resolved server-side via LNURL-pay.
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
result = wallet.pay_address(
|
|
170
|
+
lightning_address="user@getalby.com",
|
|
171
|
+
amount=100,
|
|
172
|
+
memo="coffee",
|
|
173
|
+
)
|
|
174
|
+
print(result.status) # "completed"
|
|
175
|
+
print(result.fee_sats) # routing fee
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
### `wallet.withdraw(amount)`
|
|
181
|
+
|
|
182
|
+
Withdraw funds as a portable Cashu token.
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
token = wallet.withdraw(amount=200)
|
|
186
|
+
print(token) # cashuAeyJ... — redeemable at the mint
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
For full result metadata:
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
result = wallet.withdraw_full(amount=200)
|
|
193
|
+
print(result.token)
|
|
194
|
+
print(result.new_balance_sats)
|
|
195
|
+
print(result.tx_id)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
### `wallet.transactions(limit=20, offset=0, tx_type=None)`
|
|
201
|
+
|
|
202
|
+
Fetch transaction history.
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
txs = wallet.transactions(limit=10)
|
|
206
|
+
for tx in txs:
|
|
207
|
+
print(f"{tx.tx_type}: {tx.amount_sats} sats [{tx.direction}] - {tx.status}")
|
|
208
|
+
|
|
209
|
+
# Filter by type
|
|
210
|
+
txs = wallet.transactions(tx_type="lightning_out")
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Transaction types: `internal`, `lightning_in`, `lightning_out`, `withdraw`, `mint`
|
|
214
|
+
|
|
215
|
+
For pagination metadata:
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
result = wallet.get_transactions(limit=5, offset=10)
|
|
219
|
+
print(f"Page {result.offset // result.limit + 1} of {result.total // result.limit + 1}")
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
### `AgentWallet.health()`
|
|
225
|
+
|
|
226
|
+
Check API health (no auth required).
|
|
227
|
+
|
|
228
|
+
```python
|
|
229
|
+
info = AgentWallet.health()
|
|
230
|
+
print(info.status) # "ok"
|
|
231
|
+
print(info.version) # "2.0.0"
|
|
232
|
+
print(info.features) # ["internal-pay", "lightning-in", ...]
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Error Handling
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
from mintbot import (
|
|
241
|
+
MintbotError, # base class
|
|
242
|
+
AuthenticationError, # invalid API key (401)
|
|
243
|
+
InsufficientBalance, # not enough funds (402)
|
|
244
|
+
WalletNotFound, # wallet ID not found (404)
|
|
245
|
+
PaymentError, # payment failure
|
|
246
|
+
InvoiceError, # invoice creation failed
|
|
247
|
+
WithdrawalError, # withdrawal failed
|
|
248
|
+
APIError, # generic API error
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
try:
|
|
252
|
+
wallet.pay(to_wallet="w_abc", amount=1000)
|
|
253
|
+
except InsufficientBalance as e:
|
|
254
|
+
print(f"Need {e.shortfall_sats} more sats (have {e.balance_sats})")
|
|
255
|
+
except WalletNotFound as e:
|
|
256
|
+
print(f"Wallet not found: {e.message}")
|
|
257
|
+
except MintbotError as e:
|
|
258
|
+
print(f"API error {e.status_code}: {e.message}")
|
|
259
|
+
if e.detail:
|
|
260
|
+
print(f"Detail: {e.detail}")
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## Context Manager
|
|
266
|
+
|
|
267
|
+
```python
|
|
268
|
+
with AgentWallet(api_key="vf_live_...") as wallet:
|
|
269
|
+
print(wallet.balance)
|
|
270
|
+
# HTTP client closed automatically
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## Models
|
|
276
|
+
|
|
277
|
+
| Class | Fields |
|
|
278
|
+
|-------|--------|
|
|
279
|
+
| `BalanceInfo` | `wallet_id`, `agent_name`, `balance_sats`, `budget_limit_sats`, `created_at`, `last_active` |
|
|
280
|
+
| `Invoice` | `bolt11`, `quote_id`, `amount_sats`, `status`, `method`, `wallet_id`, `note` |
|
|
281
|
+
| `PaymentResult` | `tx_id`, `amount_sats`, `fee_sats`, `tx_type`, `status`, `new_balance_sats`, `memo`, `created_at` |
|
|
282
|
+
| `WithdrawalResult` | `token`, `amount_sats`, `tx_id`, `new_balance_sats`, `wallet_id`, `created_at` |
|
|
283
|
+
| `Transaction` | `id`, `direction`, `amount_sats`, `fee_sats`, `tx_type`, `status`, `memo`, `created_at` |
|
|
284
|
+
| `HealthInfo` | `status`, `service`, `version`, `timestamp`, `features` |
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## Links
|
|
289
|
+
|
|
290
|
+
- **Website:** https://mintbot.cash
|
|
291
|
+
- **API base URL:** https://api.visionfusen.org
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## License
|
|
296
|
+
|
|
297
|
+
MIT
|
mintbot-0.1.0/README.md
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
# mintbot
|
|
2
|
+
|
|
3
|
+
> Lightning-native payments for AI agents. Powered by [Mintbot](https://mintbot.cash).
|
|
4
|
+
|
|
5
|
+
`mintbot` is a Python SDK for the Mintbot Agent Pay API — a zero-setup payment layer for AI agents using Bitcoin Lightning and Cashu.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install mintbot
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Requires Python 3.10+.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from mintbot import AgentWallet
|
|
23
|
+
|
|
24
|
+
# 1. Create a new wallet (one-time setup)
|
|
25
|
+
wallet = AgentWallet.create(agent_name="my-bot")
|
|
26
|
+
print(wallet.api_key) # vf_live_... — SAVE THIS, shown only once!
|
|
27
|
+
|
|
28
|
+
# 2. Load an existing wallet
|
|
29
|
+
wallet = AgentWallet(api_key="vf_live_...")
|
|
30
|
+
|
|
31
|
+
# 3. Check balance
|
|
32
|
+
print(wallet.balance) # 950 (satoshis)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## API Reference
|
|
38
|
+
|
|
39
|
+
### `AgentWallet.create()`
|
|
40
|
+
|
|
41
|
+
Create a new agent wallet. Returns an authenticated `AgentWallet` instance.
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
wallet = AgentWallet.create(
|
|
45
|
+
agent_name="translator-bot", # optional label
|
|
46
|
+
budget_sats=10_000, # optional spending cap
|
|
47
|
+
base_url="https://api.visionfusen.org",
|
|
48
|
+
)
|
|
49
|
+
print(wallet.api_key) # vf_live_... — store securely!
|
|
50
|
+
print(wallet._wallet_info.wallet_id) # w_abc123
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
### `AgentWallet(api_key=...)`
|
|
56
|
+
|
|
57
|
+
Load an existing wallet by API key.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
wallet = AgentWallet(api_key="vf_live_...", base_url="https://api.visionfusen.org")
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
### `wallet.balance` (property)
|
|
66
|
+
|
|
67
|
+
Live balance in satoshis.
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
sats = wallet.balance # int
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### `wallet.get_balance_info()`
|
|
74
|
+
|
|
75
|
+
Full balance info with metadata.
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
info = wallet.get_balance_info()
|
|
79
|
+
print(info.balance_sats) # 950
|
|
80
|
+
print(info.agent_name) # "my-bot"
|
|
81
|
+
print(info.budget_limit_sats) # None or int
|
|
82
|
+
print(info.last_active) # datetime
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
### `wallet.create_invoice(amount)`
|
|
88
|
+
|
|
89
|
+
Create a Lightning invoice to fund the wallet.
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
invoice = wallet.create_invoice(amount=1000) # satoshis
|
|
93
|
+
print(invoice.bolt11) # lnbc1000n1...
|
|
94
|
+
print(invoice.quote_id) # for status polling
|
|
95
|
+
print(invoice.status) # "UNPAID"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Balance credits automatically when the invoice is paid.
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
### `wallet.pay(to_wallet, amount, memo=None)`
|
|
103
|
+
|
|
104
|
+
Internal payment — instant, zero fee, wallet-to-wallet.
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
result = wallet.pay(
|
|
108
|
+
to_wallet="w_xyz789",
|
|
109
|
+
amount=50,
|
|
110
|
+
memo="translation service",
|
|
111
|
+
)
|
|
112
|
+
print(result.status) # "completed"
|
|
113
|
+
print(result.new_balance_sats) # updated balance
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
### `wallet.pay_invoice(bolt11, memo=None)`
|
|
119
|
+
|
|
120
|
+
Pay a BOLT11 Lightning invoice (external payment via Cashu melt).
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
result = wallet.pay_invoice("lnbc500n1...")
|
|
124
|
+
print(result.amount_sats) # 500
|
|
125
|
+
print(result.fee_sats) # actual routing fee
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
For explicit pre-flight balance checking:
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
result = wallet.pay_invoice_amount("lnbc500n1...", amount=500)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
### `wallet.pay_address(lightning_address, amount, memo=None)`
|
|
137
|
+
|
|
138
|
+
Pay a Lightning address — resolved server-side via LNURL-pay.
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
result = wallet.pay_address(
|
|
142
|
+
lightning_address="user@getalby.com",
|
|
143
|
+
amount=100,
|
|
144
|
+
memo="coffee",
|
|
145
|
+
)
|
|
146
|
+
print(result.status) # "completed"
|
|
147
|
+
print(result.fee_sats) # routing fee
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
### `wallet.withdraw(amount)`
|
|
153
|
+
|
|
154
|
+
Withdraw funds as a portable Cashu token.
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
token = wallet.withdraw(amount=200)
|
|
158
|
+
print(token) # cashuAeyJ... — redeemable at the mint
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
For full result metadata:
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
result = wallet.withdraw_full(amount=200)
|
|
165
|
+
print(result.token)
|
|
166
|
+
print(result.new_balance_sats)
|
|
167
|
+
print(result.tx_id)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
### `wallet.transactions(limit=20, offset=0, tx_type=None)`
|
|
173
|
+
|
|
174
|
+
Fetch transaction history.
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
txs = wallet.transactions(limit=10)
|
|
178
|
+
for tx in txs:
|
|
179
|
+
print(f"{tx.tx_type}: {tx.amount_sats} sats [{tx.direction}] - {tx.status}")
|
|
180
|
+
|
|
181
|
+
# Filter by type
|
|
182
|
+
txs = wallet.transactions(tx_type="lightning_out")
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Transaction types: `internal`, `lightning_in`, `lightning_out`, `withdraw`, `mint`
|
|
186
|
+
|
|
187
|
+
For pagination metadata:
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
result = wallet.get_transactions(limit=5, offset=10)
|
|
191
|
+
print(f"Page {result.offset // result.limit + 1} of {result.total // result.limit + 1}")
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
### `AgentWallet.health()`
|
|
197
|
+
|
|
198
|
+
Check API health (no auth required).
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
info = AgentWallet.health()
|
|
202
|
+
print(info.status) # "ok"
|
|
203
|
+
print(info.version) # "2.0.0"
|
|
204
|
+
print(info.features) # ["internal-pay", "lightning-in", ...]
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## Error Handling
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
from mintbot import (
|
|
213
|
+
MintbotError, # base class
|
|
214
|
+
AuthenticationError, # invalid API key (401)
|
|
215
|
+
InsufficientBalance, # not enough funds (402)
|
|
216
|
+
WalletNotFound, # wallet ID not found (404)
|
|
217
|
+
PaymentError, # payment failure
|
|
218
|
+
InvoiceError, # invoice creation failed
|
|
219
|
+
WithdrawalError, # withdrawal failed
|
|
220
|
+
APIError, # generic API error
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
try:
|
|
224
|
+
wallet.pay(to_wallet="w_abc", amount=1000)
|
|
225
|
+
except InsufficientBalance as e:
|
|
226
|
+
print(f"Need {e.shortfall_sats} more sats (have {e.balance_sats})")
|
|
227
|
+
except WalletNotFound as e:
|
|
228
|
+
print(f"Wallet not found: {e.message}")
|
|
229
|
+
except MintbotError as e:
|
|
230
|
+
print(f"API error {e.status_code}: {e.message}")
|
|
231
|
+
if e.detail:
|
|
232
|
+
print(f"Detail: {e.detail}")
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Context Manager
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
with AgentWallet(api_key="vf_live_...") as wallet:
|
|
241
|
+
print(wallet.balance)
|
|
242
|
+
# HTTP client closed automatically
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Models
|
|
248
|
+
|
|
249
|
+
| Class | Fields |
|
|
250
|
+
|-------|--------|
|
|
251
|
+
| `BalanceInfo` | `wallet_id`, `agent_name`, `balance_sats`, `budget_limit_sats`, `created_at`, `last_active` |
|
|
252
|
+
| `Invoice` | `bolt11`, `quote_id`, `amount_sats`, `status`, `method`, `wallet_id`, `note` |
|
|
253
|
+
| `PaymentResult` | `tx_id`, `amount_sats`, `fee_sats`, `tx_type`, `status`, `new_balance_sats`, `memo`, `created_at` |
|
|
254
|
+
| `WithdrawalResult` | `token`, `amount_sats`, `tx_id`, `new_balance_sats`, `wallet_id`, `created_at` |
|
|
255
|
+
| `Transaction` | `id`, `direction`, `amount_sats`, `fee_sats`, `tx_type`, `status`, `memo`, `created_at` |
|
|
256
|
+
| `HealthInfo` | `status`, `service`, `version`, `timestamp`, `features` |
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## Links
|
|
261
|
+
|
|
262
|
+
- **Website:** https://mintbot.cash
|
|
263
|
+
- **API base URL:** https://api.visionfusen.org
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## License
|
|
268
|
+
|
|
269
|
+
MIT
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""
|
|
2
|
+
mintbot — Python SDK for Mintbot Agent Pay.
|
|
3
|
+
|
|
4
|
+
Quick start::
|
|
5
|
+
|
|
6
|
+
from mintbot import AgentWallet
|
|
7
|
+
|
|
8
|
+
# Create a new wallet
|
|
9
|
+
wallet = AgentWallet.create(agent_name="my-bot")
|
|
10
|
+
print(wallet.api_key) # mb_live_... — save this!
|
|
11
|
+
|
|
12
|
+
# Load existing wallet
|
|
13
|
+
wallet = AgentWallet(api_key="mb_live_...")
|
|
14
|
+
print(wallet.balance) # 950
|
|
15
|
+
|
|
16
|
+
See https://mintbot.cash for full documentation.
|
|
17
|
+
"""
|
|
18
|
+
from .wallet import AgentWallet
|
|
19
|
+
from .models import (
|
|
20
|
+
BalanceInfo,
|
|
21
|
+
HealthInfo,
|
|
22
|
+
Invoice,
|
|
23
|
+
PaymentResult,
|
|
24
|
+
Transaction,
|
|
25
|
+
TransactionList,
|
|
26
|
+
WalletInfo,
|
|
27
|
+
WithdrawalResult,
|
|
28
|
+
)
|
|
29
|
+
from .exceptions import (
|
|
30
|
+
MintbotError,
|
|
31
|
+
AuthenticationError,
|
|
32
|
+
InsufficientBalance,
|
|
33
|
+
WalletNotFound,
|
|
34
|
+
PaymentError,
|
|
35
|
+
InvoiceError,
|
|
36
|
+
WithdrawalError,
|
|
37
|
+
APIError,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
__version__ = "0.1.0"
|
|
41
|
+
__all__ = [
|
|
42
|
+
"AgentWallet",
|
|
43
|
+
# Models
|
|
44
|
+
"BalanceInfo",
|
|
45
|
+
"HealthInfo",
|
|
46
|
+
"Invoice",
|
|
47
|
+
"PaymentResult",
|
|
48
|
+
"Transaction",
|
|
49
|
+
"TransactionList",
|
|
50
|
+
"WalletInfo",
|
|
51
|
+
"WithdrawalResult",
|
|
52
|
+
# Exceptions
|
|
53
|
+
"MintbotError",
|
|
54
|
+
"AuthenticationError",
|
|
55
|
+
"InsufficientBalance",
|
|
56
|
+
"WalletNotFound",
|
|
57
|
+
"PaymentError",
|
|
58
|
+
"InvoiceError",
|
|
59
|
+
"WithdrawalError",
|
|
60
|
+
"APIError",
|
|
61
|
+
]
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""
|
|
2
|
+
mintbot.exceptions — Custom exceptions for the Mintbot SDK.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MintbotError(Exception):
|
|
7
|
+
"""Base exception for all Mintbot errors."""
|
|
8
|
+
|
|
9
|
+
def __init__(self, message: str, status_code: int | None = None, detail: str | None = None):
|
|
10
|
+
super().__init__(message)
|
|
11
|
+
self.message = message
|
|
12
|
+
self.status_code = status_code
|
|
13
|
+
self.detail = detail
|
|
14
|
+
|
|
15
|
+
def __repr__(self) -> str:
|
|
16
|
+
return f"{self.__class__.__name__}({self.message!r})"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class AuthenticationError(MintbotError):
|
|
20
|
+
"""Raised when the API key is invalid or missing."""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class InsufficientBalance(MintbotError):
|
|
24
|
+
"""Raised when the wallet does not have enough funds."""
|
|
25
|
+
|
|
26
|
+
def __init__(
|
|
27
|
+
self,
|
|
28
|
+
message: str,
|
|
29
|
+
balance_sats: int = 0,
|
|
30
|
+
required_sats: int = 0,
|
|
31
|
+
shortfall_sats: int = 0,
|
|
32
|
+
**kwargs,
|
|
33
|
+
):
|
|
34
|
+
super().__init__(message, **kwargs)
|
|
35
|
+
self.balance_sats = balance_sats
|
|
36
|
+
self.required_sats = required_sats
|
|
37
|
+
self.shortfall_sats = shortfall_sats
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class WalletNotFound(MintbotError):
|
|
41
|
+
"""Raised when a wallet ID cannot be found."""
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class PaymentError(MintbotError):
|
|
45
|
+
"""Raised when a payment fails."""
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class InvoiceError(MintbotError):
|
|
49
|
+
"""Raised when invoice creation or resolution fails."""
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class WithdrawalError(MintbotError):
|
|
53
|
+
"""Raised when a Cashu token withdrawal fails."""
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class APIError(MintbotError):
|
|
57
|
+
"""Generic API error for unexpected responses."""
|