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,274 @@
|
|
|
1
|
+
"""Low-level local node swap commands."""
|
|
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
|
+
GetSwapRequest,
|
|
11
|
+
GetSwapResponse,
|
|
12
|
+
ListSwapsResponse,
|
|
13
|
+
MakerExecuteRequest,
|
|
14
|
+
MakerInitRequest,
|
|
15
|
+
MakerInitResponse,
|
|
16
|
+
TakerRequest,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
from kaleido_cli.context import get_client
|
|
20
|
+
from kaleido_cli.output import (
|
|
21
|
+
is_json_mode,
|
|
22
|
+
output_collection,
|
|
23
|
+
output_model,
|
|
24
|
+
print_error,
|
|
25
|
+
print_info,
|
|
26
|
+
print_json,
|
|
27
|
+
print_success,
|
|
28
|
+
)
|
|
29
|
+
from kaleido_cli.utils.errors import raise_cli_error
|
|
30
|
+
from kaleido_cli.utils.prompts import resolve_required_int, resolve_required_text
|
|
31
|
+
|
|
32
|
+
node_swap_app = typer.Typer(
|
|
33
|
+
no_args_is_help=True,
|
|
34
|
+
rich_markup_mode="rich",
|
|
35
|
+
help="Low-level local RLN node swap flow: maker-init, taker whitelist, then maker-execute.",
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@node_swap_app.command(
|
|
40
|
+
"pubkey",
|
|
41
|
+
epilog=" [cyan]kaleido node swap pubkey[/cyan] Print the local node's taker public key.",
|
|
42
|
+
)
|
|
43
|
+
def node_pubkey() -> None:
|
|
44
|
+
"""Show the local node's taker public key used in swap operations."""
|
|
45
|
+
asyncio.run(_node_pubkey())
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
async def _node_pubkey() -> None:
|
|
49
|
+
try:
|
|
50
|
+
client = get_client(require_node=True)
|
|
51
|
+
pubkey = await client.rln.get_taker_pubkey()
|
|
52
|
+
if is_json_mode():
|
|
53
|
+
print_json({"pubkey": pubkey})
|
|
54
|
+
else:
|
|
55
|
+
print_success(f"Taker pubkey: {pubkey}")
|
|
56
|
+
except Exception as e:
|
|
57
|
+
raise_cli_error(e)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@node_swap_app.command(
|
|
61
|
+
"init",
|
|
62
|
+
epilog=(
|
|
63
|
+
"[bold]Examples[/bold]\n\n"
|
|
64
|
+
" Initialize a local node swap:\n"
|
|
65
|
+
" [cyan]kaleido node swap init --qty-from 30 --to-asset rgb:abc... --qty-to 10[/cyan]"
|
|
66
|
+
),
|
|
67
|
+
)
|
|
68
|
+
def node_init(
|
|
69
|
+
from_asset: Annotated[
|
|
70
|
+
str | None,
|
|
71
|
+
typer.Option("--from-asset", help="RGB asset ID the maker will send (None = BTC)."),
|
|
72
|
+
] = None,
|
|
73
|
+
qty_from: Annotated[
|
|
74
|
+
int | None, typer.Option("--qty-from", help="Amount the maker will send (raw units).")
|
|
75
|
+
] = None,
|
|
76
|
+
to_asset: Annotated[
|
|
77
|
+
str | None,
|
|
78
|
+
typer.Option("--to-asset", help="RGB asset ID the maker will receive (None = BTC)."),
|
|
79
|
+
] = None,
|
|
80
|
+
qty_to: Annotated[
|
|
81
|
+
int | None, typer.Option("--qty-to", help="Amount the maker will receive (raw units).")
|
|
82
|
+
] = None,
|
|
83
|
+
timeout_sec: Annotated[
|
|
84
|
+
int, typer.Option("--timeout", help="Swap offer timeout in seconds.")
|
|
85
|
+
] = 100,
|
|
86
|
+
) -> None:
|
|
87
|
+
"""Initialize a low-level local node swap via maker-init."""
|
|
88
|
+
resolved_qty_from = resolve_required_int(qty_from, "Quantity from (raw units)", "--qty-from")
|
|
89
|
+
resolved_qty_to = resolve_required_int(qty_to, "Quantity to (raw units)", "--qty-to")
|
|
90
|
+
|
|
91
|
+
asyncio.run(_node_init(from_asset, resolved_qty_from, to_asset, resolved_qty_to, timeout_sec))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
async def _node_init(
|
|
95
|
+
from_asset: str | None,
|
|
96
|
+
qty_from: int,
|
|
97
|
+
to_asset: str | None,
|
|
98
|
+
qty_to: int,
|
|
99
|
+
timeout_sec: int,
|
|
100
|
+
) -> None:
|
|
101
|
+
try:
|
|
102
|
+
client = get_client(require_node=True)
|
|
103
|
+
resp: MakerInitResponse = await client.rln.maker_init(
|
|
104
|
+
MakerInitRequest(
|
|
105
|
+
qty_from=qty_from,
|
|
106
|
+
qty_to=qty_to,
|
|
107
|
+
from_asset=from_asset,
|
|
108
|
+
to_asset=to_asset,
|
|
109
|
+
timeout_sec=timeout_sec,
|
|
110
|
+
)
|
|
111
|
+
)
|
|
112
|
+
if is_json_mode():
|
|
113
|
+
print_json(resp.model_dump())
|
|
114
|
+
else:
|
|
115
|
+
print_success("Node swap initialized")
|
|
116
|
+
output_model(resp, title="Node Swap Init")
|
|
117
|
+
print_info("Next step: whitelist on the taker side, then execute on the maker side.")
|
|
118
|
+
except Exception as e:
|
|
119
|
+
raise_cli_error(e)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
@node_swap_app.command(
|
|
123
|
+
"whitelist",
|
|
124
|
+
epilog=(
|
|
125
|
+
"[bold]Examples[/bold]\n\n"
|
|
126
|
+
" Whitelist a swap on the local taker node:\n"
|
|
127
|
+
" [cyan]kaleido node swap whitelist --swapstring '<swapstring>'[/cyan]"
|
|
128
|
+
),
|
|
129
|
+
)
|
|
130
|
+
def node_whitelist(
|
|
131
|
+
swapstring: Annotated[
|
|
132
|
+
str | None,
|
|
133
|
+
typer.Option("--swapstring", help="Swap string returned by node init or atomic init."),
|
|
134
|
+
] = None,
|
|
135
|
+
) -> None:
|
|
136
|
+
"""Whitelist a swap on the local taker node via /taker."""
|
|
137
|
+
resolved_swapstring = resolve_required_text(swapstring, "Swap string", "--swapstring")
|
|
138
|
+
asyncio.run(_node_whitelist(resolved_swapstring))
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
async def _node_whitelist(swapstring: str) -> None:
|
|
142
|
+
try:
|
|
143
|
+
client = get_client(require_node=True)
|
|
144
|
+
await client.rln.whitelist_swap(TakerRequest(swapstring=swapstring))
|
|
145
|
+
if is_json_mode():
|
|
146
|
+
print_json({"ok": True, "swapstring": swapstring})
|
|
147
|
+
else:
|
|
148
|
+
print_success("Swap whitelisted on taker node")
|
|
149
|
+
except Exception as e:
|
|
150
|
+
raise_cli_error(e)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
@node_swap_app.command(
|
|
154
|
+
"execute",
|
|
155
|
+
epilog=(
|
|
156
|
+
"[bold]Examples[/bold]\n\n"
|
|
157
|
+
" Execute a previously initialized local node swap:\n"
|
|
158
|
+
" [cyan]kaleido node swap execute --swapstring '<swapstring>' "
|
|
159
|
+
"--payment-secret deadbeef... --taker-pubkey 03ab...[/cyan]"
|
|
160
|
+
),
|
|
161
|
+
)
|
|
162
|
+
def node_execute(
|
|
163
|
+
swapstring: Annotated[
|
|
164
|
+
str | None, typer.Option("--swapstring", help="Swap string returned by node init.")
|
|
165
|
+
] = None,
|
|
166
|
+
payment_secret: Annotated[
|
|
167
|
+
str | None, typer.Option("--payment-secret", help="Payment secret returned by node init.")
|
|
168
|
+
] = None,
|
|
169
|
+
taker_pubkey: Annotated[
|
|
170
|
+
str | None,
|
|
171
|
+
typer.Option("--taker-pubkey", help="Taker node pubkey. Defaults to own node pubkey."),
|
|
172
|
+
] = None,
|
|
173
|
+
) -> None:
|
|
174
|
+
"""Execute a low-level local node swap via maker-execute."""
|
|
175
|
+
resolved_swapstring = resolve_required_text(swapstring, "Swap string", "--swapstring")
|
|
176
|
+
resolved_payment_secret = resolve_required_text(
|
|
177
|
+
payment_secret, "Payment secret", "--payment-secret"
|
|
178
|
+
)
|
|
179
|
+
asyncio.run(_node_execute(resolved_swapstring, resolved_payment_secret, taker_pubkey))
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
async def _node_execute(
|
|
183
|
+
swapstring: str,
|
|
184
|
+
payment_secret: str,
|
|
185
|
+
taker_pubkey_override: str | None,
|
|
186
|
+
) -> None:
|
|
187
|
+
try:
|
|
188
|
+
client = get_client(require_node=True)
|
|
189
|
+
resolved_taker_pubkey = taker_pubkey_override or await client.rln.get_taker_pubkey()
|
|
190
|
+
await client.rln.maker_execute(
|
|
191
|
+
MakerExecuteRequest(
|
|
192
|
+
swapstring=swapstring,
|
|
193
|
+
payment_secret=payment_secret,
|
|
194
|
+
taker_pubkey=resolved_taker_pubkey,
|
|
195
|
+
)
|
|
196
|
+
)
|
|
197
|
+
if is_json_mode():
|
|
198
|
+
print_json(
|
|
199
|
+
{"ok": True, "swapstring": swapstring, "taker_pubkey": resolved_taker_pubkey}
|
|
200
|
+
)
|
|
201
|
+
else:
|
|
202
|
+
print_success("Node swap executed successfully")
|
|
203
|
+
except Exception as e:
|
|
204
|
+
raise_cli_error(e)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
@node_swap_app.command(
|
|
208
|
+
"status",
|
|
209
|
+
epilog=(
|
|
210
|
+
"[bold]Examples[/bold]\n\n"
|
|
211
|
+
" Check the taker-side swap status:\n"
|
|
212
|
+
" [cyan]kaleido node swap status <payment-hash> --taker[/cyan]\n\n"
|
|
213
|
+
" Check the maker-side swap status:\n"
|
|
214
|
+
" [cyan]kaleido node swap status <payment-hash> --maker[/cyan]"
|
|
215
|
+
),
|
|
216
|
+
)
|
|
217
|
+
def node_status(
|
|
218
|
+
payment_hash: Annotated[str | None, typer.Argument(help="Swap payment hash.")] = None,
|
|
219
|
+
taker: Annotated[bool, typer.Option("--taker", help="Look up the taker-side swap.")] = False,
|
|
220
|
+
maker: Annotated[bool, typer.Option("--maker", help="Look up the maker-side swap.")] = False,
|
|
221
|
+
) -> None:
|
|
222
|
+
"""Check a local node swap by payment hash."""
|
|
223
|
+
resolved_payment_hash = resolve_required_text(
|
|
224
|
+
payment_hash, "Payment hash", "PAYMENT_HASH argument"
|
|
225
|
+
)
|
|
226
|
+
if not taker and not maker:
|
|
227
|
+
taker = True
|
|
228
|
+
elif taker == maker:
|
|
229
|
+
print_error("Must specify at most one of --taker or --maker")
|
|
230
|
+
raise typer.Exit(1)
|
|
231
|
+
asyncio.run(_node_status(resolved_payment_hash, taker))
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
async def _node_status(payment_hash: str, taker: bool) -> None:
|
|
235
|
+
try:
|
|
236
|
+
client = get_client(require_node=True)
|
|
237
|
+
resp: GetSwapResponse = await client.rln.get_swap(
|
|
238
|
+
GetSwapRequest(payment_hash=payment_hash, taker=taker)
|
|
239
|
+
)
|
|
240
|
+
if is_json_mode():
|
|
241
|
+
print_json(resp.model_dump())
|
|
242
|
+
else:
|
|
243
|
+
side = "Taker" if taker else "Maker"
|
|
244
|
+
output_model(resp, title=f"{side} Node Swap — {payment_hash[:16]}…")
|
|
245
|
+
except Exception as e:
|
|
246
|
+
raise_cli_error(e)
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
@node_swap_app.command(
|
|
250
|
+
"list",
|
|
251
|
+
epilog=(
|
|
252
|
+
"[bold]Examples[/bold]\n\n List all node swaps:\n [cyan]kaleido node swap list[/cyan]"
|
|
253
|
+
),
|
|
254
|
+
)
|
|
255
|
+
def node_list() -> None:
|
|
256
|
+
"""List swaps known to the local RLN node."""
|
|
257
|
+
asyncio.run(_node_list())
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
async def _node_list() -> None:
|
|
261
|
+
try:
|
|
262
|
+
client = get_client(require_node=True)
|
|
263
|
+
resp: ListSwapsResponse = await client.rln.list_swaps()
|
|
264
|
+
if is_json_mode():
|
|
265
|
+
print_json(resp.model_dump())
|
|
266
|
+
return
|
|
267
|
+
items = []
|
|
268
|
+
for swap in resp.taker or []:
|
|
269
|
+
items.append({**swap.model_dump(), "role": "taker"})
|
|
270
|
+
for swap in resp.maker or []:
|
|
271
|
+
items.append({**swap.model_dump(), "role": "maker"})
|
|
272
|
+
output_collection("Node Swaps", items, item_title="Node Swap — {index}")
|
|
273
|
+
except Exception as e:
|
|
274
|
+
raise_cli_error(e)
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
"""Lightning payment and invoice commands."""
|
|
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
|
+
DecodeLNInvoiceRequest,
|
|
11
|
+
DecodeLNInvoiceResponse,
|
|
12
|
+
DecodeRGBInvoiceRequest,
|
|
13
|
+
DecodeRGBInvoiceResponse,
|
|
14
|
+
GetPaymentRequest,
|
|
15
|
+
GetPaymentResponse,
|
|
16
|
+
InvoiceStatusRequest,
|
|
17
|
+
InvoiceStatusResponse,
|
|
18
|
+
KeysendRequest,
|
|
19
|
+
KeysendResponse,
|
|
20
|
+
ListPaymentsResponse,
|
|
21
|
+
LNInvoiceRequest,
|
|
22
|
+
LNInvoiceResponse,
|
|
23
|
+
SendPaymentRequest,
|
|
24
|
+
SendPaymentResponse,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
from kaleido_cli.context import get_client
|
|
28
|
+
from kaleido_cli.output import (
|
|
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 (
|
|
38
|
+
require_option_when_set,
|
|
39
|
+
resolve_required_int,
|
|
40
|
+
resolve_required_text,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
payment_app = typer.Typer(
|
|
44
|
+
no_args_is_help=True,
|
|
45
|
+
rich_markup_mode="rich",
|
|
46
|
+
help="Lightning payments — create invoices, pay, decode, check status.",
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@payment_app.command(
|
|
51
|
+
"invoice",
|
|
52
|
+
epilog=(
|
|
53
|
+
"[bold]Examples[/bold]\n\n"
|
|
54
|
+
" BTC invoice for 10 000 msat:\n"
|
|
55
|
+
" [cyan]kaleido payment invoice --amount-msat 10000[/cyan]\n\n"
|
|
56
|
+
" Zero-amount (any-amount) invoice:\n"
|
|
57
|
+
" [cyan]kaleido payment invoice[/cyan]\n\n"
|
|
58
|
+
" RGB+LN invoice (receive USDT tokens over Lightning):\n"
|
|
59
|
+
" [cyan]kaleido payment invoice --asset-id rgb:abc... --asset-amount 500[/cyan]\n\n"
|
|
60
|
+
" With custom expiry (1 hour):\n"
|
|
61
|
+
" [cyan]kaleido payment invoice --amount-msat 10000 --expiry 3600[/cyan]\n\n"
|
|
62
|
+
" With a description:\n"
|
|
63
|
+
" [cyan]kaleido payment invoice --amount-msat 10000 -d 'Coffee'[/cyan]"
|
|
64
|
+
),
|
|
65
|
+
)
|
|
66
|
+
def payment_invoice(
|
|
67
|
+
amount_msat: Annotated[
|
|
68
|
+
int | None,
|
|
69
|
+
typer.Option(
|
|
70
|
+
"--amount-msat",
|
|
71
|
+
"-a",
|
|
72
|
+
help="Invoice amount in millisatoshis. Omit for a zero-amount invoice.",
|
|
73
|
+
),
|
|
74
|
+
] = None,
|
|
75
|
+
expiry: Annotated[
|
|
76
|
+
int,
|
|
77
|
+
typer.Option(
|
|
78
|
+
"--expiry",
|
|
79
|
+
"-e",
|
|
80
|
+
help="Invoice expiry in seconds.",
|
|
81
|
+
),
|
|
82
|
+
] = 3600,
|
|
83
|
+
asset_id: Annotated[
|
|
84
|
+
str | None,
|
|
85
|
+
typer.Option(
|
|
86
|
+
"--asset-id",
|
|
87
|
+
help="RGB asset ID to request over Lightning (creates an RGB+LN invoice).",
|
|
88
|
+
),
|
|
89
|
+
] = None,
|
|
90
|
+
asset_amount: Annotated[
|
|
91
|
+
int | None,
|
|
92
|
+
typer.Option("--asset-amount", help="Amount of RGB asset to request."),
|
|
93
|
+
] = None,
|
|
94
|
+
description: Annotated[
|
|
95
|
+
str | None,
|
|
96
|
+
typer.Option("--description", "-d", help="Description shown to the payer."),
|
|
97
|
+
] = None,
|
|
98
|
+
description_hash: Annotated[
|
|
99
|
+
str | None,
|
|
100
|
+
typer.Option(
|
|
101
|
+
"--description-hash",
|
|
102
|
+
help="SHA-256 (hex) of a description committed to instead of including it.",
|
|
103
|
+
),
|
|
104
|
+
] = None,
|
|
105
|
+
) -> None:
|
|
106
|
+
"""Create a Lightning invoice (BOLT11)."""
|
|
107
|
+
require_option_when_set(asset_id, "--asset-id", **{"--asset-amount": asset_amount})
|
|
108
|
+
if description and description_hash:
|
|
109
|
+
print_error("Pass either --description or --description-hash, not both.")
|
|
110
|
+
raise typer.Exit(1)
|
|
111
|
+
asyncio.run(
|
|
112
|
+
_payment_invoice(amount_msat, expiry, asset_id, asset_amount, description, description_hash)
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
async def _payment_invoice(
|
|
117
|
+
amount_msat: int | None,
|
|
118
|
+
expiry: int,
|
|
119
|
+
asset_id: str | None,
|
|
120
|
+
asset_amount: int | None,
|
|
121
|
+
description: str | None = None,
|
|
122
|
+
description_hash: str | None = None,
|
|
123
|
+
) -> None:
|
|
124
|
+
try:
|
|
125
|
+
client = get_client(require_node=True)
|
|
126
|
+
body = LNInvoiceRequest(
|
|
127
|
+
amt_msat=amount_msat,
|
|
128
|
+
expiry_sec=expiry,
|
|
129
|
+
asset_id=asset_id,
|
|
130
|
+
asset_amount=asset_amount,
|
|
131
|
+
description=description,
|
|
132
|
+
description_hash=description_hash,
|
|
133
|
+
)
|
|
134
|
+
resp: LNInvoiceResponse = await client.rln.create_ln_invoice(body)
|
|
135
|
+
if is_json_mode():
|
|
136
|
+
print_json(resp.model_dump())
|
|
137
|
+
else:
|
|
138
|
+
print_success(f"Invoice: {resp.invoice}")
|
|
139
|
+
except Exception as e:
|
|
140
|
+
raise_cli_error(e)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
@payment_app.command(
|
|
144
|
+
"send",
|
|
145
|
+
epilog=(
|
|
146
|
+
"[bold]Examples[/bold]\n\n"
|
|
147
|
+
" Pay an invoice:\n"
|
|
148
|
+
" [cyan]kaleido payment send lnbc...[/cyan]\n\n"
|
|
149
|
+
" Pay a zero-amount invoice with an explicit amount:\n"
|
|
150
|
+
" [cyan]kaleido payment send lnbc... --amount-msat 5000[/cyan]"
|
|
151
|
+
),
|
|
152
|
+
)
|
|
153
|
+
def payment_send(
|
|
154
|
+
invoice: Annotated[str | None, typer.Argument(help="BOLT11 invoice string to pay.")] = None,
|
|
155
|
+
amount_msat: Annotated[
|
|
156
|
+
int | None,
|
|
157
|
+
typer.Option("--amount-msat", help="Amount in msat. Required for zero-amount invoices."),
|
|
158
|
+
] = None,
|
|
159
|
+
asset_id: Annotated[
|
|
160
|
+
str | None,
|
|
161
|
+
typer.Option("--asset-id", help="RGB asset ID for RGB+LN payments."),
|
|
162
|
+
] = None,
|
|
163
|
+
asset_amount: Annotated[
|
|
164
|
+
int | None,
|
|
165
|
+
typer.Option("--asset-amount", help="RGB asset amount for RGB+LN payments."),
|
|
166
|
+
] = None,
|
|
167
|
+
) -> None:
|
|
168
|
+
"""Send a Lightning payment."""
|
|
169
|
+
resolved_invoice = resolve_required_text(invoice, "BOLT11 invoice", "INVOICE argument")
|
|
170
|
+
|
|
171
|
+
require_option_when_set(asset_id, "--asset-id", **{"--asset-amount": asset_amount})
|
|
172
|
+
|
|
173
|
+
asyncio.run(_payment_send(resolved_invoice, amount_msat, asset_id, asset_amount))
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
async def _payment_send(
|
|
177
|
+
invoice: str,
|
|
178
|
+
amount_msat: int | None,
|
|
179
|
+
asset_id: str | None,
|
|
180
|
+
asset_amount: int | None,
|
|
181
|
+
) -> None:
|
|
182
|
+
try:
|
|
183
|
+
client = get_client(require_node=True)
|
|
184
|
+
body = SendPaymentRequest(
|
|
185
|
+
invoice=invoice,
|
|
186
|
+
amt_msat=amount_msat,
|
|
187
|
+
asset_id=asset_id,
|
|
188
|
+
asset_amount=asset_amount,
|
|
189
|
+
)
|
|
190
|
+
resp: SendPaymentResponse = await client.rln.send_payment(body)
|
|
191
|
+
if is_json_mode():
|
|
192
|
+
print_json(resp.model_dump())
|
|
193
|
+
else:
|
|
194
|
+
output_model(resp, title="Payment Result")
|
|
195
|
+
except Exception as e:
|
|
196
|
+
raise_cli_error(e)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
@payment_app.command("list")
|
|
200
|
+
def payment_list() -> None:
|
|
201
|
+
"""List Lightning payments."""
|
|
202
|
+
asyncio.run(_payment_list())
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
async def _payment_list() -> None:
|
|
206
|
+
try:
|
|
207
|
+
client = get_client(require_node=True)
|
|
208
|
+
resp: ListPaymentsResponse = await client.rln.list_payments()
|
|
209
|
+
if is_json_mode():
|
|
210
|
+
print_json(resp.model_dump())
|
|
211
|
+
return
|
|
212
|
+
items = []
|
|
213
|
+
for p in resp.payments or []:
|
|
214
|
+
payload = p.model_dump()
|
|
215
|
+
payload["direction"] = "inbound" if p.inbound else "outbound"
|
|
216
|
+
items.append(payload)
|
|
217
|
+
output_collection("Payments", items, item_title="Payment — {index}")
|
|
218
|
+
except Exception as e:
|
|
219
|
+
raise_cli_error(e)
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
@payment_app.command("status")
|
|
223
|
+
def payment_status(
|
|
224
|
+
payment_hash: Annotated[str, typer.Argument(help="Payment hash to look up.")],
|
|
225
|
+
) -> None:
|
|
226
|
+
"""Get the status of a payment."""
|
|
227
|
+
asyncio.run(_payment_status(payment_hash))
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
async def _payment_status(payment_hash: str) -> None:
|
|
231
|
+
try:
|
|
232
|
+
client = get_client(require_node=True)
|
|
233
|
+
resp: GetPaymentResponse = await client.rln.get_payment(
|
|
234
|
+
GetPaymentRequest(payment_hash=payment_hash)
|
|
235
|
+
)
|
|
236
|
+
if is_json_mode():
|
|
237
|
+
print_json(resp.model_dump())
|
|
238
|
+
else:
|
|
239
|
+
output_model(resp, title="Payment")
|
|
240
|
+
except Exception as e:
|
|
241
|
+
raise_cli_error(e)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
@payment_app.command(
|
|
245
|
+
"decode",
|
|
246
|
+
epilog=(
|
|
247
|
+
"[bold]Examples[/bold]\n\n"
|
|
248
|
+
" Decode a BOLT11 invoice:\n"
|
|
249
|
+
" [cyan]kaleido payment decode lnbc...[/cyan]\n\n"
|
|
250
|
+
" Decode an RGB invoice:\n"
|
|
251
|
+
" [cyan]kaleido payment decode rgb:...[/cyan]"
|
|
252
|
+
),
|
|
253
|
+
)
|
|
254
|
+
def payment_decode(
|
|
255
|
+
invoice: Annotated[str, typer.Argument(help="BOLT11 or RGB invoice string to inspect.")],
|
|
256
|
+
) -> None:
|
|
257
|
+
"""Decode a Lightning or RGB invoice."""
|
|
258
|
+
asyncio.run(_payment_decode(invoice))
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
async def _payment_decode(invoice: str) -> None:
|
|
262
|
+
try:
|
|
263
|
+
client = get_client(require_node=True)
|
|
264
|
+
# Try BOLT11 first, then RGB
|
|
265
|
+
try:
|
|
266
|
+
resp: (
|
|
267
|
+
DecodeLNInvoiceResponse | DecodeRGBInvoiceResponse
|
|
268
|
+
) = await client.rln.decode_ln_invoice(DecodeLNInvoiceRequest(invoice=invoice))
|
|
269
|
+
kind = "Lightning (BOLT11)"
|
|
270
|
+
except Exception:
|
|
271
|
+
resp = await client.rln.decode_rgb_invoice(DecodeRGBInvoiceRequest(invoice=invoice))
|
|
272
|
+
kind = "RGB Invoice"
|
|
273
|
+
|
|
274
|
+
if is_json_mode():
|
|
275
|
+
print_json(resp.model_dump())
|
|
276
|
+
else:
|
|
277
|
+
output_model(resp, title=f"Decoded {kind}")
|
|
278
|
+
except Exception as e:
|
|
279
|
+
print_error(f"Error decoding invoice: {e}")
|
|
280
|
+
raise typer.Exit(1)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
@payment_app.command("invoice-status")
|
|
284
|
+
def payment_invoice_status(
|
|
285
|
+
invoice: Annotated[str, typer.Argument(help="BOLT11 invoice to check.")],
|
|
286
|
+
) -> None:
|
|
287
|
+
"""Check the status of an invoice."""
|
|
288
|
+
asyncio.run(_payment_invoice_status(invoice))
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
async def _payment_invoice_status(invoice: str) -> None:
|
|
292
|
+
try:
|
|
293
|
+
client = get_client(require_node=True)
|
|
294
|
+
resp: InvoiceStatusResponse = await client.rln.get_invoice_status(
|
|
295
|
+
InvoiceStatusRequest(invoice=invoice)
|
|
296
|
+
)
|
|
297
|
+
if is_json_mode():
|
|
298
|
+
print_json(resp.model_dump())
|
|
299
|
+
else:
|
|
300
|
+
output_model(resp, title="Invoice Status")
|
|
301
|
+
except Exception as e:
|
|
302
|
+
raise_cli_error(e)
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
@payment_app.command(
|
|
306
|
+
"keysend",
|
|
307
|
+
epilog=(
|
|
308
|
+
"[bold]Examples[/bold]\n\n"
|
|
309
|
+
" Send 1 000 msat spontaneously to a peer:\n"
|
|
310
|
+
" [cyan]kaleido payment keysend 03b79a4... 1000[/cyan]\n\n"
|
|
311
|
+
" Send RGB assets spontaneously:\n"
|
|
312
|
+
" [cyan]kaleido payment keysend 03b79a4... 3000000 --asset-id rgb:abc... --asset-amount 10[/cyan]\n\n"
|
|
313
|
+
"[dim]Keysend is a spontaneous payment — no invoice needed, but the recipient node must support it.[/dim]"
|
|
314
|
+
),
|
|
315
|
+
)
|
|
316
|
+
def payment_keysend(
|
|
317
|
+
dest_pubkey: Annotated[
|
|
318
|
+
str | None,
|
|
319
|
+
typer.Argument(help="Destination node public key (hex, 33 bytes)."),
|
|
320
|
+
] = None,
|
|
321
|
+
amt_msat: Annotated[
|
|
322
|
+
int | None,
|
|
323
|
+
typer.Argument(help="Amount to send in millisatoshis."),
|
|
324
|
+
] = None,
|
|
325
|
+
asset_id: Annotated[
|
|
326
|
+
str | None,
|
|
327
|
+
typer.Option("--asset-id", help="RGB asset ID for spontaneous RGB+LN payment."),
|
|
328
|
+
] = None,
|
|
329
|
+
asset_amount: Annotated[
|
|
330
|
+
int | None,
|
|
331
|
+
typer.Option("--asset-amount", help="RGB asset amount."),
|
|
332
|
+
] = None,
|
|
333
|
+
) -> None:
|
|
334
|
+
"""Send a spontaneous Lightning payment (keysend) without needing an invoice."""
|
|
335
|
+
resolved_pubkey = resolve_required_text(
|
|
336
|
+
dest_pubkey, "Destination pubkey", "DEST_PUBKEY argument"
|
|
337
|
+
)
|
|
338
|
+
resolved_amt = resolve_required_int(amt_msat, "Amount in msat", "AMT_MSAT argument")
|
|
339
|
+
|
|
340
|
+
asyncio.run(_payment_keysend(resolved_pubkey, resolved_amt, asset_id, asset_amount))
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
async def _payment_keysend(
|
|
344
|
+
dest_pubkey: str,
|
|
345
|
+
amt_msat: int,
|
|
346
|
+
asset_id: str | None,
|
|
347
|
+
asset_amount: int | None,
|
|
348
|
+
) -> None:
|
|
349
|
+
try:
|
|
350
|
+
client = get_client(require_node=True)
|
|
351
|
+
resp: KeysendResponse = await client.rln.keysend(
|
|
352
|
+
KeysendRequest(
|
|
353
|
+
dest_pubkey=dest_pubkey,
|
|
354
|
+
amt_msat=amt_msat,
|
|
355
|
+
asset_id=asset_id,
|
|
356
|
+
asset_amount=asset_amount,
|
|
357
|
+
)
|
|
358
|
+
)
|
|
359
|
+
if is_json_mode():
|
|
360
|
+
print_json(resp.model_dump())
|
|
361
|
+
else:
|
|
362
|
+
output_model(resp, title="Keysend Result")
|
|
363
|
+
except Exception as e:
|
|
364
|
+
raise_cli_error(e)
|