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,850 @@
|
|
|
1
|
+
"""RGB asset commands — list, issue, send, invoices, transfers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import time
|
|
7
|
+
from typing import Annotated
|
|
8
|
+
|
|
9
|
+
import typer
|
|
10
|
+
from kaleido_sdk.rln import (
|
|
11
|
+
AssetBalanceRequest,
|
|
12
|
+
AssetBalanceResponse,
|
|
13
|
+
AssetFilterAnyOrNone,
|
|
14
|
+
AssetFilterId,
|
|
15
|
+
AssetFilterNone,
|
|
16
|
+
AssetMetadataRequest,
|
|
17
|
+
AssetMetadataResponse,
|
|
18
|
+
AssignmentFungible,
|
|
19
|
+
FailTransfersRequest,
|
|
20
|
+
FailTransfersResponse,
|
|
21
|
+
GetAssetMediaRequest,
|
|
22
|
+
GetAssetMediaResponse,
|
|
23
|
+
IssueAssetCFARequest,
|
|
24
|
+
IssueAssetCFAResponse,
|
|
25
|
+
IssueAssetNIARequest,
|
|
26
|
+
IssueAssetNIAResponse,
|
|
27
|
+
IssueAssetUDARequest,
|
|
28
|
+
IssueAssetUDAResponse,
|
|
29
|
+
ListAssetsResponse,
|
|
30
|
+
ListTransfersRequest,
|
|
31
|
+
ListTransfersResponse,
|
|
32
|
+
Recipient,
|
|
33
|
+
RefreshRequest,
|
|
34
|
+
RgbInvoiceRequest,
|
|
35
|
+
RgbInvoiceResponse,
|
|
36
|
+
SendRgbRequest,
|
|
37
|
+
SendRgbResponse,
|
|
38
|
+
WitnessData,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
from kaleido_cli.config import DEFAULT_PROXY_ENDPOINT
|
|
42
|
+
from kaleido_cli.context import get_client
|
|
43
|
+
from kaleido_cli.output import (
|
|
44
|
+
is_interactive,
|
|
45
|
+
is_json_mode,
|
|
46
|
+
output_collection,
|
|
47
|
+
output_model,
|
|
48
|
+
print_error,
|
|
49
|
+
print_json,
|
|
50
|
+
print_success,
|
|
51
|
+
)
|
|
52
|
+
from kaleido_cli.utils.assets import resolve_asset_metadata, sha256_file
|
|
53
|
+
from kaleido_cli.utils.errors import raise_cli_error
|
|
54
|
+
from kaleido_cli.utils.prompts import resolve_required_int, resolve_required_text
|
|
55
|
+
|
|
56
|
+
asset_app = typer.Typer(
|
|
57
|
+
no_args_is_help=True,
|
|
58
|
+
rich_markup_mode="rich",
|
|
59
|
+
help="Manage RGB assets — list, issue, send (single or batch), invoices, and transfer history.",
|
|
60
|
+
)
|
|
61
|
+
issue_app = typer.Typer(
|
|
62
|
+
no_args_is_help=True,
|
|
63
|
+
rich_markup_mode="rich",
|
|
64
|
+
help="Issue new RGB assets by schema: NIA, CFA, or UDA.",
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
asset_app.add_typer(issue_app, name="issue")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@asset_app.command(
|
|
71
|
+
"list",
|
|
72
|
+
epilog=(
|
|
73
|
+
" [cyan]kaleido asset list[/cyan] Table view\n"
|
|
74
|
+
" [cyan]kaleido --json asset list[/cyan] Raw JSON output"
|
|
75
|
+
),
|
|
76
|
+
)
|
|
77
|
+
def asset_list() -> None:
|
|
78
|
+
"""List all RGB assets held by the node."""
|
|
79
|
+
asyncio.run(_asset_list())
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
async def _asset_list() -> None:
|
|
83
|
+
try:
|
|
84
|
+
client = get_client(require_node=True)
|
|
85
|
+
resp: ListAssetsResponse = await client.rln.list_assets()
|
|
86
|
+
if is_json_mode():
|
|
87
|
+
print_json(resp.model_dump())
|
|
88
|
+
return
|
|
89
|
+
items = []
|
|
90
|
+
if resp.nia:
|
|
91
|
+
for asset in resp.nia:
|
|
92
|
+
items.append({**asset.model_dump(), "schema": "NIA"})
|
|
93
|
+
if resp.cfa:
|
|
94
|
+
for asset in resp.cfa:
|
|
95
|
+
items.append({**asset.model_dump(), "schema": "CFA"})
|
|
96
|
+
if resp.uda:
|
|
97
|
+
for asset in resp.uda:
|
|
98
|
+
items.append({**asset.model_dump(), "schema": "UDA"})
|
|
99
|
+
output_collection("RGB Assets", items, item_title="RGB Asset — {index}")
|
|
100
|
+
except Exception as e:
|
|
101
|
+
raise_cli_error(e)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@asset_app.command("balance")
|
|
105
|
+
def asset_balance(
|
|
106
|
+
asset_id: Annotated[str, typer.Argument(help="RGB asset ID.")],
|
|
107
|
+
) -> None:
|
|
108
|
+
"""Show balance for a specific RGB asset."""
|
|
109
|
+
asyncio.run(_asset_balance(asset_id))
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
async def _asset_balance(asset_id: str) -> None:
|
|
113
|
+
try:
|
|
114
|
+
client = get_client(require_node=True)
|
|
115
|
+
resp: AssetBalanceResponse = await client.rln.get_asset_balance(
|
|
116
|
+
AssetBalanceRequest(asset_id=asset_id)
|
|
117
|
+
)
|
|
118
|
+
if is_json_mode():
|
|
119
|
+
print_json(resp.model_dump())
|
|
120
|
+
else:
|
|
121
|
+
output_model(resp, title=f"Balance — {asset_id[:20]}…")
|
|
122
|
+
except Exception as e:
|
|
123
|
+
raise_cli_error(e)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
@asset_app.command("metadata")
|
|
127
|
+
def asset_metadata(
|
|
128
|
+
asset_id: Annotated[str, typer.Argument(help="RGB asset ID.")],
|
|
129
|
+
) -> None:
|
|
130
|
+
"""Show metadata for a specific RGB asset."""
|
|
131
|
+
asyncio.run(_asset_metadata(asset_id))
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
async def _asset_metadata(asset_id: str) -> None:
|
|
135
|
+
try:
|
|
136
|
+
client = get_client(require_node=True)
|
|
137
|
+
resp: AssetMetadataResponse = await client.rln.get_asset_metadata(
|
|
138
|
+
AssetMetadataRequest(asset_id=asset_id)
|
|
139
|
+
)
|
|
140
|
+
if is_json_mode():
|
|
141
|
+
print_json(resp.model_dump())
|
|
142
|
+
else:
|
|
143
|
+
output_model(resp, title=f"Metadata — {asset_id[:20]}…")
|
|
144
|
+
except Exception as e:
|
|
145
|
+
raise_cli_error(e)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
@issue_app.command(
|
|
149
|
+
"nia",
|
|
150
|
+
epilog=(
|
|
151
|
+
"[bold]Examples[/bold]\n\n"
|
|
152
|
+
" Issue 1 000 000 USDT tokens with 6 decimal places:\n"
|
|
153
|
+
' [cyan]kaleido asset issue nia --name "Tether USD" --ticker USDT --supply 1000000 --precision 6[/cyan]\n\n'
|
|
154
|
+
" Issue a simple whole-unit token:\n"
|
|
155
|
+
" [cyan]kaleido asset issue nia --name MyToken --ticker MTK --supply 21000000[/cyan]\n\n"
|
|
156
|
+
"[dim]NIA = Non-Inflatable Asset (fixed-supply fungible token).[/dim]"
|
|
157
|
+
),
|
|
158
|
+
)
|
|
159
|
+
def asset_issue_nia(
|
|
160
|
+
name: Annotated[
|
|
161
|
+
str | None,
|
|
162
|
+
typer.Option("--name", help="Human-readable asset name."),
|
|
163
|
+
] = None,
|
|
164
|
+
ticker: Annotated[
|
|
165
|
+
str | None,
|
|
166
|
+
typer.Option("--ticker", help="Short ticker symbol, e.g. USDT."),
|
|
167
|
+
] = None,
|
|
168
|
+
supply: Annotated[
|
|
169
|
+
int | None,
|
|
170
|
+
typer.Option("--supply", help="Total supply expressed in the smallest raw unit."),
|
|
171
|
+
] = None,
|
|
172
|
+
precision: Annotated[
|
|
173
|
+
int,
|
|
174
|
+
typer.Option("--precision", help="Number of decimal places (0 = whole units)."),
|
|
175
|
+
] = 0,
|
|
176
|
+
) -> None:
|
|
177
|
+
"""Issue a new NIA (Non-Inflatable Asset) RGB token."""
|
|
178
|
+
resolved_name = resolve_required_text(name, "Asset name", "--name")
|
|
179
|
+
resolved_ticker = resolve_required_text(ticker, "Ticker symbol (e.g. USDT)", "--ticker")
|
|
180
|
+
resolved_supply = resolve_required_int(supply, "Total supply (raw units)", "--supply")
|
|
181
|
+
|
|
182
|
+
if is_interactive():
|
|
183
|
+
precision = typer.prompt("[OPTIONAL] Decimal places (0 = whole units)", default=0, type=int)
|
|
184
|
+
|
|
185
|
+
asyncio.run(_issue_nia(resolved_name, resolved_ticker, resolved_supply, precision))
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
async def _issue_nia(name: str, ticker: str, supply: int, precision: int) -> None:
|
|
189
|
+
try:
|
|
190
|
+
client = get_client(require_node=True)
|
|
191
|
+
resp: IssueAssetNIAResponse = await client.rln.issue_asset_nia(
|
|
192
|
+
IssueAssetNIARequest(name=name, ticker=ticker, amounts=[supply], precision=precision)
|
|
193
|
+
)
|
|
194
|
+
if is_json_mode():
|
|
195
|
+
print_json(resp.model_dump())
|
|
196
|
+
else:
|
|
197
|
+
print_success(f"NIA asset issued: {resp.asset.asset_id}")
|
|
198
|
+
output_model(resp, title="Issued Asset")
|
|
199
|
+
except Exception as e:
|
|
200
|
+
raise_cli_error(e)
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
@issue_app.command(
|
|
204
|
+
"cfa",
|
|
205
|
+
epilog=(
|
|
206
|
+
"[bold]Examples[/bold]\n\n"
|
|
207
|
+
" Basic CFA with no media:\n"
|
|
208
|
+
' [cyan]kaleido asset issue cfa --name "My NFT" --supply 1[/cyan]\n\n'
|
|
209
|
+
" With description and attached media file:\n"
|
|
210
|
+
' [cyan]kaleido asset issue cfa --name "Art Piece" --supply 100 --description "Limited series" --file ./art.png[/cyan]\n\n'
|
|
211
|
+
"[dim]CFA = Collectible Fungible Asset.[/dim]"
|
|
212
|
+
),
|
|
213
|
+
)
|
|
214
|
+
def asset_issue_cfa(
|
|
215
|
+
name: Annotated[
|
|
216
|
+
str | None,
|
|
217
|
+
typer.Option("--name", help="Asset name."),
|
|
218
|
+
] = None,
|
|
219
|
+
supply: Annotated[
|
|
220
|
+
int | None,
|
|
221
|
+
typer.Option("--supply", help="Total supply in raw units."),
|
|
222
|
+
] = None,
|
|
223
|
+
description: Annotated[
|
|
224
|
+
str | None,
|
|
225
|
+
typer.Option("--description", help="Optional description shown in wallets."),
|
|
226
|
+
] = None,
|
|
227
|
+
file_path: Annotated[
|
|
228
|
+
str | None,
|
|
229
|
+
typer.Option("--file", help="Path to a media file (image, etc.) to embed."),
|
|
230
|
+
] = None,
|
|
231
|
+
precision: Annotated[
|
|
232
|
+
int,
|
|
233
|
+
typer.Option("--precision", help="Number of decimal places (0 = whole units)."),
|
|
234
|
+
] = 0,
|
|
235
|
+
) -> None:
|
|
236
|
+
"""Issue a new CFA (Collectible Fungible Asset) RGB token."""
|
|
237
|
+
resolved_name = resolve_required_text(name, "Asset name", "--name")
|
|
238
|
+
resolved_supply = resolve_required_int(supply, "Total supply (raw units)", "--supply")
|
|
239
|
+
|
|
240
|
+
description, file_path = resolve_asset_metadata(description, file_path)
|
|
241
|
+
if is_interactive():
|
|
242
|
+
precision = typer.prompt("[OPTIONAL] Decimal places (0 = whole units)", default=0, type=int)
|
|
243
|
+
|
|
244
|
+
asyncio.run(_issue_cfa(resolved_name, resolved_supply, description, file_path, precision))
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
async def _issue_cfa(
|
|
248
|
+
name: str,
|
|
249
|
+
supply: int,
|
|
250
|
+
description: str | None,
|
|
251
|
+
file_path: str | None,
|
|
252
|
+
precision: int,
|
|
253
|
+
) -> None:
|
|
254
|
+
try:
|
|
255
|
+
client = get_client(require_node=True)
|
|
256
|
+
body = IssueAssetCFARequest(
|
|
257
|
+
name=name,
|
|
258
|
+
amounts=[supply],
|
|
259
|
+
precision=precision,
|
|
260
|
+
details=description,
|
|
261
|
+
file_digest=sha256_file(file_path),
|
|
262
|
+
)
|
|
263
|
+
resp: IssueAssetCFAResponse = await client.rln.issue_asset_cfa(body)
|
|
264
|
+
if is_json_mode():
|
|
265
|
+
print_json(resp.model_dump())
|
|
266
|
+
else:
|
|
267
|
+
print_success(f"CFA asset issued: {resp.asset.asset_id}")
|
|
268
|
+
output_model(resp, title="Issued Asset")
|
|
269
|
+
except Exception as e:
|
|
270
|
+
raise_cli_error(e)
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
@asset_app.command(
|
|
274
|
+
"invoice",
|
|
275
|
+
epilog=(
|
|
276
|
+
"[bold]Examples[/bold]\n\n"
|
|
277
|
+
" Request any amount of an asset:\n"
|
|
278
|
+
" [cyan]kaleido asset invoice rgb:abc123...[/cyan]\n\n"
|
|
279
|
+
" Request exactly 500 units:\n"
|
|
280
|
+
" [cyan]kaleido asset invoice rgb:abc123... --amount 500[/cyan]\n\n"
|
|
281
|
+
" With expiration time (1 hour):\n"
|
|
282
|
+
" [cyan]kaleido asset invoice rgb:abc123... --amount 500 --duration 3600[/cyan]\n\n"
|
|
283
|
+
" With minimum confirmations:\n"
|
|
284
|
+
" [cyan]kaleido asset invoice rgb:abc123... --amount 500 --min-confirmations 3[/cyan]"
|
|
285
|
+
),
|
|
286
|
+
)
|
|
287
|
+
def asset_invoice(
|
|
288
|
+
asset_id: Annotated[str | None, typer.Argument(help="RGB asset ID to receive.")] = None,
|
|
289
|
+
amount: Annotated[
|
|
290
|
+
int | None,
|
|
291
|
+
typer.Option(
|
|
292
|
+
"--amount",
|
|
293
|
+
"-a",
|
|
294
|
+
help="Amount to request (raw units). Omit for any-amount invoice.",
|
|
295
|
+
),
|
|
296
|
+
] = None,
|
|
297
|
+
min_confirmations: Annotated[
|
|
298
|
+
int,
|
|
299
|
+
typer.Option(
|
|
300
|
+
"--min-confirmations",
|
|
301
|
+
help="Minimum number of confirmations required for the transfer.",
|
|
302
|
+
),
|
|
303
|
+
] = 0,
|
|
304
|
+
duration_seconds: Annotated[
|
|
305
|
+
int | None,
|
|
306
|
+
typer.Option(
|
|
307
|
+
"--duration",
|
|
308
|
+
help="Invoice validity duration in seconds.",
|
|
309
|
+
),
|
|
310
|
+
] = None,
|
|
311
|
+
transport_endpoints: Annotated[
|
|
312
|
+
list[str],
|
|
313
|
+
typer.Option(
|
|
314
|
+
"--transport-endpoint",
|
|
315
|
+
help="RGB proxy endpoint(s) to advertise on the invoice; can be repeated.",
|
|
316
|
+
),
|
|
317
|
+
] = [],
|
|
318
|
+
witness: Annotated[
|
|
319
|
+
bool,
|
|
320
|
+
typer.Option(
|
|
321
|
+
"--witness/--no-witness",
|
|
322
|
+
help="Use witness-based transaction.",
|
|
323
|
+
),
|
|
324
|
+
] = False,
|
|
325
|
+
) -> None:
|
|
326
|
+
"""Create an RGB invoice to receive assets."""
|
|
327
|
+
resolved_asset_id = resolve_required_text(
|
|
328
|
+
asset_id, "RGB asset ID (rgb:...)", "ASSET_ID argument"
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
if is_interactive() and amount is None:
|
|
332
|
+
raw = typer.prompt(
|
|
333
|
+
"[OPTIONAL] Amount to request (Enter for any-amount invoice)", default=""
|
|
334
|
+
)
|
|
335
|
+
if raw.strip():
|
|
336
|
+
amount = int(raw.strip())
|
|
337
|
+
|
|
338
|
+
asyncio.run(
|
|
339
|
+
_asset_invoice(
|
|
340
|
+
resolved_asset_id,
|
|
341
|
+
amount,
|
|
342
|
+
min_confirmations,
|
|
343
|
+
duration_seconds,
|
|
344
|
+
transport_endpoints,
|
|
345
|
+
witness,
|
|
346
|
+
)
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
async def _asset_invoice(
|
|
351
|
+
asset_id: str,
|
|
352
|
+
amount: int | None,
|
|
353
|
+
min_confirmations: int,
|
|
354
|
+
duration_seconds: int | None,
|
|
355
|
+
transport_endpoints: list[str],
|
|
356
|
+
witness: bool,
|
|
357
|
+
) -> None:
|
|
358
|
+
expiration_timestamp = int(time.time()) + (duration_seconds or 86400)
|
|
359
|
+
endpoints = transport_endpoints or [DEFAULT_PROXY_ENDPOINT]
|
|
360
|
+
try:
|
|
361
|
+
client = get_client(require_node=True)
|
|
362
|
+
resp: RgbInvoiceResponse = await client.rln.create_rgb_invoice(
|
|
363
|
+
RgbInvoiceRequest(
|
|
364
|
+
asset_id=asset_id,
|
|
365
|
+
assignment=(
|
|
366
|
+
AssignmentFungible(type="Fungible", value=amount)
|
|
367
|
+
if amount is not None
|
|
368
|
+
else None
|
|
369
|
+
),
|
|
370
|
+
min_confirmations=min_confirmations,
|
|
371
|
+
expiration_timestamp=expiration_timestamp,
|
|
372
|
+
transport_endpoints=endpoints,
|
|
373
|
+
witness=witness,
|
|
374
|
+
)
|
|
375
|
+
)
|
|
376
|
+
if is_json_mode():
|
|
377
|
+
print_json(resp.model_dump())
|
|
378
|
+
else:
|
|
379
|
+
print_success(f"Invoice: {resp.invoice}")
|
|
380
|
+
except Exception as e:
|
|
381
|
+
raise_cli_error(e)
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
@asset_app.command(
|
|
385
|
+
"send",
|
|
386
|
+
epilog=(
|
|
387
|
+
"[bold]Examples[/bold]\n\n"
|
|
388
|
+
" Send 100 units to an RGB invoice:\n"
|
|
389
|
+
" [cyan]kaleido asset send rgb:abc123... 100 rgb:invoice...[/cyan]\n\n"
|
|
390
|
+
" With a custom on-chain fee rate:\n"
|
|
391
|
+
" [cyan]kaleido asset send rgb:abc123... 100 rgb:invoice... --fee-rate 3.0[/cyan]\n\n"
|
|
392
|
+
" Mark as donation with minimum confirmations:\n"
|
|
393
|
+
" [cyan]kaleido asset send rgb:abc123... 100 rgb:invoice... --donation --min-confirmations 3[/cyan]\n\n"
|
|
394
|
+
" Skip sync before sending:\n"
|
|
395
|
+
" [cyan]kaleido asset send rgb:abc123... 100 rgb:invoice... --skip-sync[/cyan]"
|
|
396
|
+
),
|
|
397
|
+
)
|
|
398
|
+
def asset_send(
|
|
399
|
+
asset_id: Annotated[str | None, typer.Argument(help="RGB asset ID to send.")] = None,
|
|
400
|
+
amount: Annotated[int | None, typer.Argument(help="Amount to send in raw asset units.")] = None,
|
|
401
|
+
invoice: Annotated[str | None, typer.Argument(help="Recipient RGB invoice.")] = None,
|
|
402
|
+
fee_rate: Annotated[
|
|
403
|
+
int,
|
|
404
|
+
typer.Option(
|
|
405
|
+
"--fee-rate",
|
|
406
|
+
help="On-chain fee rate in sat/vbyte.",
|
|
407
|
+
),
|
|
408
|
+
] = 1,
|
|
409
|
+
min_confirmations: Annotated[
|
|
410
|
+
int,
|
|
411
|
+
typer.Option(
|
|
412
|
+
"--min-confirmations",
|
|
413
|
+
help="Minimum number of confirmations required for the transfer.",
|
|
414
|
+
),
|
|
415
|
+
] = 0,
|
|
416
|
+
donation: Annotated[
|
|
417
|
+
bool,
|
|
418
|
+
typer.Option(
|
|
419
|
+
"--donation",
|
|
420
|
+
help="Mark this transfer as a donation.",
|
|
421
|
+
),
|
|
422
|
+
] = False,
|
|
423
|
+
transport_endpoints: Annotated[
|
|
424
|
+
list[str],
|
|
425
|
+
typer.Option(
|
|
426
|
+
"--transport-endpoint",
|
|
427
|
+
help="Transport endpoint(s) for the recipient; can be repeated.",
|
|
428
|
+
),
|
|
429
|
+
] = [],
|
|
430
|
+
witness_amount_sat: Annotated[
|
|
431
|
+
int | None,
|
|
432
|
+
typer.Option("--witness-amount-sat", help="Optional witness UTXO amount in satoshis."),
|
|
433
|
+
] = None,
|
|
434
|
+
witness_blinding: Annotated[
|
|
435
|
+
int | None,
|
|
436
|
+
typer.Option("--witness-blinding", help="Optional witness blinding factor."),
|
|
437
|
+
] = None,
|
|
438
|
+
skip_sync: Annotated[
|
|
439
|
+
bool,
|
|
440
|
+
typer.Option(
|
|
441
|
+
"--skip-sync",
|
|
442
|
+
help="Skip syncing before sending the transfer.",
|
|
443
|
+
),
|
|
444
|
+
] = False,
|
|
445
|
+
) -> None:
|
|
446
|
+
"""Send RGB assets to an invoice."""
|
|
447
|
+
resolved_asset_id = resolve_required_text(
|
|
448
|
+
asset_id, "RGB asset ID (rgb:...)", "ASSET_ID argument"
|
|
449
|
+
)
|
|
450
|
+
resolved_amount = resolve_required_int(amount, "Amount to send (raw units)", "AMOUNT argument")
|
|
451
|
+
resolved_invoice = resolve_required_text(invoice, "Recipient RGB invoice", "INVOICE argument")
|
|
452
|
+
|
|
453
|
+
asyncio.run(
|
|
454
|
+
_asset_send(
|
|
455
|
+
resolved_asset_id,
|
|
456
|
+
resolved_amount,
|
|
457
|
+
resolved_invoice,
|
|
458
|
+
fee_rate,
|
|
459
|
+
min_confirmations,
|
|
460
|
+
donation,
|
|
461
|
+
transport_endpoints,
|
|
462
|
+
witness_amount_sat,
|
|
463
|
+
witness_blinding,
|
|
464
|
+
skip_sync,
|
|
465
|
+
)
|
|
466
|
+
)
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
async def _asset_send(
|
|
470
|
+
asset_id: str,
|
|
471
|
+
amount: int,
|
|
472
|
+
invoice: str,
|
|
473
|
+
fee_rate: int,
|
|
474
|
+
min_confirmations: int,
|
|
475
|
+
donation: bool,
|
|
476
|
+
transport_endpoints: list[str],
|
|
477
|
+
witness_amount_sat: int | None,
|
|
478
|
+
witness_blinding: int | None,
|
|
479
|
+
skip_sync: bool,
|
|
480
|
+
) -> None:
|
|
481
|
+
try:
|
|
482
|
+
client = get_client(require_node=True)
|
|
483
|
+
witness_data = None
|
|
484
|
+
if witness_amount_sat is not None:
|
|
485
|
+
witness_data = WitnessData(amount_sat=witness_amount_sat, blinding=witness_blinding)
|
|
486
|
+
body = SendRgbRequest(
|
|
487
|
+
recipient_map={
|
|
488
|
+
asset_id: [
|
|
489
|
+
Recipient(
|
|
490
|
+
recipient_id=invoice,
|
|
491
|
+
witness_data=witness_data,
|
|
492
|
+
assignment=AssignmentFungible(type="Fungible", value=amount),
|
|
493
|
+
transport_endpoints=transport_endpoints,
|
|
494
|
+
)
|
|
495
|
+
]
|
|
496
|
+
},
|
|
497
|
+
fee_rate=fee_rate,
|
|
498
|
+
min_confirmations=min_confirmations,
|
|
499
|
+
donation=donation,
|
|
500
|
+
expiration_timestamp=int(time.time()) + 86400,
|
|
501
|
+
)
|
|
502
|
+
resp: SendRgbResponse = await client.rln.send_rgb(body)
|
|
503
|
+
if is_json_mode():
|
|
504
|
+
print_json(resp.model_dump())
|
|
505
|
+
else:
|
|
506
|
+
print_success(f"Sent! TXID: {resp.txid}")
|
|
507
|
+
except Exception as e:
|
|
508
|
+
raise_cli_error(e)
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
@asset_app.command(
|
|
512
|
+
"send-batch",
|
|
513
|
+
epilog=(
|
|
514
|
+
"[bold]Examples[/bold]\n\n"
|
|
515
|
+
" Batch send from JSON file:\n"
|
|
516
|
+
" [cyan]kaleido asset send-batch batch.json[/cyan]\n\n"
|
|
517
|
+
"[bold]JSON format example:[/bold]\n"
|
|
518
|
+
"{\n"
|
|
519
|
+
' "recipient_map": {\n'
|
|
520
|
+
' "rgb:asset1...": [\n'
|
|
521
|
+
' {"recipient_id": "rgb:invoice1...", "assignment": {"type": "Fungible", "value": 100}},\n'
|
|
522
|
+
' {"recipient_id": "rgb:invoice2...", "assignment": {"type": "Fungible", "value": 200}}\n'
|
|
523
|
+
" ],\n"
|
|
524
|
+
' "rgb:asset2...": [\n'
|
|
525
|
+
' {"recipient_id": "rgb:invoice3...", "assignment": {"type": "Fungible", "value": 50}}\n'
|
|
526
|
+
" ]\n"
|
|
527
|
+
" },\n"
|
|
528
|
+
' "fee_rate": 2,\n'
|
|
529
|
+
' "min_confirmations": 3,\n'
|
|
530
|
+
' "donation": false,\n'
|
|
531
|
+
' "skip_sync": false\n'
|
|
532
|
+
"}"
|
|
533
|
+
),
|
|
534
|
+
)
|
|
535
|
+
def asset_send_batch(
|
|
536
|
+
json_file: Annotated[str, typer.Argument(help="Path to JSON file with batch transfer data.")],
|
|
537
|
+
) -> None:
|
|
538
|
+
"""Send RGB assets to multiple recipients in a single transaction."""
|
|
539
|
+
asyncio.run(_asset_send_batch(json_file))
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
async def _asset_send_batch(json_file: str) -> None:
|
|
543
|
+
import json
|
|
544
|
+
from pathlib import Path
|
|
545
|
+
|
|
546
|
+
try:
|
|
547
|
+
path = Path(json_file).expanduser().resolve()
|
|
548
|
+
if not path.exists():
|
|
549
|
+
print_error(f"File not found: {json_file}")
|
|
550
|
+
raise typer.Exit(1)
|
|
551
|
+
|
|
552
|
+
with open(path) as f:
|
|
553
|
+
data = json.load(f)
|
|
554
|
+
|
|
555
|
+
client = get_client(require_node=True)
|
|
556
|
+
|
|
557
|
+
recipient_map = {}
|
|
558
|
+
for asset_id, recipients in data.get("recipient_map", {}).items():
|
|
559
|
+
recipient_map[asset_id] = [
|
|
560
|
+
Recipient.model_validate(recipient) for recipient in recipients
|
|
561
|
+
]
|
|
562
|
+
|
|
563
|
+
body = SendRgbRequest(
|
|
564
|
+
recipient_map=recipient_map,
|
|
565
|
+
fee_rate=data.get("fee_rate", 1),
|
|
566
|
+
min_confirmations=data.get("min_confirmations", 0),
|
|
567
|
+
donation=bool(data.get("donation", False)),
|
|
568
|
+
expiration_timestamp=int(time.time()) + int(data.get("duration_seconds", 86400)),
|
|
569
|
+
)
|
|
570
|
+
|
|
571
|
+
resp: SendRgbResponse = await client.rln.send_rgb(body)
|
|
572
|
+
if is_json_mode():
|
|
573
|
+
print_json(resp.model_dump())
|
|
574
|
+
else:
|
|
575
|
+
total_recipients = sum(len(recipients) for recipients in recipient_map.values())
|
|
576
|
+
print_success(f"Batch send complete! Sent to {total_recipients} recipient(s)")
|
|
577
|
+
print_success(f"TXID: {resp.txid}")
|
|
578
|
+
except json.JSONDecodeError as e:
|
|
579
|
+
print_error(f"Invalid JSON: {e}")
|
|
580
|
+
raise typer.Exit(1)
|
|
581
|
+
except Exception as e:
|
|
582
|
+
raise_cli_error(e)
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
@asset_app.command(
|
|
586
|
+
"transfers",
|
|
587
|
+
epilog=(
|
|
588
|
+
" [cyan]kaleido asset transfers[/cyan] All transfers\n"
|
|
589
|
+
" [cyan]kaleido asset transfers rgb:abc123...[/cyan] Filtered by asset\n"
|
|
590
|
+
" [cyan]kaleido asset transfers --no-asset[/cyan] Transfers without an asset\n"
|
|
591
|
+
" [cyan]kaleido asset transfers --txid 47ee0f...[/cyan] Transfers in one transaction"
|
|
592
|
+
),
|
|
593
|
+
)
|
|
594
|
+
def asset_transfers(
|
|
595
|
+
asset_id: Annotated[
|
|
596
|
+
str | None,
|
|
597
|
+
typer.Argument(help="RGB asset ID to list transfers for. Omit for all transfers."),
|
|
598
|
+
] = None,
|
|
599
|
+
no_asset: Annotated[
|
|
600
|
+
bool,
|
|
601
|
+
typer.Option("--no-asset", help="Only transfers not bound to an asset."),
|
|
602
|
+
] = False,
|
|
603
|
+
txid: Annotated[
|
|
604
|
+
str | None,
|
|
605
|
+
typer.Option("--txid", help="Only transfers belonging to this transaction."),
|
|
606
|
+
] = None,
|
|
607
|
+
) -> None:
|
|
608
|
+
"""List RGB transfers, optionally filtered by asset or transaction."""
|
|
609
|
+
if asset_id and no_asset:
|
|
610
|
+
print_error("Pass either ASSET_ID or --no-asset, not both.")
|
|
611
|
+
raise typer.Exit(1)
|
|
612
|
+
asyncio.run(_asset_transfers(asset_id, no_asset, txid))
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
def _transfer_filter(
|
|
616
|
+
asset_id: str | None, no_asset: bool
|
|
617
|
+
) -> AssetFilterId | AssetFilterNone | AssetFilterAnyOrNone:
|
|
618
|
+
if asset_id:
|
|
619
|
+
return AssetFilterId(type="Id", value=asset_id)
|
|
620
|
+
if no_asset:
|
|
621
|
+
return AssetFilterNone(type="None")
|
|
622
|
+
return AssetFilterAnyOrNone(type="AnyOrNone")
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
async def _asset_transfers(asset_id: str | None, no_asset: bool, txid: str | None) -> None:
|
|
626
|
+
try:
|
|
627
|
+
client = get_client(require_node=True)
|
|
628
|
+
resp: ListTransfersResponse = await client.rln.list_transfers(
|
|
629
|
+
ListTransfersRequest(asset_filter=_transfer_filter(asset_id, no_asset), txid=txid)
|
|
630
|
+
)
|
|
631
|
+
if is_json_mode():
|
|
632
|
+
print_json(resp.model_dump())
|
|
633
|
+
return
|
|
634
|
+
items = []
|
|
635
|
+
for t in resp.transfers or []:
|
|
636
|
+
payload = t.model_dump()
|
|
637
|
+
payload["amount"] = (
|
|
638
|
+
t.requested_assignment.value
|
|
639
|
+
if isinstance(t.requested_assignment, AssignmentFungible)
|
|
640
|
+
else None
|
|
641
|
+
)
|
|
642
|
+
items.append(payload)
|
|
643
|
+
output_collection("RGB Transfers", items, item_title="RGB Transfer — {index}")
|
|
644
|
+
except Exception as e:
|
|
645
|
+
raise_cli_error(e)
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
@asset_app.command(
|
|
649
|
+
"refresh",
|
|
650
|
+
epilog=(
|
|
651
|
+
"[bold]Examples[/bold]\n\n"
|
|
652
|
+
" Refresh pending transfers (with sync):\n"
|
|
653
|
+
" [cyan]kaleido asset refresh[/cyan]\n\n"
|
|
654
|
+
" Refresh without syncing blockchain data:\n"
|
|
655
|
+
" [cyan]kaleido asset refresh --skip-sync[/cyan]\n\n"
|
|
656
|
+
"[bold]Note:[/bold] --skip-sync skips synchronization with the blockchain before refreshing,\n"
|
|
657
|
+
"which is faster but may not include the latest on-chain state."
|
|
658
|
+
),
|
|
659
|
+
)
|
|
660
|
+
def asset_refresh(
|
|
661
|
+
skip_sync: Annotated[
|
|
662
|
+
bool,
|
|
663
|
+
typer.Option(
|
|
664
|
+
"--skip-sync",
|
|
665
|
+
help="Skip blockchain synchronization before refreshing transfers.",
|
|
666
|
+
),
|
|
667
|
+
] = False,
|
|
668
|
+
) -> None:
|
|
669
|
+
"""Refresh pending RGB transfers to update their status."""
|
|
670
|
+
asyncio.run(_asset_refresh(skip_sync))
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
async def _asset_refresh(skip_sync: bool) -> None:
|
|
674
|
+
try:
|
|
675
|
+
client = get_client(require_node=True)
|
|
676
|
+
body = RefreshRequest(skip_sync=skip_sync, filter=[])
|
|
677
|
+
await client.rln.refresh_transfers(body)
|
|
678
|
+
print_success("Transfers refreshed.")
|
|
679
|
+
except Exception as e:
|
|
680
|
+
raise_cli_error(e)
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
@issue_app.command(
|
|
684
|
+
"uda",
|
|
685
|
+
epilog=(
|
|
686
|
+
"[bold]Examples[/bold]\n\n"
|
|
687
|
+
" Issue a simple UDA (NFT):\n"
|
|
688
|
+
' [cyan]kaleido asset issue uda --ticker NFT1 --name "My NFT"[/cyan]\n\n'
|
|
689
|
+
" With a description and a media file:\n"
|
|
690
|
+
' [cyan]kaleido asset issue uda --ticker ART1 --name "Art NFT" --description "Limited edition" --file ./art.png[/cyan]\n\n'
|
|
691
|
+
"[dim]UDA = Unique Digital Asset (non-fungible). Supply is always 1.[/dim]"
|
|
692
|
+
),
|
|
693
|
+
)
|
|
694
|
+
def asset_issue_uda(
|
|
695
|
+
ticker: Annotated[
|
|
696
|
+
str | None,
|
|
697
|
+
typer.Option("--ticker", help="Short ticker symbol, e.g. NFT1."),
|
|
698
|
+
] = None,
|
|
699
|
+
name: Annotated[
|
|
700
|
+
str | None,
|
|
701
|
+
typer.Option("--name", help="Human-readable asset name."),
|
|
702
|
+
] = None,
|
|
703
|
+
description: Annotated[
|
|
704
|
+
str | None,
|
|
705
|
+
typer.Option("--description", help="Optional description."),
|
|
706
|
+
] = None,
|
|
707
|
+
file_path: Annotated[
|
|
708
|
+
str | None,
|
|
709
|
+
typer.Option("--file", help="Path to a media file (image, etc.) to embed."),
|
|
710
|
+
] = None,
|
|
711
|
+
precision: Annotated[
|
|
712
|
+
int,
|
|
713
|
+
typer.Option("--precision", help="Number of decimal places (usually 0 for NFTs)."),
|
|
714
|
+
] = 0,
|
|
715
|
+
) -> None:
|
|
716
|
+
"""Issue a new UDA (Unique Digital Asset / NFT) RGB token."""
|
|
717
|
+
resolved_ticker = resolve_required_text(ticker, "Ticker symbol (e.g. NFT1)", "--ticker")
|
|
718
|
+
resolved_name = resolve_required_text(name, "Asset name", "--name")
|
|
719
|
+
|
|
720
|
+
description, file_path = resolve_asset_metadata(description, file_path)
|
|
721
|
+
|
|
722
|
+
asyncio.run(_issue_uda(resolved_ticker, resolved_name, description, file_path, precision))
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
async def _issue_uda(
|
|
726
|
+
ticker: str,
|
|
727
|
+
name: str,
|
|
728
|
+
description: str | None,
|
|
729
|
+
file_path: str | None,
|
|
730
|
+
precision: int,
|
|
731
|
+
) -> None:
|
|
732
|
+
try:
|
|
733
|
+
client = get_client(require_node=True)
|
|
734
|
+
body = IssueAssetUDARequest(
|
|
735
|
+
ticker=ticker,
|
|
736
|
+
name=name,
|
|
737
|
+
details=description,
|
|
738
|
+
precision=precision,
|
|
739
|
+
media_file_digest=sha256_file(file_path),
|
|
740
|
+
attachments_file_digests=[],
|
|
741
|
+
)
|
|
742
|
+
resp: IssueAssetUDAResponse = await client.rln.issue_asset_uda(body)
|
|
743
|
+
if is_json_mode():
|
|
744
|
+
print_json(resp.model_dump())
|
|
745
|
+
else:
|
|
746
|
+
print_success(f"UDA asset issued: {resp.asset.asset_id}")
|
|
747
|
+
output_model(resp, title="Issued Asset")
|
|
748
|
+
except Exception as e:
|
|
749
|
+
raise_cli_error(e)
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
@asset_app.command(
|
|
753
|
+
"sync",
|
|
754
|
+
epilog=" [cyan]kaleido asset sync[/cyan] Synchronize RGB wallet with the blockchain.",
|
|
755
|
+
)
|
|
756
|
+
def asset_sync() -> None:
|
|
757
|
+
"""Synchronize the RGB wallet with the blockchain."""
|
|
758
|
+
asyncio.run(_asset_sync())
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
async def _asset_sync() -> None:
|
|
762
|
+
try:
|
|
763
|
+
client = get_client(require_node=True)
|
|
764
|
+
await client.rln.sync_rgb_wallet()
|
|
765
|
+
print_success("RGB wallet synced.")
|
|
766
|
+
except Exception as e:
|
|
767
|
+
raise_cli_error(e)
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
@asset_app.command(
|
|
771
|
+
"fail-transfers",
|
|
772
|
+
epilog=(
|
|
773
|
+
"[bold]Examples[/bold]\n\n"
|
|
774
|
+
" Fail all pending transfers with no asset assigned:\n"
|
|
775
|
+
" [cyan]kaleido asset fail-transfers[/cyan]\n\n"
|
|
776
|
+
" Fail a specific batch transfer:\n"
|
|
777
|
+
" [cyan]kaleido asset fail-transfers --batch-idx 3[/cyan]"
|
|
778
|
+
),
|
|
779
|
+
)
|
|
780
|
+
def asset_fail_transfers(
|
|
781
|
+
batch_idx: Annotated[
|
|
782
|
+
int | None,
|
|
783
|
+
typer.Option("--batch-idx", help="Specific batch transfer index to fail. Omit for all."),
|
|
784
|
+
] = None,
|
|
785
|
+
no_asset_only: Annotated[
|
|
786
|
+
bool,
|
|
787
|
+
typer.Option("--no-asset-only", help="Only fail transfers with no associated asset."),
|
|
788
|
+
] = False,
|
|
789
|
+
skip_sync: Annotated[
|
|
790
|
+
bool,
|
|
791
|
+
typer.Option("--skip-sync", help="Skip blockchain sync before processing."),
|
|
792
|
+
] = False,
|
|
793
|
+
) -> None:
|
|
794
|
+
"""Mark pending RGB transfers as failed."""
|
|
795
|
+
asyncio.run(_asset_fail_transfers(batch_idx, no_asset_only, skip_sync))
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
async def _asset_fail_transfers(
|
|
799
|
+
batch_idx: int | None, no_asset_only: bool, skip_sync: bool
|
|
800
|
+
) -> None:
|
|
801
|
+
try:
|
|
802
|
+
client = get_client(require_node=True)
|
|
803
|
+
resp: FailTransfersResponse = await client.rln.fail_transfers(
|
|
804
|
+
FailTransfersRequest(
|
|
805
|
+
batch_transfer_idx=batch_idx,
|
|
806
|
+
no_asset_only=no_asset_only,
|
|
807
|
+
skip_sync=skip_sync,
|
|
808
|
+
)
|
|
809
|
+
)
|
|
810
|
+
if is_json_mode():
|
|
811
|
+
print_json(resp.model_dump())
|
|
812
|
+
else:
|
|
813
|
+
changed = "yes" if resp.transfers_changed else "no"
|
|
814
|
+
print_success(f"Done. Transfers changed: {changed}")
|
|
815
|
+
except Exception as e:
|
|
816
|
+
raise_cli_error(e)
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
@asset_app.command(
|
|
820
|
+
"media",
|
|
821
|
+
epilog=(
|
|
822
|
+
"[bold]Examples[/bold]\n\n"
|
|
823
|
+
" Fetch and print the hex bytes of an asset's media:\n"
|
|
824
|
+
" [cyan]kaleido asset media 5891b5b5...[/cyan]\n\n"
|
|
825
|
+
" Save the raw bytes to a file:\n"
|
|
826
|
+
" [cyan]kaleido --json asset media 5891b5b5... | jq -r .bytes_hex | xxd -r -p > out.png[/cyan]"
|
|
827
|
+
),
|
|
828
|
+
)
|
|
829
|
+
def asset_media(
|
|
830
|
+
digest: Annotated[
|
|
831
|
+
str,
|
|
832
|
+
typer.Argument(help="SHA-256 digest of the media file to retrieve."),
|
|
833
|
+
],
|
|
834
|
+
) -> None:
|
|
835
|
+
"""Fetch raw media bytes for an RGB asset by file digest."""
|
|
836
|
+
asyncio.run(_asset_media(digest))
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
async def _asset_media(digest: str) -> None:
|
|
840
|
+
try:
|
|
841
|
+
client = get_client(require_node=True)
|
|
842
|
+
resp: GetAssetMediaResponse = await client.rln.get_asset_media(
|
|
843
|
+
GetAssetMediaRequest(digest=digest)
|
|
844
|
+
)
|
|
845
|
+
if is_json_mode():
|
|
846
|
+
print_json(resp.model_dump())
|
|
847
|
+
else:
|
|
848
|
+
output_model(resp, title=f"Asset Media — {digest[:20]}…")
|
|
849
|
+
except Exception as e:
|
|
850
|
+
raise_cli_error(e)
|