Skip to content

Commit f2458fb

Browse files
committed
rebalance: migrate to uv shebang
1 parent 457c51c commit f2458fb

File tree

5 files changed

+1560
-7
lines changed

5 files changed

+1560
-7
lines changed

rebalance/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ This plugin moves liquidity between your channels using circular payments
55

66
## Installation
77

8+
You need [uv](https://docs.astral.sh/uv/getting-started/installation/) to run this
9+
plugin like a binary. After `uv` is installed you can simply run
10+
11+
```
12+
lightning-cli plugin start /path/to/rebalance.py
13+
```
14+
815
For general plugin installation instructions see the repos main
916
[README.md](https://github.com/lightningd/plugins/blob/master/README.md#Installation)
1017

rebalance/pyproject.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[project]
2+
name = "rebalance"
3+
version = "0.1.0"
4+
description = "Moves liquidity between your channels using circular payments"
5+
readme = "README.md"
6+
requires-python = ">=3.9.2"
7+
8+
dependencies = ["pyln-client>=24.11"]
9+
10+
[dependency-groups]
11+
dev = [
12+
"pytest>=7.4,<9",
13+
"pytest-xdist>=3.7,<4",
14+
"pytest-timeout>=2.4,<3",
15+
"pyln-testing>=24.11.1",
16+
"pyln-client>=24.11.1",
17+
"pyln-proto>=24.11.1",
18+
]

rebalance/rebalance.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
#!/usr/bin/env python3
1+
#!/usr/bin/env -S uv run --script
2+
3+
# /// script
4+
# requires-python = ">=3.9.2"
5+
# dependencies = [
6+
# "pyln-client>=24.11",
7+
# ]
8+
# ///
9+
210
from clnutils import cln_parse_rpcversion
311
from datetime import timedelta
412
from functools import reduce
@@ -50,7 +58,12 @@ def setup_routing_fees(route, msat):
5058
route_set_msat(r, msat)
5159
r["delay"] = delay
5260
channels = plugin.rpc.listpeerchannels(route[-2]["id"]).get("channels")
53-
ch = next(c["updates"]["remote"] for c in channels if c["short_channel_id"] == r["channel"] or c["alias"].get("remote") == r["channel"])
61+
ch = next(
62+
c["updates"]["remote"]
63+
for c in channels
64+
if c["short_channel_id"] == r["channel"]
65+
or c["alias"].get("remote") == r["channel"]
66+
)
5467
fee = Millisatoshi(ch["fee_base_msat"])
5568
# BOLT #7 requires fee >= fee_base_msat + ( amount_to_forward * fee_proportional_millionths / 1000000 )
5669
fee += (
@@ -355,10 +368,22 @@ def rebalance(
355368
my_node_id = plugin.getinfo.get("id")
356369
outgoing_node_id = peer_from_scid(outgoing_scid, my_node_id, payload)
357370
incoming_node_id = peer_from_scid(incoming_scid, my_node_id, payload)
358-
out_aliases = get_channel(payload, outgoing_node_id, outgoing_scid, True).get("alias")
359-
out_alias = out_aliases.get("local") if (out_aliases and out_aliases.get("local")) else outgoing_scid
360-
in_aliases = get_channel(payload, incoming_node_id, incoming_scid, True).get("alias")
361-
in_alias = in_aliases.get("remote") if (in_aliases and in_aliases.get("remote")) else incoming_scid
371+
out_aliases = get_channel(payload, outgoing_node_id, outgoing_scid, True).get(
372+
"alias"
373+
)
374+
out_alias = (
375+
out_aliases.get("local")
376+
if (out_aliases and out_aliases.get("local"))
377+
else outgoing_scid
378+
)
379+
in_aliases = get_channel(payload, incoming_node_id, incoming_scid, True).get(
380+
"alias"
381+
)
382+
in_alias = (
383+
in_aliases.get("remote")
384+
if (in_aliases and in_aliases.get("remote"))
385+
else incoming_scid
386+
)
362387
out_ours, out_total = amounts_from_scid(outgoing_scid)
363388
in_ours, in_total = amounts_from_scid(incoming_scid)
364389

rebalance/requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)