kaleido-cli 0.1.2__py3-none-any.whl
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.
- kaleido_cli/__init__.py +3 -0
- kaleido_cli/__main__.py +6 -0
- kaleido_cli/app.py +204 -0
- kaleido_cli/commands/__init__.py +1 -0
- kaleido_cli/commands/asset.py +850 -0
- kaleido_cli/commands/channel.py +855 -0
- kaleido_cli/commands/config_cmd.py +113 -0
- kaleido_cli/commands/market.py +241 -0
- kaleido_cli/commands/node.py +874 -0
- kaleido_cli/commands/node_swap.py +274 -0
- kaleido_cli/commands/payment.py +364 -0
- kaleido_cli/commands/peer.py +108 -0
- kaleido_cli/commands/swap.py +460 -0
- kaleido_cli/commands/wallet.py +487 -0
- kaleido_cli/config.py +88 -0
- kaleido_cli/context.py +41 -0
- kaleido_cli/docker_manager.py +463 -0
- kaleido_cli/onboarding.py +275 -0
- kaleido_cli/output.py +123 -0
- kaleido_cli/utils/__init__.py +1 -0
- kaleido_cli/utils/assets.py +40 -0
- kaleido_cli/utils/channel_orders.py +822 -0
- kaleido_cli/utils/errors.py +17 -0
- kaleido_cli/utils/pairs.py +133 -0
- kaleido_cli/utils/prompts.py +102 -0
- kaleido_cli/utils/quotes.py +163 -0
- kaleido_cli/utils/swaps.py +142 -0
- kaleido_cli-0.1.2.dist-info/METADATA +416 -0
- kaleido_cli-0.1.2.dist-info/RECORD +32 -0
- kaleido_cli-0.1.2.dist-info/WHEEL +4 -0
- kaleido_cli-0.1.2.dist-info/entry_points.txt +2 -0
- kaleido_cli-0.1.2.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
"""Wallet commands — BTC balance, addresses, transactions."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
from typing import Annotated
|
|
7
|
+
|
|
8
|
+
import typer
|
|
9
|
+
from kaleido_sdk.rln import (
|
|
10
|
+
AddressResponse,
|
|
11
|
+
BackupRequest,
|
|
12
|
+
BtcBalanceResponse,
|
|
13
|
+
ChangePasswordRequest,
|
|
14
|
+
CreateUtxosRequest,
|
|
15
|
+
EstimateFeeRequest,
|
|
16
|
+
EstimateFeeResponse,
|
|
17
|
+
ListTransactionsRequest,
|
|
18
|
+
ListTransactionsResponse,
|
|
19
|
+
ListUnspentsRequest,
|
|
20
|
+
ListUnspentsResponse,
|
|
21
|
+
RestoreRequest,
|
|
22
|
+
SendBtcRequest,
|
|
23
|
+
SendBtcResponse,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
from kaleido_cli.context import get_client
|
|
27
|
+
from kaleido_cli.output import (
|
|
28
|
+
is_interactive,
|
|
29
|
+
is_json_mode,
|
|
30
|
+
output_collection,
|
|
31
|
+
output_model,
|
|
32
|
+
print_error,
|
|
33
|
+
print_json,
|
|
34
|
+
print_success,
|
|
35
|
+
)
|
|
36
|
+
from kaleido_cli.utils.errors import raise_cli_error
|
|
37
|
+
from kaleido_cli.utils.prompts import resolve_required_int, resolve_required_text
|
|
38
|
+
|
|
39
|
+
wallet_app = typer.Typer(
|
|
40
|
+
no_args_is_help=True,
|
|
41
|
+
rich_markup_mode="rich",
|
|
42
|
+
help="BTC wallet operations — balance, addresses, send, UTXOs, transactions, backup.",
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@wallet_app.command(
|
|
47
|
+
"address",
|
|
48
|
+
epilog=" [cyan]kaleido wallet address[/cyan] Get a fresh on-chain deposit address.",
|
|
49
|
+
)
|
|
50
|
+
def wallet_address() -> None:
|
|
51
|
+
"""Get a new on-chain BTC deposit address."""
|
|
52
|
+
asyncio.run(_wallet_address())
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
async def _wallet_address() -> None:
|
|
56
|
+
try:
|
|
57
|
+
client = get_client(require_node=True)
|
|
58
|
+
resp: AddressResponse = await client.rln.get_address()
|
|
59
|
+
if is_json_mode():
|
|
60
|
+
print_json(resp.model_dump())
|
|
61
|
+
else:
|
|
62
|
+
print_success(f"Address: {resp.address}")
|
|
63
|
+
except Exception as e:
|
|
64
|
+
raise_cli_error(e)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@wallet_app.command(
|
|
68
|
+
"balance",
|
|
69
|
+
epilog=(
|
|
70
|
+
"[bold]Examples[/bold]\n\n"
|
|
71
|
+
" [cyan]kaleido wallet balance[/cyan] Full balance (syncs first)\n"
|
|
72
|
+
" [cyan]kaleido wallet balance --skip-sync[/cyan] Use cached balance (faster)"
|
|
73
|
+
),
|
|
74
|
+
)
|
|
75
|
+
def wallet_balance(
|
|
76
|
+
skip_sync: Annotated[
|
|
77
|
+
bool,
|
|
78
|
+
typer.Option("--skip-sync", help="Skip blockchain sync and return cached balance."),
|
|
79
|
+
] = False,
|
|
80
|
+
) -> None:
|
|
81
|
+
"""Show BTC wallet balance (vanilla + colored UTXOs)."""
|
|
82
|
+
asyncio.run(_wallet_balance(skip_sync))
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
async def _wallet_balance(skip_sync: bool) -> None:
|
|
86
|
+
try:
|
|
87
|
+
client = get_client(require_node=True)
|
|
88
|
+
resp: BtcBalanceResponse = await client.rln.get_btc_balance(skip_sync=skip_sync)
|
|
89
|
+
if is_json_mode():
|
|
90
|
+
print_json(resp.model_dump())
|
|
91
|
+
return
|
|
92
|
+
output_model(resp, title="BTC Balance")
|
|
93
|
+
except Exception as e:
|
|
94
|
+
raise_cli_error(e)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@wallet_app.command(
|
|
98
|
+
"send",
|
|
99
|
+
epilog=(
|
|
100
|
+
"[bold]Examples[/bold]\n\n"
|
|
101
|
+
" Send 50 000 sats at default fee rate:\n"
|
|
102
|
+
" [cyan]kaleido wallet send 50000 bc1q...[/cyan]\n\n"
|
|
103
|
+
" Send with a specific fee rate:\n"
|
|
104
|
+
" [cyan]kaleido wallet send 50000 bc1q... --fee-rate 5.0[/cyan]\n\n"
|
|
105
|
+
" Skip blockchain sync before sending:\n"
|
|
106
|
+
" [cyan]kaleido wallet send 50000 bc1q... --skip-sync[/cyan]"
|
|
107
|
+
),
|
|
108
|
+
)
|
|
109
|
+
def wallet_send(
|
|
110
|
+
amount: Annotated[int | None, typer.Argument(help="Amount to send in satoshis.")] = None,
|
|
111
|
+
address: Annotated[str | None, typer.Argument(help="Destination Bitcoin address.")] = None,
|
|
112
|
+
fee_rate: Annotated[
|
|
113
|
+
int,
|
|
114
|
+
typer.Option("--fee-rate", help="Fee rate in sat/vbyte."),
|
|
115
|
+
] = 1,
|
|
116
|
+
skip_sync: Annotated[
|
|
117
|
+
bool,
|
|
118
|
+
typer.Option("--skip-sync", help="Skip blockchain sync before sending."),
|
|
119
|
+
] = False,
|
|
120
|
+
) -> None:
|
|
121
|
+
"""Send on-chain BTC."""
|
|
122
|
+
resolved_amount = resolve_required_int(amount, "Amount to send (satoshis)", "AMOUNT argument")
|
|
123
|
+
resolved_address = resolve_required_text(
|
|
124
|
+
address, "Destination Bitcoin address", "ADDRESS argument"
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
asyncio.run(_wallet_send(resolved_amount, resolved_address, fee_rate, skip_sync))
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
async def _wallet_send(amount: int, address: str, fee_rate: int, skip_sync: bool) -> None:
|
|
131
|
+
try:
|
|
132
|
+
client = get_client(require_node=True)
|
|
133
|
+
body = SendBtcRequest(
|
|
134
|
+
amount=amount,
|
|
135
|
+
address=address,
|
|
136
|
+
fee_rate=fee_rate,
|
|
137
|
+
skip_sync=skip_sync,
|
|
138
|
+
)
|
|
139
|
+
resp: SendBtcResponse = await client.rln.send_btc(body)
|
|
140
|
+
if is_json_mode():
|
|
141
|
+
print_json(resp.model_dump())
|
|
142
|
+
else:
|
|
143
|
+
print_success(f"Sent! TXID: {resp.txid}")
|
|
144
|
+
except Exception as e:
|
|
145
|
+
raise_cli_error(e)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
@wallet_app.command(
|
|
149
|
+
"utxos",
|
|
150
|
+
epilog=(
|
|
151
|
+
"[bold]Examples[/bold]\n\n"
|
|
152
|
+
" [cyan]kaleido wallet utxos[/cyan] List UTXOs (syncs first)\n"
|
|
153
|
+
" [cyan]kaleido wallet utxos --skip-sync[/cyan] Use cached UTXO data (faster)"
|
|
154
|
+
),
|
|
155
|
+
)
|
|
156
|
+
def wallet_utxos(
|
|
157
|
+
skip_sync: Annotated[
|
|
158
|
+
bool,
|
|
159
|
+
typer.Option("--skip-sync", help="Skip blockchain sync and return cached UTXOs."),
|
|
160
|
+
] = False,
|
|
161
|
+
) -> None:
|
|
162
|
+
"""List unspent transaction outputs."""
|
|
163
|
+
asyncio.run(_wallet_utxos(skip_sync))
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
async def _wallet_utxos(skip_sync: bool) -> None:
|
|
167
|
+
try:
|
|
168
|
+
client = get_client(require_node=True)
|
|
169
|
+
resp: ListUnspentsResponse = await client.rln.list_unspents(
|
|
170
|
+
ListUnspentsRequest(skip_sync=skip_sync, settled_only=False)
|
|
171
|
+
)
|
|
172
|
+
if is_json_mode():
|
|
173
|
+
print_json(resp.model_dump())
|
|
174
|
+
return
|
|
175
|
+
items = []
|
|
176
|
+
for u in resp.unspents or []:
|
|
177
|
+
items.append(
|
|
178
|
+
{
|
|
179
|
+
"outpoint": u.utxo.outpoint if u.utxo else None,
|
|
180
|
+
"btc_amount_sat": u.utxo.btc_amount if u.utxo else None,
|
|
181
|
+
"rgb_allocations": u.rgb_allocations,
|
|
182
|
+
}
|
|
183
|
+
)
|
|
184
|
+
output_collection("UTXOs", items, item_title="UTXO — {index}")
|
|
185
|
+
except Exception as e:
|
|
186
|
+
raise_cli_error(e)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
@wallet_app.command(
|
|
190
|
+
"create-utxos",
|
|
191
|
+
epilog=(
|
|
192
|
+
"[bold]Examples[/bold]\n\n"
|
|
193
|
+
" Create 5 UTXOs of default size:\n"
|
|
194
|
+
" [cyan]kaleido wallet create-utxos[/cyan]\n\n"
|
|
195
|
+
" Create 10 UTXOs of 3000 sats each:\n"
|
|
196
|
+
" [cyan]kaleido wallet create-utxos --num 10 --size 3000[/cyan]\n\n"
|
|
197
|
+
" Create UTXOs up to a total limit with custom fee rate:\n"
|
|
198
|
+
" [cyan]kaleido wallet create-utxos --up-to --num 10 --size 1000 --fee-rate 2.5[/cyan]\n\n"
|
|
199
|
+
"[dim]RGB assets require colored UTXOs to hold allocations.[/dim]"
|
|
200
|
+
),
|
|
201
|
+
)
|
|
202
|
+
def wallet_create_utxos(
|
|
203
|
+
num: Annotated[
|
|
204
|
+
int | None, typer.Option("--num", "-n", help="Number of UTXOs to create.")
|
|
205
|
+
] = None,
|
|
206
|
+
size: Annotated[
|
|
207
|
+
int | None, typer.Option("--size", help="Size of each UTXO in satoshis.")
|
|
208
|
+
] = None,
|
|
209
|
+
up_to: Annotated[
|
|
210
|
+
bool,
|
|
211
|
+
typer.Option("--up-to", help="If true, num represents total limit instead of count."),
|
|
212
|
+
] = False,
|
|
213
|
+
fee_rate: Annotated[
|
|
214
|
+
int,
|
|
215
|
+
typer.Option("--fee-rate", help="On-chain fee rate in sat/vbyte."),
|
|
216
|
+
] = 1,
|
|
217
|
+
skip_sync: Annotated[
|
|
218
|
+
bool,
|
|
219
|
+
typer.Option("--skip-sync", help="Skip blockchain sync before creating UTXOs."),
|
|
220
|
+
] = False,
|
|
221
|
+
) -> None:
|
|
222
|
+
"""Create UTXOs for RGB asset operations."""
|
|
223
|
+
if is_interactive():
|
|
224
|
+
if num is None:
|
|
225
|
+
raw = typer.prompt(
|
|
226
|
+
"[OPTIONAL] Number of UTXOs to create (Enter for node default)", default=""
|
|
227
|
+
)
|
|
228
|
+
if raw.strip():
|
|
229
|
+
num = int(raw.strip())
|
|
230
|
+
if size is None:
|
|
231
|
+
raw = typer.prompt(
|
|
232
|
+
"[OPTIONAL] Size of each UTXO in satoshis (Enter for node default)", default=""
|
|
233
|
+
)
|
|
234
|
+
if raw.strip():
|
|
235
|
+
size = int(raw.strip())
|
|
236
|
+
|
|
237
|
+
asyncio.run(
|
|
238
|
+
_wallet_create_utxos(
|
|
239
|
+
num=num,
|
|
240
|
+
size=size,
|
|
241
|
+
up_to=up_to,
|
|
242
|
+
fee_rate=fee_rate,
|
|
243
|
+
skip_sync=skip_sync,
|
|
244
|
+
)
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
async def _wallet_create_utxos(
|
|
249
|
+
num: int | None,
|
|
250
|
+
size: int | None,
|
|
251
|
+
up_to: bool,
|
|
252
|
+
fee_rate: int,
|
|
253
|
+
skip_sync: bool,
|
|
254
|
+
) -> None:
|
|
255
|
+
try:
|
|
256
|
+
client = get_client(require_node=True)
|
|
257
|
+
body = CreateUtxosRequest(
|
|
258
|
+
num=num,
|
|
259
|
+
size=size,
|
|
260
|
+
up_to=up_to,
|
|
261
|
+
fee_rate=fee_rate,
|
|
262
|
+
skip_sync=skip_sync,
|
|
263
|
+
)
|
|
264
|
+
await client.rln.create_utxos(body)
|
|
265
|
+
created_msg = f"{num} UTXO(s)" if num else "UTXOs"
|
|
266
|
+
print_success(f"Created {created_msg}.")
|
|
267
|
+
except Exception as e:
|
|
268
|
+
raise_cli_error(e)
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
@wallet_app.command(
|
|
272
|
+
"transactions",
|
|
273
|
+
epilog=(
|
|
274
|
+
"[bold]Examples[/bold]\n\n"
|
|
275
|
+
" [cyan]kaleido wallet transactions[/cyan] Full transaction list (syncs first)\n"
|
|
276
|
+
" [cyan]kaleido wallet transactions --skip-sync[/cyan] Use cached transactions (faster)"
|
|
277
|
+
),
|
|
278
|
+
)
|
|
279
|
+
def wallet_transactions(
|
|
280
|
+
skip_sync: Annotated[
|
|
281
|
+
bool,
|
|
282
|
+
typer.Option("--skip-sync", help="Skip blockchain sync and return cached transactions."),
|
|
283
|
+
] = False,
|
|
284
|
+
) -> None:
|
|
285
|
+
"""List on-chain transactions."""
|
|
286
|
+
asyncio.run(_wallet_transactions(skip_sync))
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
async def _wallet_transactions(skip_sync: bool) -> None:
|
|
290
|
+
try:
|
|
291
|
+
client = get_client(require_node=True)
|
|
292
|
+
resp: ListTransactionsResponse = await client.rln.list_transactions(
|
|
293
|
+
ListTransactionsRequest(skip_sync=skip_sync)
|
|
294
|
+
)
|
|
295
|
+
if is_json_mode():
|
|
296
|
+
print_json(resp.model_dump())
|
|
297
|
+
return
|
|
298
|
+
output_collection(
|
|
299
|
+
"Transactions",
|
|
300
|
+
[t.model_dump() for t in (resp.transactions or [])],
|
|
301
|
+
item_title="Transaction — {index}",
|
|
302
|
+
)
|
|
303
|
+
except Exception as e:
|
|
304
|
+
raise_cli_error(e)
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
@wallet_app.command(
|
|
308
|
+
"backup",
|
|
309
|
+
epilog=(
|
|
310
|
+
"[bold]Examples[/bold]\n\n"
|
|
311
|
+
" Interactive password prompt:\n"
|
|
312
|
+
" [cyan]kaleido wallet backup ~/my-backup.zip[/cyan]\n\n"
|
|
313
|
+
" Non-interactive:\n"
|
|
314
|
+
" [cyan]kaleido wallet backup /backups/node.zip --password mysecret[/cyan]"
|
|
315
|
+
),
|
|
316
|
+
)
|
|
317
|
+
def wallet_backup(
|
|
318
|
+
path: Annotated[
|
|
319
|
+
str | None, typer.Argument(help="Destination path for the backup archive.")
|
|
320
|
+
] = None,
|
|
321
|
+
password: Annotated[
|
|
322
|
+
str | None,
|
|
323
|
+
typer.Option(
|
|
324
|
+
"--password",
|
|
325
|
+
"-p",
|
|
326
|
+
hide_input=True,
|
|
327
|
+
help="Backup encryption password. Prompted if omitted.",
|
|
328
|
+
),
|
|
329
|
+
] = None,
|
|
330
|
+
) -> None:
|
|
331
|
+
"""Backup node wallet data."""
|
|
332
|
+
resolved_path: str
|
|
333
|
+
if path is not None:
|
|
334
|
+
resolved_path = path
|
|
335
|
+
elif is_interactive():
|
|
336
|
+
resolved_path = typer.prompt("Destination path for the backup archive")
|
|
337
|
+
else:
|
|
338
|
+
print_error("PATH argument is required in non-interactive mode.")
|
|
339
|
+
raise typer.Exit(1)
|
|
340
|
+
|
|
341
|
+
resolved_password: str
|
|
342
|
+
if password is not None:
|
|
343
|
+
resolved_password = password
|
|
344
|
+
else:
|
|
345
|
+
resolved_password = typer.prompt(
|
|
346
|
+
"Backup password", hide_input=True, confirmation_prompt=True
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
asyncio.run(_wallet_backup(resolved_path, resolved_password))
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
async def _wallet_backup(path: str, password: str) -> None:
|
|
353
|
+
try:
|
|
354
|
+
client = get_client(require_node=True)
|
|
355
|
+
await client.rln.backup(BackupRequest(backup_path=path, password=password))
|
|
356
|
+
print_success(f"Backup saved to {path}")
|
|
357
|
+
except Exception as e:
|
|
358
|
+
raise_cli_error(e)
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
@wallet_app.command(
|
|
362
|
+
"restore",
|
|
363
|
+
epilog=(
|
|
364
|
+
"[bold]Examples[/bold]\n\n"
|
|
365
|
+
" Interactive password prompt:\n"
|
|
366
|
+
" [cyan]kaleido wallet restore ~/my-backup.zip[/cyan]\n\n"
|
|
367
|
+
" Non-interactive:\n"
|
|
368
|
+
" [cyan]kaleido wallet restore /backups/node.zip --password mysecret[/cyan]\n\n"
|
|
369
|
+
"[bold dim]Warning:[/bold dim] Restore will overwrite the current node data."
|
|
370
|
+
),
|
|
371
|
+
)
|
|
372
|
+
def wallet_restore(
|
|
373
|
+
path: Annotated[
|
|
374
|
+
str | None, typer.Argument(help="Path to the backup archive to restore from.")
|
|
375
|
+
] = None,
|
|
376
|
+
password: Annotated[
|
|
377
|
+
str | None,
|
|
378
|
+
typer.Option(
|
|
379
|
+
"--password",
|
|
380
|
+
"-p",
|
|
381
|
+
hide_input=True,
|
|
382
|
+
help="Backup decryption password. Prompted if omitted.",
|
|
383
|
+
),
|
|
384
|
+
] = None,
|
|
385
|
+
) -> None:
|
|
386
|
+
"""Restore node wallet data from a backup."""
|
|
387
|
+
resolved_path: str
|
|
388
|
+
if path is not None:
|
|
389
|
+
resolved_path = path
|
|
390
|
+
elif is_interactive():
|
|
391
|
+
resolved_path = typer.prompt("Path to the backup archive")
|
|
392
|
+
else:
|
|
393
|
+
print_error("PATH argument is required in non-interactive mode.")
|
|
394
|
+
raise typer.Exit(1)
|
|
395
|
+
|
|
396
|
+
resolved_password: str
|
|
397
|
+
if password is not None:
|
|
398
|
+
resolved_password = password
|
|
399
|
+
else:
|
|
400
|
+
resolved_password = typer.prompt("Backup password", hide_input=True)
|
|
401
|
+
|
|
402
|
+
asyncio.run(_wallet_restore(resolved_path, resolved_password))
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
async def _wallet_restore(path: str, password: str) -> None:
|
|
406
|
+
try:
|
|
407
|
+
client = get_client(require_node=True)
|
|
408
|
+
await client.rln.restore(RestoreRequest(backup_path=path, password=password))
|
|
409
|
+
print_success(f"Restored from {path}")
|
|
410
|
+
except Exception as e:
|
|
411
|
+
raise_cli_error(e)
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
@wallet_app.command(
|
|
415
|
+
"change-password",
|
|
416
|
+
epilog=(
|
|
417
|
+
"[bold]Examples[/bold]\n\n"
|
|
418
|
+
" Interactive prompts:\n"
|
|
419
|
+
" [cyan]kaleido wallet change-password[/cyan]\n\n"
|
|
420
|
+
" Non-interactive:\n"
|
|
421
|
+
" [cyan]kaleido wallet change-password --old-password old --new-password new[/cyan]"
|
|
422
|
+
),
|
|
423
|
+
)
|
|
424
|
+
def wallet_change_password(
|
|
425
|
+
old_password: Annotated[
|
|
426
|
+
str | None,
|
|
427
|
+
typer.Option("--old-password", hide_input=True, help="Current wallet password."),
|
|
428
|
+
] = None,
|
|
429
|
+
new_password: Annotated[
|
|
430
|
+
str | None,
|
|
431
|
+
typer.Option("--new-password", hide_input=True, help="New wallet password."),
|
|
432
|
+
] = None,
|
|
433
|
+
) -> None:
|
|
434
|
+
"""Change the node wallet password."""
|
|
435
|
+
if old_password is None:
|
|
436
|
+
old_password = typer.prompt("Current password", hide_input=True)
|
|
437
|
+
if new_password is None:
|
|
438
|
+
new_password = typer.prompt("New password", hide_input=True, confirmation_prompt=True)
|
|
439
|
+
|
|
440
|
+
assert old_password is not None
|
|
441
|
+
assert new_password is not None
|
|
442
|
+
asyncio.run(_wallet_change_password(old_password, new_password))
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
async def _wallet_change_password(old_password: str, new_password: str) -> None:
|
|
446
|
+
try:
|
|
447
|
+
client = get_client(require_node=True)
|
|
448
|
+
await client.rln.change_password(
|
|
449
|
+
ChangePasswordRequest(old_password=old_password, new_password=new_password)
|
|
450
|
+
)
|
|
451
|
+
print_success("Password changed successfully.")
|
|
452
|
+
except Exception as e:
|
|
453
|
+
raise_cli_error(e)
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
@wallet_app.command(
|
|
457
|
+
"estimate-fee",
|
|
458
|
+
epilog=(
|
|
459
|
+
"[bold]Examples[/bold]\n\n"
|
|
460
|
+
" Estimate fee for confirmation within 6 blocks:\n"
|
|
461
|
+
" [cyan]kaleido wallet estimate-fee --blocks 6[/cyan]\n\n"
|
|
462
|
+
" Fast (1 block) confirmation target:\n"
|
|
463
|
+
" [cyan]kaleido wallet estimate-fee --blocks 1[/cyan]"
|
|
464
|
+
),
|
|
465
|
+
)
|
|
466
|
+
def wallet_estimate_fee(
|
|
467
|
+
blocks: Annotated[
|
|
468
|
+
int,
|
|
469
|
+
typer.Option("--blocks", "-b", help="Target confirmation in this many blocks."),
|
|
470
|
+
] = 6,
|
|
471
|
+
) -> None:
|
|
472
|
+
"""Estimate the on-chain fee rate for a target confirmation window."""
|
|
473
|
+
asyncio.run(_wallet_estimate_fee(blocks))
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
async def _wallet_estimate_fee(blocks: int) -> None:
|
|
477
|
+
try:
|
|
478
|
+
client = get_client(require_node=True)
|
|
479
|
+
resp: EstimateFeeResponse = await client.rln.estimate_fee(EstimateFeeRequest(blocks=blocks))
|
|
480
|
+
if is_json_mode():
|
|
481
|
+
print_json(resp.model_dump())
|
|
482
|
+
else:
|
|
483
|
+
print_success(
|
|
484
|
+
f"Estimated fee rate: {resp.fee_rate} sat/vbyte (target: {blocks} blocks)"
|
|
485
|
+
)
|
|
486
|
+
except Exception as e:
|
|
487
|
+
raise_cli_error(e)
|
kaleido_cli/config.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""CLI configuration management — stored in ~/.kaleido/config.json."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from dataclasses import asdict, dataclass
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
CONFIG_DIR = Path.home() / ".kaleido"
|
|
10
|
+
CONFIG_FILE = CONFIG_DIR / "config.json"
|
|
11
|
+
|
|
12
|
+
DEFAULT_API_URL = "https://api.signet.kaleidoswap.com/"
|
|
13
|
+
DEFAULT_NODE_URL = "http://localhost:3001"
|
|
14
|
+
DEFAULT_NETWORK = "mutinynet"
|
|
15
|
+
|
|
16
|
+
RLN_SIGNET_CUSTOM_NETWORK = "signetcustom"
|
|
17
|
+
MUTINYNET_ALIASES = {"mutinynet", "signetcustom", "customsignet"}
|
|
18
|
+
|
|
19
|
+
DEFAULT_BITCOIND_RPC_USERNAME = "user"
|
|
20
|
+
DEFAULT_BITCOIND_RPC_PASSWORD = "default_password"
|
|
21
|
+
DEFAULT_BITCOIND_RPC_HOST = "bitcoind.signet.kaleidoswap.com"
|
|
22
|
+
DEFAULT_BITCOIND_RPC_PORT = 38332
|
|
23
|
+
DEFAULT_INDEXER_URL = "https://esplora.signet.kaleidoswap.com"
|
|
24
|
+
DEFAULT_PROXY_ENDPOINT = "rpcs://proxy.iriswallet.com/0.2/json-rpc"
|
|
25
|
+
|
|
26
|
+
DEFAULT_REGTEST_BITCOIND_RPC_USERNAME = "user"
|
|
27
|
+
DEFAULT_REGTEST_BITCOIND_RPC_PASSWORD = "password"
|
|
28
|
+
DEFAULT_REGTEST_BITCOIND_RPC_HOST = "regtest-bitcoind.rgbtools.org"
|
|
29
|
+
DEFAULT_REGTEST_BITCOIND_RPC_PORT = 80
|
|
30
|
+
DEFAULT_REGTEST_INDEXER_URL = "electrum.rgbtools.org:50041"
|
|
31
|
+
DEFAULT_REGTEST_PROXY_ENDPOINT = "rpcs://proxy.iriswallet.com/0.2/json-rpc"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def normalize_network_name(network: str) -> str:
|
|
35
|
+
"""Normalize friendly CLI aliases to the network value expected by RLN."""
|
|
36
|
+
lowered = network.strip().lower()
|
|
37
|
+
if lowered in MUTINYNET_ALIASES:
|
|
38
|
+
return RLN_SIGNET_CUSTOM_NETWORK
|
|
39
|
+
return lowered
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@dataclass
|
|
43
|
+
class CliConfig:
|
|
44
|
+
api_url: str = DEFAULT_API_URL
|
|
45
|
+
node_url: str = DEFAULT_NODE_URL
|
|
46
|
+
network: str = DEFAULT_NETWORK
|
|
47
|
+
# Directory used to write generated compose files + volumes.
|
|
48
|
+
spawn_dir: str = "" # default: ~/.kaleido
|
|
49
|
+
|
|
50
|
+
def to_dict(self) -> dict:
|
|
51
|
+
return asdict(self)
|
|
52
|
+
|
|
53
|
+
@classmethod
|
|
54
|
+
def from_dict(cls, data: dict) -> CliConfig:
|
|
55
|
+
valid = {f for f in cls.__dataclass_fields__}
|
|
56
|
+
return cls(**{k: v for k, v in data.items() if k in valid})
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def load_config() -> CliConfig:
|
|
60
|
+
if not CONFIG_FILE.exists():
|
|
61
|
+
return CliConfig()
|
|
62
|
+
try:
|
|
63
|
+
return CliConfig.from_dict(json.loads(CONFIG_FILE.read_text()))
|
|
64
|
+
except Exception:
|
|
65
|
+
return CliConfig()
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def save_config(config: CliConfig) -> None:
|
|
69
|
+
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
|
|
70
|
+
CONFIG_FILE.write_text(json.dumps(config.to_dict(), indent=2))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# Friendly aliases for `kaleido config set <key> <value>`
|
|
74
|
+
_KEY_ALIASES: dict[str, str] = {
|
|
75
|
+
"node-url": "node_url",
|
|
76
|
+
"api-url": "api_url",
|
|
77
|
+
"network": "network",
|
|
78
|
+
"spawn-dir": "spawn_dir",
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def set_config_key(key: str, value: str) -> None:
|
|
83
|
+
field_name = _KEY_ALIASES.get(key, key)
|
|
84
|
+
config = load_config()
|
|
85
|
+
if not hasattr(config, field_name):
|
|
86
|
+
raise KeyError(f"Unknown config key: {key!r}. Valid keys: {list(_KEY_ALIASES)}")
|
|
87
|
+
object.__setattr__(config, field_name, value)
|
|
88
|
+
save_config(config)
|
kaleido_cli/context.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Global application context and state management."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
from kaleido_sdk import KaleidoClient
|
|
7
|
+
|
|
8
|
+
from .config import CliConfig
|
|
9
|
+
from .output import print_error
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class _State:
|
|
13
|
+
config: CliConfig = None # type: ignore[assignment]
|
|
14
|
+
node_url: str | None = None
|
|
15
|
+
api_url: str | None = None
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
state = _State()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def get_client(
|
|
22
|
+
*,
|
|
23
|
+
require_node: bool = False,
|
|
24
|
+
timeout: float | None = None,
|
|
25
|
+
max_retries: int = 3,
|
|
26
|
+
) -> KaleidoClient:
|
|
27
|
+
"""Build a KaleidoClient from current state."""
|
|
28
|
+
node_url = state.node_url or state.config.node_url or None
|
|
29
|
+
api_url = state.api_url or state.config.api_url
|
|
30
|
+
|
|
31
|
+
if require_node and not node_url:
|
|
32
|
+
print_error("Node URL not configured.")
|
|
33
|
+
print_error("Use --node-url or: kaleido config set node-url http://localhost:3001")
|
|
34
|
+
raise typer.Exit(1)
|
|
35
|
+
|
|
36
|
+
return KaleidoClient.create(
|
|
37
|
+
base_url=api_url,
|
|
38
|
+
node_url=node_url,
|
|
39
|
+
timeout=timeout or 30.0,
|
|
40
|
+
max_retries=max_retries,
|
|
41
|
+
)
|