├── .gitignore
├── COPYING
├── README.md
├── channel.py
├── clnclient.py
├── feepolicy.py
├── lndcliclient.py
├── lndclient.py
├── lndrestclient.py
├── poetry.lock
├── pyproject.toml
├── screenshot.png
├── shell.nix
├── suez
├── suez.py
└── terminal_web.py
/.gitignore:
--------------------------------------------------------------------------------
1 | __pycache__/
2 |
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Suez
2 |
3 | Tool for pretty printing and optimizing Lightning Network channels.
4 |
5 | 
6 |
7 | ## Installation
8 |
9 | 1. Install [poetry](https://python-poetry.org/)
10 | 2. `poetry install`
11 | 3. `poetry run ./suez`
12 |
13 | ## Channel fee policy
14 |
15 | You can set channel fees by passing `--base-fee` and `--fee-rate` parameters.
16 |
17 | For example:
18 |
19 | `poetry run ./suez --base-fee 1000 --fee-rate 200`
20 |
21 | You can override the channel fee policy by changing the `FeePolicy` class.
22 |
23 | Example implementation does the following:
24 |
25 | * sets lower fee rate for channels with mostly local balance
26 | * sets higher fee rate for channels with mostly remote balance
27 | * sets medium (close to specified) fee rate for balanced channels
28 |
29 | You control the spread via the `--fee-spread` argument. By default `--fee-spread` is set to 0.0 (no spread).
30 |
31 | For example:
32 |
33 | `poetry run ./suez --base-fee 1000 --fee-rate 500 --fee-spread 1.8`
34 |
35 | This will set the fee rate above 500 for channels with mostly remote balance and below 500
36 | for channels with mostly local balance.
37 |
38 | ## Lightning node support
39 |
40 | Currently, Suez supports LND (both via `lncli` and via the REST API) and c-lightning.
41 |
42 | By default it uses LND (`lncli`).
43 |
44 | You can use it with c-lightning as follows:
45 |
46 | `poetry run ./suez --client=c-lightning`
47 |
48 | You can connect to LND using the REST API as follows:
49 |
50 | `SSL_CERT_FILE= poetry run ./suez --client=lnd-rest --client-args=rpcserver=https://: --client-args=macaroonpath= --client-args=tlscertpath=`
51 |
52 | If you need to pass additional options to the lncli/lightning-cli you can do so:
53 |
54 | (single argument)
55 |
56 | `poetry run ./suez --client=c-lightning --client-args=--conf=/usr/local/etc/lightningd-bitcoin.conf`
57 |
58 | (multiple arguments)
59 |
60 | `poetry run ./suez --client-args=--rpcserver=host:10009 --client-args=--macaroonpath=admin.macaroon --client-args=--tlscertpath=tls.cert`
61 |
62 | Adding support requires writing a client similar to `lndclient.py` and instantiating it in `suez.py`.
63 |
64 | ## Donate
65 |
66 | You can tip me some satoshis via [tippin.me/@pavolrusnak](https://tippin.me/@pavolrusnak)
67 |
68 | or you can donate via Spontaneous AMP Payment (data field encodes `tip=suez`):
69 |
70 | `lncli sendpayment --amt 10000 --amp --dest 0385218f0e307b6a0e989d2a717d346942d96b4fd550e937de5f8ffe1568510a18 --data 7629168=7375657a`
71 |
72 | ## License
73 |
74 | This software is licensed under the [GNU General Public License v3](COPYING).
75 |
--------------------------------------------------------------------------------
/channel.py:
--------------------------------------------------------------------------------
1 | class Channel:
2 | """
3 | self.chan_id
4 | self.active
5 | self.channel_point
6 | self.local_node_id
7 | self.remote_node_id
8 | self.capacity
9 | self.commit_fee
10 | self.local_balance
11 | self.remote_balance
12 | self.local_base_fee
13 | self.local_fee_rate
14 | self.remote_base_fee
15 | self.remote_fee_rate
16 | self.local_alias
17 | self.remote_alias
18 | self.uptime
19 | self.lifetime
20 | self.last_forward
21 | self.earned_fees
22 | self.opener
23 | """
24 |
--------------------------------------------------------------------------------
/clnclient.py:
--------------------------------------------------------------------------------
1 | import json
2 | import subprocess
3 |
4 | from channel import Channel
5 |
6 |
7 | class ClnClient:
8 | def __init__(self, client_args):
9 | self.client_args = client_args
10 | self.refresh()
11 |
12 | def refresh(self):
13 | gi = self._run("getinfo")
14 | self.local_pubkey = gi["id"]
15 | self.local_alias = gi["alias"]
16 | self.channels = {}
17 |
18 | peers = self._run("listpeers")["peers"]
19 | for p in (peer["id"] for peer in peers if peer["num_channels"] > 0):
20 | peer_channels = self._run("listpeerchannels", p)["channels"]
21 | for c in peer_channels:
22 | chan = Channel()
23 | chan.chan_id = c.get("short_channel_id")
24 | chan.active = c["state"] == "CHANNELD_NORMAL"
25 | chan.opener = c["opener"]
26 | chan.private = c["private"]
27 | chan.local_node_id, chan.remote_node_id = self.local_pubkey, p
28 | chan.channel_point = c["channel_id"]
29 | chan.uptime, chan.lifetime = None, None
30 | total_msat = self._resolve_total_msat(c)
31 | to_us_msat = self._resolve_to_us_msat(c)
32 | chan.capacity, chan.commit_fee = (
33 | total_msat // 1000,
34 | self._cleanup_msat_value(c["last_tx_fee_msat"]) // 1000,
35 | )
36 | chan.local_balance, chan.remote_balance = (
37 | to_us_msat // 1000,
38 | (total_msat - to_us_msat) // 1000,
39 | )
40 | chan.ins = c["in_payments_fulfilled"]
41 | chan.ins_percent = chan.outs_percent = 0
42 | if chan.ins > 0:
43 | chan.ins_percent = chan.ins / c["in_payments_offered"]
44 | chan.outs = c["out_payments_fulfilled"]
45 | if chan.outs > 0:
46 | chan.outs_percent = chan.outs / c["out_payments_offered"]
47 | if chan.chan_id is not None:
48 | info = self._run("listchannels", chan.chan_id)["channels"]
49 | else:
50 | info = {}
51 | if len(info) > 0:
52 | node1_fee = (
53 | int(info[0]["base_fee_millisatoshi"]),
54 | int(info[0]["fee_per_millionth"]),
55 | )
56 | node1_htlc = (
57 | self._cleanup_msat_value(info[0]["htlc_minimum_msat"]),
58 | self._cleanup_msat_value(info[0]["htlc_maximum_msat"]),
59 | )
60 | node1_disabled = not info[0]["active"]
61 | if len(info) > 1:
62 | node2_fee = (
63 | int(info[1]["base_fee_millisatoshi"]),
64 | int(info[1]["fee_per_millionth"]),
65 | )
66 | node2_htlc = (
67 | self._cleanup_msat_value(info[1]["htlc_minimum_msat"]),
68 | self._cleanup_msat_value(info[1]["htlc_maximum_msat"]),
69 | )
70 | node2_disabled = not info[1]["active"]
71 | if info[0]["source"] != self.local_pubkey:
72 | assert info[1]["source"] == self.local_pubkey
73 | fee_remote = node1_fee
74 | fee_local = node2_fee
75 | htlc_remote = node1_htlc
76 | htlc_local = node2_htlc
77 | disabled_remote = node1_disabled
78 | disabled_local = node2_disabled
79 | if len(info) > 1:
80 | if info[1]["source"] != self.local_pubkey:
81 | assert info[0]["source"] == self.local_pubkey
82 | fee_local = node1_fee
83 | fee_remote = node2_fee
84 | htlc_local = node1_htlc
85 | htlc_remote = node2_htlc
86 | disabled_local = node1_disabled
87 | disabled_remote = node2_disabled
88 | else:
89 | fee_local = node1_fee
90 | fee_remote = 0, 0
91 | htlc_local = node1_htlc
92 | htlc_remote = None, None
93 | disabled_local = node1_disabled
94 | disabled_remote = None
95 | else:
96 | fee_local = 0, 0
97 | fee_remote = 0, 0
98 | htlc_local = None, None
99 | htlc_remote = None, None
100 | disabled_local = None
101 | disabled_remote = None
102 |
103 | chan.local_base_fee, chan.local_fee_rate = fee_local
104 | chan.remote_base_fee, chan.remote_fee_rate = fee_remote
105 | chan.local_min_htlc, chan.local_max_htlc = htlc_local
106 | chan.remote_min_htlc, chan.remote_max_htlc = htlc_remote
107 | chan.local_disabled = disabled_local
108 | chan.remote_disabled = disabled_remote
109 | chan.local_alias = self.local_alias
110 | listnode = self._run("listnodes", chan.remote_node_id)
111 | if len(listnode["nodes"]) > 0:
112 | chan.remote_alias = listnode["nodes"][0].get(
113 | "alias", chan.remote_node_id
114 | )
115 | else:
116 | chan.remote_alias = chan.remote_node_id
117 | chan.last_forward = 0
118 | chan.local_fees_msat = 0
119 | chan.remote_fees = 0
120 |
121 | self.channels[chan.chan_id] = chan
122 |
123 | fwd_events = self._run("listforwards", "status=settled")["forwards"]
124 | for fe in fwd_events:
125 | cin = fe["in_channel"]
126 | cout = fe["out_channel"]
127 | ts = int(fe.get("resolved_time", 0))
128 | #
129 | # 23.05 naming change renamed everything to _msat
130 | if "fee" in fe:
131 | fee = fe["fee"]
132 | amount_in = fe["in_msatoshi"] // 1000
133 | else:
134 | fee = fe["fee_msat"]
135 | amount_in = fe["in_msat"] // 1000
136 | if cin in self.channels:
137 | self.channels[cin].last_forward = max(
138 | ts, self.channels[cin].last_forward
139 | )
140 | self.channels[cin].remote_fees += (
141 | self.channels[cin].remote_base_fee
142 | + (self.channels[cin].remote_fee_rate * amount_in // 1000)
143 | ) // 1000
144 | if cout in self.channels:
145 | self.channels[cout].last_forward = max(
146 | ts, self.channels[cout].last_forward
147 | )
148 | self.channels[cout].local_fees_msat += fee
149 |
150 | def apply_fee_policy(self, policy):
151 | for c in self.channels.values():
152 | if c.chan_id is not None:
153 | base_fee, fee_rate, _ = policy.calculate(c)
154 | self._run(
155 | "setchannel",
156 | c.chan_id,
157 | str(base_fee),
158 | str(int(fee_rate * 1000000)),
159 | )
160 |
161 | @staticmethod
162 | def _resolve_total_msat(channel):
163 | if "msatoshi_total" in channel:
164 | return int(channel["msatoshi_total"])
165 | return channel["total_msat"]
166 |
167 | @staticmethod
168 | def _resolve_to_us_msat(channel):
169 | if "msatoshi_to_us" in channel:
170 | return int(channel["msatoshi_to_us"])
171 | return channel["to_us_msat"]
172 |
173 | @staticmethod
174 | def _cleanup_msat_value(value):
175 | if isinstance(value, str):
176 | return int(value.replace("msat", ""))
177 | return value
178 |
179 | def _run(self, *args):
180 | if self.client_args:
181 | args = ["lightning-cli"] + list(self.client_args) + list(args)
182 | else:
183 | args = ["lightning-cli"] + list(args)
184 | j = subprocess.run(args, stdout=subprocess.PIPE)
185 | return json.loads(j.stdout)
186 |
--------------------------------------------------------------------------------
/feepolicy.py:
--------------------------------------------------------------------------------
1 | import math
2 |
3 |
4 | class FeePolicy:
5 | def __init__(self, base_fee, fee_rate, fee_spread, time_lock_delta):
6 | self.base_fee = base_fee
7 | self.fee_rate = fee_rate
8 | self.fee_spread = fee_spread
9 | self.time_lock_delta = time_lock_delta
10 |
11 | def calculate(self, channel):
12 | ratio = channel.local_balance / (channel.capacity - channel.commit_fee)
13 | # -1.0 = all funds local
14 | # +1.0 = all funds remote
15 | ratio = 1.0 - 2.0 * ratio
16 | coef = math.exp(self.fee_spread * ratio)
17 | fee_rate = 0.000001 * coef * self.fee_rate
18 | if fee_rate < 0.000001:
19 | fee_rate = 0.000001
20 | base_fee = self.base_fee
21 | time_lock_delta = self.time_lock_delta
22 | return base_fee, fee_rate, time_lock_delta
23 |
--------------------------------------------------------------------------------
/lndcliclient.py:
--------------------------------------------------------------------------------
1 | import json
2 | import subprocess
3 |
4 | from lndclient import LndClient
5 |
6 |
7 | class LndCliClient(LndClient):
8 | def getinfo(self):
9 | return self._run("getinfo")
10 |
11 | def listchannels(self):
12 | return self._run("listchannels")
13 |
14 | def getchaninfo(self, chan_id):
15 | return self._run("getchaninfo", chan_id)
16 |
17 | def getnodeinfo(self, node_id):
18 | return self._run("getnodeinfo", node_id)
19 |
20 | def fwd_events(self):
21 | return self._run(
22 | "fwdinghistory", "--max_events", "50000", "--start_time", "-30d"
23 | )
24 |
25 | def updatechanpolicy(self, channel, policy):
26 | base_fee, fee_rate, time_lock_delta = policy.calculate(channel)
27 | return self._run(
28 | "updatechanpolicy",
29 | "--base_fee_msat",
30 | str(base_fee),
31 | "--fee_rate",
32 | "%0.8f" % fee_rate,
33 | "--time_lock_delta",
34 | str(time_lock_delta),
35 | "--chan_point",
36 | channel.channel_point,
37 | )
38 |
39 | def _run(self, *args):
40 | if self.client_args:
41 | args = ["lncli"] + list(self.client_args) + list(args)
42 | else:
43 | args = ["lncli"] + list(args)
44 | j = subprocess.run(args, stdout=subprocess.PIPE)
45 | return json.loads(j.stdout)
46 |
--------------------------------------------------------------------------------
/lndclient.py:
--------------------------------------------------------------------------------
1 | import abc
2 |
3 | from channel import Channel
4 |
5 |
6 | class LndClient(abc.ABC):
7 | def __init__(self, client_args):
8 | self.client_args = client_args
9 | self.refresh()
10 |
11 | @abc.abstractmethod
12 | def getinfo(self):
13 | pass
14 |
15 | @abc.abstractmethod
16 | def listchannels(self):
17 | pass
18 |
19 | @abc.abstractmethod
20 | def getchaninfo(self, chan_id):
21 | pass
22 |
23 | @abc.abstractmethod
24 | def getnodeinfo(self, node_id):
25 | pass
26 |
27 | @abc.abstractmethod
28 | def fwd_events(self):
29 | pass
30 |
31 | @abc.abstractmethod
32 | def updatechanpolicy(self, channel_point, policy):
33 | pass
34 |
35 | def refresh(self):
36 | gi = self.getinfo()
37 | self.local_pubkey = gi["identity_pubkey"]
38 | self.local_alias = gi["alias"]
39 | self.channels = {}
40 |
41 | channels = self.listchannels()["channels"]
42 | for c in channels:
43 | chan = Channel()
44 | chan.chan_id = c["chan_id"]
45 | chan.active = c["active"]
46 | chan.private = c["private"]
47 | chan.opener = "local" if c["initiator"] else "remote"
48 | chan.local_node_id, chan.remote_node_id = (
49 | self.local_pubkey,
50 | c["remote_pubkey"],
51 | )
52 | chan.channel_point = c["channel_point"]
53 | chan.uptime, chan.lifetime = int(c["uptime"]), int(c["lifetime"])
54 | chan.capacity, chan.commit_fee, chan.local_balance, chan.remote_balance = (
55 | int(c["capacity"]),
56 | int(c["commit_fee"]),
57 | int(c["local_balance"]),
58 | int(c["remote_balance"]),
59 | )
60 | try:
61 | info = self.getchaninfo(chan.chan_id)
62 | node1_policy = info["node1_policy"]
63 | node2_policy = info["node2_policy"]
64 | node1_fee = (
65 | int(node1_policy["fee_base_msat"]),
66 | int(node1_policy["fee_rate_milli_msat"]),
67 | )
68 | node1_htlc = (
69 | int(node1_policy["min_htlc"]),
70 | int(node1_policy["max_htlc_msat"]),
71 | )
72 | node1_disabled = node1_policy["disabled"]
73 | node2_fee = (
74 | int(node2_policy["fee_base_msat"]),
75 | int(node2_policy["fee_rate_milli_msat"]),
76 | )
77 | node2_htlc = (
78 | int(node2_policy["min_htlc"]),
79 | int(node2_policy["max_htlc_msat"]),
80 | )
81 | node2_disabled = node2_policy["disabled"]
82 | if info["node1_pub"] != self.local_pubkey:
83 | assert info["node2_pub"] == self.local_pubkey
84 | fee_remote = node1_fee
85 | fee_local = node2_fee
86 | htlc_remote = node1_htlc
87 | htlc_local = node2_htlc
88 | disabled_remote = node1_disabled
89 | disabled_local = node2_disabled
90 | if info["node2_pub"] != self.local_pubkey:
91 | assert info["node1_pub"] == self.local_pubkey
92 | fee_local = node1_fee
93 | fee_remote = node2_fee
94 | htlc_local = node1_htlc
95 | htlc_remote = node2_htlc
96 | disabled_local = node1_disabled
97 | disabled_remote = node2_disabled
98 | chan.local_base_fee, chan.local_fee_rate = fee_local
99 | chan.remote_base_fee, chan.remote_fee_rate = fee_remote
100 | chan.local_min_htlc, chan.local_max_htlc = htlc_local
101 | chan.remote_min_htlc, chan.remote_max_htlc = htlc_remote
102 | chan.local_disabled = disabled_local
103 | chan.remote_disabled = disabled_remote
104 | except:
105 | chan.local_base_fee, chan.local_fee_rate = None, None
106 | chan.remote_base_fee, chan.remote_fee_rate = None, None
107 | chan.local_min_htlc, chan.local_max_htlc = None, None
108 | chan.remote_min_htlc, chan.remote_max_htlc = None, None
109 | chan.local_disabled, chan.remote_disabled = None, None
110 | chan.local_alias = self.local_alias
111 | chan.remote_alias = self.getnodeinfo(chan.remote_node_id)["node"]["alias"]
112 | chan.last_forward = 0
113 | chan.local_fees_msat = 0
114 | chan.remote_fees = 0
115 |
116 | self.channels[chan.chan_id] = chan
117 |
118 | fwd_events = self.fwd_events()["forwarding_events"]
119 | for fe in fwd_events:
120 | cin = fe["chan_id_in"]
121 | cout = fe["chan_id_out"]
122 | ts = int(fe["timestamp"])
123 | fee = int(fe["fee_msat"])
124 | amt_in = int(fe["amt_in"])
125 | amt_out = int(fe["amt_out"])
126 | if cin in self.channels:
127 | self.channels[cin].last_forward = max(
128 | ts, self.channels[cin].last_forward
129 | )
130 | self.channels[cin].remote_fees += (
131 | self.channels[cin].remote_base_fee
132 | + self.channels[cin].remote_fee_rate * amt_in // 1000000
133 | )
134 | if cout in self.channels:
135 | self.channels[cout].last_forward = max(
136 | ts, self.channels[cout].last_forward
137 | )
138 | self.channels[cout].local_fees_msat += fee
139 |
140 | def apply_fee_policy(self, policy):
141 | for c in self.channels.values():
142 | self.updatechanpolicy(c, policy)
143 |
--------------------------------------------------------------------------------
/lndrestclient.py:
--------------------------------------------------------------------------------
1 | import json
2 | import posixpath
3 | import time
4 | from datetime import datetime, timedelta
5 | from pathlib import Path
6 |
7 | import requests
8 |
9 | from lndclient import LndClient
10 |
11 |
12 | class LndRestClient(LndClient):
13 | def __init__(self, client_args):
14 | args = dict(a.split("=", 1) for a in client_args)
15 |
16 | self.rpcserver = (
17 | args["rpcserver"] if "rpcserver" in args else "https://localhost:8080"
18 | )
19 | self.macaroonpath = (
20 | Path(args["macaroonpath"])
21 | if "macaroonpath" in args
22 | else Path.home()
23 | / ".lnd"
24 | / "data"
25 | / "chain"
26 | / "bitcoin"
27 | / "mainnet"
28 | / "admin.macaroon"
29 | )
30 | self.tlscertpath = str(
31 | Path(args["tlscertpath"])
32 | if "tlscertpath" in args
33 | else Path.home() / ".lnd" / "tls.cert"
34 | )
35 |
36 | self.api_base = posixpath.join(self.rpcserver, "v1")
37 |
38 | with self.macaroonpath.open("rb") as f:
39 | macaroon = f.read().hex()
40 | self.headers = {"Grpc-Metadata-macaroon": macaroon}
41 |
42 | super().__init__(client_args)
43 |
44 | def getinfo(self):
45 | return self._do_get("getinfo")
46 |
47 | def listchannels(self):
48 | return self._do_get("channels")
49 |
50 | def getchaninfo(self, chan_id):
51 | return self._do_get("graph/edge", chan_id)
52 |
53 | def getnodeinfo(self, node_id):
54 | return self._do_get("graph/node", node_id)
55 |
56 | def fwd_events(self):
57 | start_date = datetime.now() - timedelta(days=30)
58 | return self._do_post(
59 | "switch",
60 | num_max_events=50000,
61 | start_time=str(int(time.mktime(start_date.timetuple()))),
62 | )
63 |
64 | def updatechanpolicy(self, channel, policy):
65 | base_fee, fee_rate, time_lock_delta = policy.calculate(channel)
66 | funding_txid_str, output_index = channel.channel_point.split(":")
67 | return self._do_post(
68 | "chanpolicy",
69 | chan_point={
70 | "funding_txid_str": funding_txid_str,
71 | "output_index": int(output_index),
72 | },
73 | base_fee_msat=str(base_fee),
74 | fee_rate=fee_rate,
75 | time_lock_delta=time_lock_delta,
76 | )
77 |
78 | def _do_get(self, method, *args):
79 | response = requests.get(
80 | posixpath.join(self.api_base, method, *args),
81 | headers=self.headers,
82 | verify=self.tlscertpath,
83 | )
84 | return json.loads(response.text)
85 |
86 | def _do_post(self, method, **data):
87 | response = requests.post(
88 | posixpath.join(self.api_base, method),
89 | headers=self.headers,
90 | data=json.dumps(data),
91 | verify=self.tlscertpath,
92 | )
93 | return json.loads(response.text)
94 |
--------------------------------------------------------------------------------
/poetry.lock:
--------------------------------------------------------------------------------
1 | [[package]]
2 | name = "appdirs"
3 | version = "1.4.4"
4 | description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"."
5 | category = "dev"
6 | optional = false
7 | python-versions = "*"
8 |
9 | [[package]]
10 | name = "black"
11 | version = "21.6b0"
12 | description = "The uncompromising code formatter."
13 | category = "dev"
14 | optional = false
15 | python-versions = ">=3.6.2"
16 |
17 | [package.dependencies]
18 | appdirs = "*"
19 | click = ">=7.1.2"
20 | dataclasses = {version = ">=0.6", markers = "python_version < \"3.7\""}
21 | mypy-extensions = ">=0.4.3"
22 | pathspec = ">=0.8.1,<1"
23 | regex = ">=2020.1.8"
24 | toml = ">=0.10.1"
25 | typed-ast = {version = ">=1.4.2", markers = "python_version < \"3.8\""}
26 | typing-extensions = {version = ">=3.7.4", markers = "python_version < \"3.8\""}
27 |
28 | [package.extras]
29 | colorama = ["colorama (>=0.4.3)"]
30 | d = ["aiohttp (>=3.6.0)", "aiohttp-cors (>=0.4.0)"]
31 | python2 = ["typed-ast (>=1.4.2)"]
32 | uvloop = ["uvloop (>=0.15.2)"]
33 |
34 | [[package]]
35 | name = "certifi"
36 | version = "2021.5.30"
37 | description = "Python package for providing Mozilla's CA Bundle."
38 | category = "main"
39 | optional = false
40 | python-versions = "*"
41 |
42 | [[package]]
43 | name = "chardet"
44 | version = "4.0.0"
45 | description = "Universal encoding detector for Python 2 and 3"
46 | category = "main"
47 | optional = false
48 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
49 |
50 | [[package]]
51 | name = "click"
52 | version = "8.0.1"
53 | description = "Composable command line interface toolkit"
54 | category = "main"
55 | optional = false
56 | python-versions = ">=3.6"
57 |
58 | [package.dependencies]
59 | colorama = {version = "*", markers = "platform_system == \"Windows\""}
60 | importlib-metadata = {version = "*", markers = "python_version < \"3.8\""}
61 |
62 | [[package]]
63 | name = "colorama"
64 | version = "0.4.4"
65 | description = "Cross-platform colored terminal text."
66 | category = "main"
67 | optional = false
68 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
69 |
70 | [[package]]
71 | name = "commonmark"
72 | version = "0.9.1"
73 | description = "Python parser for the CommonMark Markdown spec"
74 | category = "main"
75 | optional = false
76 | python-versions = "*"
77 |
78 | [package.extras]
79 | test = ["flake8 (==3.7.8)", "hypothesis (==3.55.3)"]
80 |
81 | [[package]]
82 | name = "dataclasses"
83 | version = "0.8"
84 | description = "A backport of the dataclasses module for Python 3.6"
85 | category = "main"
86 | optional = false
87 | python-versions = ">=3.6, <3.7"
88 |
89 | [[package]]
90 | name = "idna"
91 | version = "2.10"
92 | description = "Internationalized Domain Names in Applications (IDNA)"
93 | category = "main"
94 | optional = false
95 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
96 |
97 | [[package]]
98 | name = "importlib-metadata"
99 | version = "4.6.0"
100 | description = "Read metadata from Python packages"
101 | category = "main"
102 | optional = false
103 | python-versions = ">=3.6"
104 |
105 | [package.dependencies]
106 | typing-extensions = {version = ">=3.6.4", markers = "python_version < \"3.8\""}
107 | zipp = ">=0.5"
108 |
109 | [package.extras]
110 | docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"]
111 | perf = ["ipython"]
112 | testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "packaging", "pep517", "pyfakefs", "flufl.flake8", "pytest-perf (>=0.9.2)", "pytest-black (>=0.3.7)", "pytest-mypy", "importlib-resources (>=1.3)"]
113 |
114 | [[package]]
115 | name = "mypy-extensions"
116 | version = "0.4.3"
117 | description = "Experimental type system extensions for programs checked with the mypy typechecker."
118 | category = "dev"
119 | optional = false
120 | python-versions = "*"
121 |
122 | [[package]]
123 | name = "pathspec"
124 | version = "0.8.1"
125 | description = "Utility library for gitignore style pattern matching of file paths."
126 | category = "dev"
127 | optional = false
128 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
129 |
130 | [[package]]
131 | name = "pygments"
132 | version = "2.9.0"
133 | description = "Pygments is a syntax highlighting package written in Python."
134 | category = "main"
135 | optional = false
136 | python-versions = ">=3.5"
137 |
138 | [[package]]
139 | name = "regex"
140 | version = "2021.4.4"
141 | description = "Alternative regular expression module, to replace re."
142 | category = "dev"
143 | optional = false
144 | python-versions = "*"
145 |
146 | [[package]]
147 | name = "requests"
148 | version = "2.25.1"
149 | description = "Python HTTP for Humans."
150 | category = "main"
151 | optional = false
152 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
153 |
154 | [package.dependencies]
155 | certifi = ">=2017.4.17"
156 | chardet = ">=3.0.2,<5"
157 | idna = ">=2.5,<3"
158 | urllib3 = ">=1.21.1,<1.27"
159 |
160 | [package.extras]
161 | security = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)"]
162 | socks = ["PySocks (>=1.5.6,!=1.5.7)", "win-inet-pton"]
163 |
164 | [[package]]
165 | name = "rich"
166 | version = "10.4.0"
167 | description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
168 | category = "main"
169 | optional = false
170 | python-versions = ">=3.6,<4.0"
171 |
172 | [package.dependencies]
173 | colorama = ">=0.4.0,<0.5.0"
174 | commonmark = ">=0.9.0,<0.10.0"
175 | dataclasses = {version = ">=0.7,<0.9", markers = "python_version >= \"3.6\" and python_version < \"3.7\""}
176 | pygments = ">=2.6.0,<3.0.0"
177 | typing-extensions = {version = ">=3.7.4,<4.0.0", markers = "python_version < \"3.8\""}
178 |
179 | [package.extras]
180 | jupyter = ["ipywidgets (>=7.5.1,<8.0.0)"]
181 |
182 | [[package]]
183 | name = "toml"
184 | version = "0.10.2"
185 | description = "Python Library for Tom's Obvious, Minimal Language"
186 | category = "dev"
187 | optional = false
188 | python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*"
189 |
190 | [[package]]
191 | name = "typed-ast"
192 | version = "1.4.3"
193 | description = "a fork of Python 2 and 3 ast modules with type comment support"
194 | category = "dev"
195 | optional = false
196 | python-versions = "*"
197 |
198 | [[package]]
199 | name = "typing-extensions"
200 | version = "3.10.0.0"
201 | description = "Backported and Experimental Type Hints for Python 3.5+"
202 | category = "main"
203 | optional = false
204 | python-versions = "*"
205 |
206 | [[package]]
207 | name = "urllib3"
208 | version = "1.26.6"
209 | description = "HTTP library with thread-safe connection pooling, file post, and more."
210 | category = "main"
211 | optional = false
212 | python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4"
213 |
214 | [package.extras]
215 | brotli = ["brotlipy (>=0.6.0)"]
216 | secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "ipaddress"]
217 | socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"]
218 |
219 | [[package]]
220 | name = "zipp"
221 | version = "3.4.1"
222 | description = "Backport of pathlib-compatible object wrapper for zip files"
223 | category = "main"
224 | optional = false
225 | python-versions = ">=3.6"
226 |
227 | [package.extras]
228 | docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"]
229 | testing = ["pytest (>=4.6)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pytest-cov", "pytest-enabler", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy"]
230 |
231 | [metadata]
232 | lock-version = "1.1"
233 | python-versions = "^3.6.2"
234 | content-hash = "5a3f37aa0f7830e497bc74336e71f7e53762ecb2f8a66dbb81badb70c3e3dc1f"
235 |
236 | [metadata.files]
237 | appdirs = [
238 | {file = "appdirs-1.4.4-py2.py3-none-any.whl", hash = "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128"},
239 | {file = "appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41"},
240 | ]
241 | black = [
242 | {file = "black-21.6b0-py3-none-any.whl", hash = "sha256:dfb8c5a069012b2ab1e972e7b908f5fb42b6bbabcba0a788b86dc05067c7d9c7"},
243 | {file = "black-21.6b0.tar.gz", hash = "sha256:dc132348a88d103016726fe360cb9ede02cecf99b76e3660ce6c596be132ce04"},
244 | ]
245 | certifi = [
246 | {file = "certifi-2021.5.30-py2.py3-none-any.whl", hash = "sha256:50b1e4f8446b06f41be7dd6338db18e0990601dce795c2b1686458aa7e8fa7d8"},
247 | {file = "certifi-2021.5.30.tar.gz", hash = "sha256:2bbf76fd432960138b3ef6dda3dde0544f27cbf8546c458e60baf371917ba9ee"},
248 | ]
249 | chardet = [
250 | {file = "chardet-4.0.0-py2.py3-none-any.whl", hash = "sha256:f864054d66fd9118f2e67044ac8981a54775ec5b67aed0441892edb553d21da5"},
251 | {file = "chardet-4.0.0.tar.gz", hash = "sha256:0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa"},
252 | ]
253 | click = [
254 | {file = "click-8.0.1-py3-none-any.whl", hash = "sha256:fba402a4a47334742d782209a7c79bc448911afe1149d07bdabdf480b3e2f4b6"},
255 | {file = "click-8.0.1.tar.gz", hash = "sha256:8c04c11192119b1ef78ea049e0a6f0463e4c48ef00a30160c704337586f3ad7a"},
256 | ]
257 | colorama = [
258 | {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"},
259 | {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"},
260 | ]
261 | commonmark = [
262 | {file = "commonmark-0.9.1-py2.py3-none-any.whl", hash = "sha256:da2f38c92590f83de410ba1a3cbceafbc74fee9def35f9251ba9a971d6d66fd9"},
263 | {file = "commonmark-0.9.1.tar.gz", hash = "sha256:452f9dc859be7f06631ddcb328b6919c67984aca654e5fefb3914d54691aed60"},
264 | ]
265 | dataclasses = [
266 | {file = "dataclasses-0.8-py3-none-any.whl", hash = "sha256:0201d89fa866f68c8ebd9d08ee6ff50c0b255f8ec63a71c16fda7af82bb887bf"},
267 | {file = "dataclasses-0.8.tar.gz", hash = "sha256:8479067f342acf957dc82ec415d355ab5edb7e7646b90dc6e2fd1d96ad084c97"},
268 | ]
269 | idna = [
270 | {file = "idna-2.10-py2.py3-none-any.whl", hash = "sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0"},
271 | {file = "idna-2.10.tar.gz", hash = "sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6"},
272 | ]
273 | importlib-metadata = [
274 | {file = "importlib_metadata-4.6.0-py3-none-any.whl", hash = "sha256:c6513572926a96458f8c8f725bf0e00108fba0c9583ade9bd15b869c9d726e33"},
275 | {file = "importlib_metadata-4.6.0.tar.gz", hash = "sha256:4a5611fea3768d3d967c447ab4e93f567d95db92225b43b7b238dbfb855d70bb"},
276 | ]
277 | mypy-extensions = [
278 | {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"},
279 | {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"},
280 | ]
281 | pathspec = [
282 | {file = "pathspec-0.8.1-py2.py3-none-any.whl", hash = "sha256:aa0cb481c4041bf52ffa7b0d8fa6cd3e88a2ca4879c533c9153882ee2556790d"},
283 | {file = "pathspec-0.8.1.tar.gz", hash = "sha256:86379d6b86d75816baba717e64b1a3a3469deb93bb76d613c9ce79edc5cb68fd"},
284 | ]
285 | pygments = [
286 | {file = "Pygments-2.9.0-py3-none-any.whl", hash = "sha256:d66e804411278594d764fc69ec36ec13d9ae9147193a1740cd34d272ca383b8e"},
287 | {file = "Pygments-2.9.0.tar.gz", hash = "sha256:a18f47b506a429f6f4b9df81bb02beab9ca21d0a5fee38ed15aef65f0545519f"},
288 | ]
289 | regex = [
290 | {file = "regex-2021.4.4-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:619d71c59a78b84d7f18891fe914446d07edd48dc8328c8e149cbe0929b4e000"},
291 | {file = "regex-2021.4.4-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:47bf5bf60cf04d72bf6055ae5927a0bd9016096bf3d742fa50d9bf9f45aa0711"},
292 | {file = "regex-2021.4.4-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:281d2fd05555079448537fe108d79eb031b403dac622621c78944c235f3fcf11"},
293 | {file = "regex-2021.4.4-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:bd28bc2e3a772acbb07787c6308e00d9626ff89e3bfcdebe87fa5afbfdedf968"},
294 | {file = "regex-2021.4.4-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:7c2a1af393fcc09e898beba5dd59196edaa3116191cc7257f9224beaed3e1aa0"},
295 | {file = "regex-2021.4.4-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:c38c71df845e2aabb7fb0b920d11a1b5ac8526005e533a8920aea97efb8ec6a4"},
296 | {file = "regex-2021.4.4-cp36-cp36m-manylinux2014_i686.whl", hash = "sha256:96fcd1888ab4d03adfc9303a7b3c0bd78c5412b2bfbe76db5b56d9eae004907a"},
297 | {file = "regex-2021.4.4-cp36-cp36m-manylinux2014_x86_64.whl", hash = "sha256:ade17eb5d643b7fead300a1641e9f45401c98eee23763e9ed66a43f92f20b4a7"},
298 | {file = "regex-2021.4.4-cp36-cp36m-win32.whl", hash = "sha256:e8e5b509d5c2ff12f8418006d5a90e9436766133b564db0abaec92fd27fcee29"},
299 | {file = "regex-2021.4.4-cp36-cp36m-win_amd64.whl", hash = "sha256:11d773d75fa650cd36f68d7ca936e3c7afaae41b863b8c387a22aaa78d3c5c79"},
300 | {file = "regex-2021.4.4-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:d3029c340cfbb3ac0a71798100ccc13b97dddf373a4ae56b6a72cf70dfd53bc8"},
301 | {file = "regex-2021.4.4-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:18c071c3eb09c30a264879f0d310d37fe5d3a3111662438889ae2eb6fc570c31"},
302 | {file = "regex-2021.4.4-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:4c557a7b470908b1712fe27fb1ef20772b78079808c87d20a90d051660b1d69a"},
303 | {file = "regex-2021.4.4-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:01afaf2ec48e196ba91b37451aa353cb7eda77efe518e481707e0515025f0cd5"},
304 | {file = "regex-2021.4.4-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:3a9cd17e6e5c7eb328517969e0cb0c3d31fd329298dd0c04af99ebf42e904f82"},
305 | {file = "regex-2021.4.4-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:90f11ff637fe8798933fb29f5ae1148c978cccb0452005bf4c69e13db951e765"},
306 | {file = "regex-2021.4.4-cp37-cp37m-manylinux2014_i686.whl", hash = "sha256:919859aa909429fb5aa9cf8807f6045592c85ef56fdd30a9a3747e513db2536e"},
307 | {file = "regex-2021.4.4-cp37-cp37m-manylinux2014_x86_64.whl", hash = "sha256:339456e7d8c06dd36a22e451d58ef72cef293112b559010db3d054d5560ef439"},
308 | {file = "regex-2021.4.4-cp37-cp37m-win32.whl", hash = "sha256:67bdb9702427ceddc6ef3dc382455e90f785af4c13d495f9626861763ee13f9d"},
309 | {file = "regex-2021.4.4-cp37-cp37m-win_amd64.whl", hash = "sha256:32e65442138b7b76dd8173ffa2cf67356b7bc1768851dded39a7a13bf9223da3"},
310 | {file = "regex-2021.4.4-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1e1c20e29358165242928c2de1482fb2cf4ea54a6a6dea2bd7a0e0d8ee321500"},
311 | {file = "regex-2021.4.4-cp38-cp38-manylinux1_i686.whl", hash = "sha256:314d66636c494ed9c148a42731b3834496cc9a2c4251b1661e40936814542b14"},
312 | {file = "regex-2021.4.4-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:6d1b01031dedf2503631d0903cb563743f397ccaf6607a5e3b19a3d76fc10480"},
313 | {file = "regex-2021.4.4-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:741a9647fcf2e45f3a1cf0e24f5e17febf3efe8d4ba1281dcc3aa0459ef424dc"},
314 | {file = "regex-2021.4.4-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:4c46e22a0933dd783467cf32b3516299fb98cfebd895817d685130cc50cd1093"},
315 | {file = "regex-2021.4.4-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:e512d8ef5ad7b898cdb2d8ee1cb09a8339e4f8be706d27eaa180c2f177248a10"},
316 | {file = "regex-2021.4.4-cp38-cp38-manylinux2014_i686.whl", hash = "sha256:980d7be47c84979d9136328d882f67ec5e50008681d94ecc8afa8a65ed1f4a6f"},
317 | {file = "regex-2021.4.4-cp38-cp38-manylinux2014_x86_64.whl", hash = "sha256:ce15b6d103daff8e9fee13cf7f0add05245a05d866e73926c358e871221eae87"},
318 | {file = "regex-2021.4.4-cp38-cp38-win32.whl", hash = "sha256:a91aa8619b23b79bcbeb37abe286f2f408d2f2d6f29a17237afda55bb54e7aac"},
319 | {file = "regex-2021.4.4-cp38-cp38-win_amd64.whl", hash = "sha256:c0502c0fadef0d23b128605d69b58edb2c681c25d44574fc673b0e52dce71ee2"},
320 | {file = "regex-2021.4.4-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:598585c9f0af8374c28edd609eb291b5726d7cbce16be6a8b95aa074d252ee17"},
321 | {file = "regex-2021.4.4-cp39-cp39-manylinux1_i686.whl", hash = "sha256:ee54ff27bf0afaf4c3b3a62bcd016c12c3fdb4ec4f413391a90bd38bc3624605"},
322 | {file = "regex-2021.4.4-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:7d9884d86dd4dd489e981d94a65cd30d6f07203d90e98f6f657f05170f6324c9"},
323 | {file = "regex-2021.4.4-cp39-cp39-manylinux2010_i686.whl", hash = "sha256:bf5824bfac591ddb2c1f0a5f4ab72da28994548c708d2191e3b87dd207eb3ad7"},
324 | {file = "regex-2021.4.4-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:563085e55b0d4fb8f746f6a335893bda5c2cef43b2f0258fe1020ab1dd874df8"},
325 | {file = "regex-2021.4.4-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:b9c3db21af35e3b3c05764461b262d6f05bbca08a71a7849fd79d47ba7bc33ed"},
326 | {file = "regex-2021.4.4-cp39-cp39-manylinux2014_i686.whl", hash = "sha256:3916d08be28a1149fb97f7728fca1f7c15d309a9f9682d89d79db75d5e52091c"},
327 | {file = "regex-2021.4.4-cp39-cp39-manylinux2014_x86_64.whl", hash = "sha256:fd45ff9293d9274c5008a2054ecef86a9bfe819a67c7be1afb65e69b405b3042"},
328 | {file = "regex-2021.4.4-cp39-cp39-win32.whl", hash = "sha256:fa4537fb4a98fe8fde99626e4681cc644bdcf2a795038533f9f711513a862ae6"},
329 | {file = "regex-2021.4.4-cp39-cp39-win_amd64.whl", hash = "sha256:97f29f57d5b84e73fbaf99ab3e26134e6687348e95ef6b48cfd2c06807005a07"},
330 | {file = "regex-2021.4.4.tar.gz", hash = "sha256:52ba3d3f9b942c49d7e4bc105bb28551c44065f139a65062ab7912bef10c9afb"},
331 | ]
332 | requests = [
333 | {file = "requests-2.25.1-py2.py3-none-any.whl", hash = "sha256:c210084e36a42ae6b9219e00e48287def368a26d03a048ddad7bfee44f75871e"},
334 | {file = "requests-2.25.1.tar.gz", hash = "sha256:27973dd4a904a4f13b263a19c866c13b92a39ed1c964655f025f3f8d3d75b804"},
335 | ]
336 | rich = [
337 | {file = "rich-10.4.0-py3-none-any.whl", hash = "sha256:9fb2404c4e870d4de3837c11d0cd1f26c44725865535caba1379c2343a49f6a1"},
338 | {file = "rich-10.4.0.tar.gz", hash = "sha256:6e8a3e2c61e6cf6193bfcffbb89865a0973af7779d3ead913fdbbbc33f457c2c"},
339 | ]
340 | toml = [
341 | {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"},
342 | {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"},
343 | ]
344 | typed-ast = [
345 | {file = "typed_ast-1.4.3-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:2068531575a125b87a41802130fa7e29f26c09a2833fea68d9a40cf33902eba6"},
346 | {file = "typed_ast-1.4.3-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:c907f561b1e83e93fad565bac5ba9c22d96a54e7ea0267c708bffe863cbe4075"},
347 | {file = "typed_ast-1.4.3-cp35-cp35m-manylinux2014_aarch64.whl", hash = "sha256:1b3ead4a96c9101bef08f9f7d1217c096f31667617b58de957f690c92378b528"},
348 | {file = "typed_ast-1.4.3-cp35-cp35m-win32.whl", hash = "sha256:dde816ca9dac1d9c01dd504ea5967821606f02e510438120091b84e852367428"},
349 | {file = "typed_ast-1.4.3-cp35-cp35m-win_amd64.whl", hash = "sha256:777a26c84bea6cd934422ac2e3b78863a37017618b6e5c08f92ef69853e765d3"},
350 | {file = "typed_ast-1.4.3-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:f8afcf15cc511ada719a88e013cec87c11aff7b91f019295eb4530f96fe5ef2f"},
351 | {file = "typed_ast-1.4.3-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:52b1eb8c83f178ab787f3a4283f68258525f8d70f778a2f6dd54d3b5e5fb4341"},
352 | {file = "typed_ast-1.4.3-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:01ae5f73431d21eead5015997ab41afa53aa1fbe252f9da060be5dad2c730ace"},
353 | {file = "typed_ast-1.4.3-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:c190f0899e9f9f8b6b7863debfb739abcb21a5c054f911ca3596d12b8a4c4c7f"},
354 | {file = "typed_ast-1.4.3-cp36-cp36m-win32.whl", hash = "sha256:398e44cd480f4d2b7ee8d98385ca104e35c81525dd98c519acff1b79bdaac363"},
355 | {file = "typed_ast-1.4.3-cp36-cp36m-win_amd64.whl", hash = "sha256:bff6ad71c81b3bba8fa35f0f1921fb24ff4476235a6e94a26ada2e54370e6da7"},
356 | {file = "typed_ast-1.4.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:0fb71b8c643187d7492c1f8352f2c15b4c4af3f6338f21681d3681b3dc31a266"},
357 | {file = "typed_ast-1.4.3-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:760ad187b1041a154f0e4d0f6aae3e40fdb51d6de16e5c99aedadd9246450e9e"},
358 | {file = "typed_ast-1.4.3-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:5feca99c17af94057417d744607b82dd0a664fd5e4ca98061480fd8b14b18d04"},
359 | {file = "typed_ast-1.4.3-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:95431a26309a21874005845c21118c83991c63ea800dd44843e42a916aec5899"},
360 | {file = "typed_ast-1.4.3-cp37-cp37m-win32.whl", hash = "sha256:aee0c1256be6c07bd3e1263ff920c325b59849dc95392a05f258bb9b259cf39c"},
361 | {file = "typed_ast-1.4.3-cp37-cp37m-win_amd64.whl", hash = "sha256:9ad2c92ec681e02baf81fdfa056fe0d818645efa9af1f1cd5fd6f1bd2bdfd805"},
362 | {file = "typed_ast-1.4.3-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:b36b4f3920103a25e1d5d024d155c504080959582b928e91cb608a65c3a49e1a"},
363 | {file = "typed_ast-1.4.3-cp38-cp38-manylinux1_i686.whl", hash = "sha256:067a74454df670dcaa4e59349a2e5c81e567d8d65458d480a5b3dfecec08c5ff"},
364 | {file = "typed_ast-1.4.3-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:7538e495704e2ccda9b234b82423a4038f324f3a10c43bc088a1636180f11a41"},
365 | {file = "typed_ast-1.4.3-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:af3d4a73793725138d6b334d9d247ce7e5f084d96284ed23f22ee626a7b88e39"},
366 | {file = "typed_ast-1.4.3-cp38-cp38-win32.whl", hash = "sha256:f2362f3cb0f3172c42938946dbc5b7843c2a28aec307c49100c8b38764eb6927"},
367 | {file = "typed_ast-1.4.3-cp38-cp38-win_amd64.whl", hash = "sha256:dd4a21253f42b8d2b48410cb31fe501d32f8b9fbeb1f55063ad102fe9c425e40"},
368 | {file = "typed_ast-1.4.3-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:f328adcfebed9f11301eaedfa48e15bdece9b519fb27e6a8c01aa52a17ec31b3"},
369 | {file = "typed_ast-1.4.3-cp39-cp39-manylinux1_i686.whl", hash = "sha256:2c726c276d09fc5c414693a2de063f521052d9ea7c240ce553316f70656c84d4"},
370 | {file = "typed_ast-1.4.3-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:cae53c389825d3b46fb37538441f75d6aecc4174f615d048321b716df2757fb0"},
371 | {file = "typed_ast-1.4.3-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:b9574c6f03f685070d859e75c7f9eeca02d6933273b5e69572e5ff9d5e3931c3"},
372 | {file = "typed_ast-1.4.3-cp39-cp39-win32.whl", hash = "sha256:209596a4ec71d990d71d5e0d312ac935d86930e6eecff6ccc7007fe54d703808"},
373 | {file = "typed_ast-1.4.3-cp39-cp39-win_amd64.whl", hash = "sha256:9c6d1a54552b5330bc657b7ef0eae25d00ba7ffe85d9ea8ae6540d2197a3788c"},
374 | {file = "typed_ast-1.4.3.tar.gz", hash = "sha256:fb1bbeac803adea29cedd70781399c99138358c26d05fcbd23c13016b7f5ec65"},
375 | ]
376 | typing-extensions = [
377 | {file = "typing_extensions-3.10.0.0-py2-none-any.whl", hash = "sha256:0ac0f89795dd19de6b97debb0c6af1c70987fd80a2d62d1958f7e56fcc31b497"},
378 | {file = "typing_extensions-3.10.0.0-py3-none-any.whl", hash = "sha256:779383f6086d90c99ae41cf0ff39aac8a7937a9283ce0a414e5dd782f4c94a84"},
379 | {file = "typing_extensions-3.10.0.0.tar.gz", hash = "sha256:50b6f157849174217d0656f99dc82fe932884fb250826c18350e159ec6cdf342"},
380 | ]
381 | urllib3 = [
382 | {file = "urllib3-1.26.6-py2.py3-none-any.whl", hash = "sha256:39fb8672126159acb139a7718dd10806104dec1e2f0f6c88aab05d17df10c8d4"},
383 | {file = "urllib3-1.26.6.tar.gz", hash = "sha256:f57b4c16c62fa2760b7e3d97c35b255512fb6b59a259730f36ba32ce9f8e342f"},
384 | ]
385 | zipp = [
386 | {file = "zipp-3.4.1-py3-none-any.whl", hash = "sha256:51cb66cc54621609dd593d1787f286ee42a5c0adbb4b29abea5a63edc3e03098"},
387 | {file = "zipp-3.4.1.tar.gz", hash = "sha256:3607921face881ba3e026887d8150cca609d517579abe052ac81fc5aeffdbd76"},
388 | ]
389 |
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | [tool.poetry]
2 | name = "suez"
3 | version = "0.1.0"
4 | description = "Tool for optimizing Lightning Network channels"
5 | authors = ["Pavol Rusnak "]
6 | license = "GPL-3.0-or-later"
7 |
8 | [tool.poetry.dependencies]
9 | python = "^3.6.2"
10 | rich = "^10.2.2"
11 | click = "^8.0.1"
12 | requests = "^2.25.1"
13 | dataclasses = {version = "^0.8", python = "~3.6"}
14 |
15 | [tool.poetry.dev-dependencies]
16 | black = "^21.5b2"
17 |
18 | [build-system]
19 | requires = ["poetry-core>=1.0.0"]
20 | build-backend = "poetry.core.masonry.api"
21 |
--------------------------------------------------------------------------------
/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/prusnak/suez/4b2a4ff187ff2e478ed64155303b624dd6585634/screenshot.png
--------------------------------------------------------------------------------
/shell.nix:
--------------------------------------------------------------------------------
1 | with import {};
2 |
3 | let
4 | SuezPython = python3.withPackages(ps: [
5 | ps.black
6 | ps.click
7 | ps.rich
8 | ]);
9 |
10 | in
11 |
12 | stdenv.mkDerivation {
13 | name = "suez-env";
14 | buildInputs = [
15 | SuezPython
16 | poetry
17 | ];
18 | }
19 |
--------------------------------------------------------------------------------
/suez:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | from suez import suez
3 |
4 | if __name__ == "__main__":
5 | suez(auto_envvar_prefix="SUEZ")
6 |
--------------------------------------------------------------------------------
/suez.py:
--------------------------------------------------------------------------------
1 | from datetime import datetime
2 |
3 | import click
4 | from rich import box, markup
5 | from rich.console import Console
6 | from rich.table import Table
7 |
8 | from clnclient import ClnClient
9 | from feepolicy import FeePolicy
10 | from lndcliclient import LndCliClient
11 | from lndrestclient import LndRestClient
12 | from terminal_web import TerminalWeb
13 |
14 |
15 | def _sort_channels(c):
16 | return c.local_balance / (c.capacity - c.commit_fee)
17 |
18 |
19 | def _since(ts):
20 | d = datetime.utcnow() - datetime.utcfromtimestamp(ts)
21 | return f"{d.total_seconds() / 86400:.1f}"
22 |
23 |
24 | def _resolve_htlc(htlc_msat):
25 | if htlc_msat is None:
26 | return "-"
27 | htlc_sat = htlc_msat / 1000
28 | htlc_sat = int(htlc_sat) if htlc_sat == int(htlc_sat) else htlc_sat
29 | return f"{htlc_sat:,}"
30 |
31 |
32 | def _resolve_disabled(c):
33 | local = "y" if c.local_disabled else "n" if c.local_disabled is not None else "-"
34 | remote = "y" if c.remote_disabled else "n" if c.remote_disabled is not None else "-"
35 | return f"[bright_blue]{local}[/bright_blue]|[bright_yellow]{remote}[/bright_yellow]"
36 |
37 |
38 | def _resolve_good_peer(c, terminal_web):
39 | good_in = terminal_web.is_good_inbound_peer(c.remote_node_id)
40 | good_out = terminal_web.is_good_outbound_peer(c.remote_node_id)
41 | res_in = "[green]y[/green]" if good_in else "[bright_red]n[/bright_red]"
42 | res_out = "[green]y[/green]" if good_out else "[bright_red]n[/bright_red]"
43 | return res_in + "|" + res_out
44 |
45 |
46 | def info_box(ln, terminal_web):
47 | grid = Table.grid()
48 | grid.add_column(style="bold")
49 | grid.add_column()
50 | grid.add_row("pubkey : ", ln.local_pubkey)
51 | grid.add_row("alias : ", ln.local_alias)
52 | grid.add_row("channels : ", f"{len(ln.channels):,}")
53 | if terminal_web.show_scores:
54 | score = terminal_web.get_score(ln.local_pubkey)
55 | score = f"{score:,}" if score is not None else "-"
56 | grid.add_row("score : ", score)
57 | return grid
58 |
59 |
60 | def channelcount_info_box(count, channel_type):
61 | grid = Table.grid()
62 | grid.add_column(style="bold")
63 | grid.add_column()
64 | grid.add_row(f"{channel_type} channels : ", f"{count}")
65 | return grid
66 |
67 |
68 | def channel_table(
69 | channels,
70 | terminal_web,
71 | show_remote_fees,
72 | show_chan_ids,
73 | show_forwarding_stats,
74 | show_minmax_htlc,
75 | show_disabled,
76 | ):
77 | table = Table(box=box.SIMPLE)
78 | table.add_column("\ninbound", justify="right", style="bright_red")
79 | table.add_column("\nratio", justify="center")
80 | table.add_column("\noutbound", justify="right", style="green")
81 | if show_disabled:
82 | table.add_column("is\ndisabled", justify="right")
83 | if show_minmax_htlc:
84 | table.add_column("local\nmin_htlc\n(sat)", justify="right", style="bright_blue")
85 | table.add_column("local\nmax_htlc\n(sat)", justify="right", style="bright_blue")
86 | table.add_column(
87 | "remote\nmin_htlc\n(sat)", justify="right", style="bright_yellow"
88 | )
89 | table.add_column(
90 | "remote\nmax_htlc\n(sat)", justify="right", style="bright_yellow"
91 | )
92 | table.add_column("local\nbase_fee\n(msat)", justify="right", style="bright_blue")
93 | table.add_column("local\nfee_rate\n(ppm)", justify="right", style="bright_blue")
94 | table.add_column("remote\nbase_fee\n(msat)", justify="right", style="bright_yellow")
95 | table.add_column("remote\nfee_rate\n(ppm)", justify="right", style="bright_yellow")
96 | table.add_column("\nuptime\n(%)", justify="right")
97 | table.add_column("last\nforward\n(days)", justify="right")
98 | table.add_column("local\nfees\n(sat)", justify="right", style="bright_cyan")
99 | if show_forwarding_stats:
100 | table.add_column("\nfwd in", justify="right")
101 | table.add_column("\nin %", justify="right")
102 | table.add_column("\nfwd out", justify="right")
103 | table.add_column("\nout %", justify="right")
104 | if show_remote_fees:
105 | table.add_column("remote\nfees\n(sat)", justify="right", style="bright_cyan")
106 | if terminal_web.show_good_peers:
107 | table.add_column("good\npeer\n(in|out)", justify="right")
108 | if terminal_web.show_scores:
109 | table.add_column("\nscore", justify="right")
110 | table.add_column("\nalias", max_width=25, no_wrap=True)
111 | if show_chan_ids:
112 | table.add_column("\nchan_id")
113 |
114 | total_local, total_fees_local = 0, 0
115 | total_remote, total_fees_remote = 0, 0
116 | local_base_fees, local_fee_rates = [], []
117 | remote_base_fees, remote_fee_rates = [], []
118 |
119 | for c in sorted(channels, key=_sort_channels):
120 | send = int(round(10 * c.local_balance / (c.capacity - c.commit_fee)))
121 | recv = 10 - send
122 | bar = (
123 | "[bright_red]"
124 | + ("·" * recv)
125 | + "[/bright_red]"
126 | + "|"
127 | + "[green]"
128 | + ("·" * send)
129 | + "[/green]"
130 | )
131 | if c.uptime is not None and c.lifetime:
132 | uptime = 100 * c.uptime // c.lifetime
133 | else:
134 | uptime = "n/a"
135 | total_fees_local += c.local_fees_msat
136 | total_fees_remote += c.remote_fees
137 | total_local += c.local_balance
138 | total_remote += c.remote_balance
139 | if c.local_base_fee is not None:
140 | local_base_fees.append(c.local_base_fee)
141 | if c.local_fee_rate is not None:
142 | local_fee_rates.append(c.local_fee_rate)
143 | if c.remote_base_fee is not None:
144 | remote_base_fees.append(c.remote_base_fee)
145 | if c.remote_fee_rate is not None:
146 | remote_fee_rates.append(c.remote_fee_rate)
147 | columns = [
148 | f"{c.remote_balance:,}",
149 | bar,
150 | f"{c.local_balance:,}",
151 | ]
152 | if show_disabled:
153 | columns += [
154 | _resolve_disabled(c),
155 | ]
156 | if show_minmax_htlc:
157 | columns += [
158 | _resolve_htlc(c.local_min_htlc),
159 | _resolve_htlc(c.local_max_htlc),
160 | _resolve_htlc(c.remote_min_htlc),
161 | _resolve_htlc(c.remote_max_htlc),
162 | ]
163 | columns += [
164 | str(c.local_base_fee) if c.local_base_fee is not None else "-",
165 | str(c.local_fee_rate) if c.local_fee_rate is not None else "-",
166 | str(c.remote_base_fee) if c.remote_base_fee is not None else "-",
167 | str(c.remote_fee_rate) if c.remote_fee_rate is not None else "-",
168 | f"[green]{uptime}[/green]"
169 | if c.active
170 | else f"[bright_red]{uptime}[/bright_red]",
171 | _since(c.last_forward) if c.last_forward else "never",
172 | f"{round(c.local_fees_msat / 1000):,}"
173 | if c.local_fees_msat
174 | else "-",
175 | ]
176 | if show_forwarding_stats:
177 | columns += [
178 | f"{c.ins}",
179 | f"{c.ins_percent:.0%}",
180 | f"{c.outs}",
181 | f"{c.outs_percent:.0%}",
182 | ]
183 | if show_remote_fees:
184 | columns += [
185 | f"{c.remote_fees:,}" if c.remote_fees else "-",
186 | ]
187 | if terminal_web.show_good_peers:
188 | columns += [
189 | _resolve_good_peer(c, terminal_web),
190 | ]
191 | if terminal_web.show_scores:
192 | s = terminal_web.get_score(c.remote_node_id)
193 | columns += [
194 | f"{s:,}" if s is not None else "-",
195 | ]
196 | alias_color = "bright_blue" if c.opener == "local" else "bright_yellow"
197 | alias = c.remote_alias if c.remote_alias else c.remote_node_id[:16]
198 | columns += [
199 | f"[{alias_color}]{markup.escape(alias)}[/{alias_color}]",
200 | ]
201 | if show_chan_ids:
202 | columns += [c.chan_id]
203 | table.add_row(*columns)
204 |
205 | columns = [
206 | "─" * 6,
207 | None,
208 | "─" * 6,
209 | ]
210 | if show_disabled:
211 | columns += [
212 | None,
213 | ]
214 | if show_minmax_htlc:
215 | columns += [
216 | None,
217 | None,
218 | None,
219 | None,
220 | ]
221 | columns += [
222 | "─" * 4,
223 | "─" * 4,
224 | "─" * 4,
225 | "─" * 4,
226 | None,
227 | None,
228 | "─" * 6,
229 | ]
230 | if show_remote_fees:
231 | columns += ["─" * 6]
232 | table.add_row(*columns)
233 | columns = [
234 | f"{total_remote:,}",
235 | None,
236 | f"{total_local:,}",
237 | ]
238 | if show_disabled:
239 | columns += [
240 | None,
241 | ]
242 | if show_minmax_htlc:
243 | columns += [
244 | None,
245 | None,
246 | None,
247 | None,
248 | ]
249 | columns += [
250 | f"{sum(local_base_fees) // len(local_base_fees)}",
251 | f"{sum(local_fee_rates) // len(local_fee_rates)}",
252 | f"{sum(remote_base_fees) // len(remote_base_fees)}",
253 | f"{sum(remote_fee_rates) // len(remote_fee_rates)}",
254 | None,
255 | None,
256 | f"{round(total_fees_local / 1000):,}",
257 | ]
258 | if show_remote_fees:
259 | columns += [
260 | f"{total_fees_remote:,}",
261 | ]
262 | table.add_row(*columns)
263 | return table
264 |
265 |
266 | @click.command()
267 | @click.option("--base-fee", default=0, help="Set base fee.")
268 | @click.option("--fee-rate", default=0, help="Set fee rate.")
269 | @click.option("--fee-spread", default=0.0, help="Fee spread.")
270 | @click.option("--time-lock-delta", default=40, help="Set time lock delta.")
271 | @click.option(
272 | "--client",
273 | default="lnd",
274 | type=click.Choice(("lnd", "c-lightning", "lnd-rest"), case_sensitive=False),
275 | help="Type of LN client.",
276 | )
277 | @click.option(
278 | "--client-args",
279 | default=[],
280 | multiple=True,
281 | help="Extra arguments to pass to client RPC.",
282 | )
283 | @click.option(
284 | "--show-remote-fees", is_flag=True, help="Show (estimate of) remote fees."
285 | )
286 | @click.option(
287 | "--show-scores", is_flag=True, help="Show node scores (from Lightning Terminal)."
288 | )
289 | @click.option(
290 | "--show-good-peers", is_flag=True, help="Show good peers (from Lightning Terminal)."
291 | )
292 | @click.option("--show-chan-ids", is_flag=True, help="Show channel ids.")
293 | @click.option(
294 | "--show-forwarding-stats",
295 | is_flag=True,
296 | help="Show forwarding counts and success percentages (CLN)",
297 | )
298 | @click.option("--show-minmax-htlc", is_flag=True, help="Show min and max htlc.")
299 | @click.option("--show-disabled", is_flag=True, help="Show if channel is disabled.")
300 | @click.option(
301 | "--channels",
302 | default="all",
303 | type=click.Choice(("all", "public", "private", "split"), case_sensitive=False),
304 | help="Which channels to select/show.",
305 | )
306 | def suez(
307 | base_fee,
308 | fee_rate,
309 | fee_spread,
310 | time_lock_delta,
311 | client,
312 | client_args,
313 | show_remote_fees,
314 | show_scores,
315 | show_good_peers,
316 | show_chan_ids,
317 | show_forwarding_stats,
318 | show_minmax_htlc,
319 | show_disabled,
320 | channels,
321 | ):
322 | clients = {
323 | "lnd": LndCliClient,
324 | "c-lightning": ClnClient,
325 | "lnd-rest": LndRestClient,
326 | }
327 |
328 | ln = clients[client](client_args)
329 |
330 | if len(ln.channels) == 0:
331 | click.echo("No channels found. Exiting")
332 | return
333 |
334 | terminal_web = TerminalWeb(ln.local_pubkey, show_scores, show_good_peers)
335 |
336 | if fee_rate:
337 | policy = FeePolicy(base_fee, fee_rate, fee_spread, time_lock_delta)
338 | ln.apply_fee_policy(policy)
339 | ln.refresh()
340 |
341 | info = info_box(ln, terminal_web)
342 |
343 | console = Console()
344 | console.print()
345 | console.print(info)
346 |
347 | if channels == "split":
348 | public_channels = [c for c in ln.channels.values() if not c.private]
349 | private_channels = [c for c in ln.channels.values() if c.private]
350 |
351 | if len(public_channels) > 0:
352 | public_table = channel_table(
353 | public_channels,
354 | terminal_web,
355 | show_remote_fees,
356 | show_chan_ids,
357 | show_forwarding_stats,
358 | show_minmax_htlc,
359 | show_disabled,
360 | )
361 | public_info = channelcount_info_box(len(public_channels), "public")
362 | console.print(public_table)
363 | console.print(public_info)
364 |
365 | if len(private_channels) > 0:
366 | private_table = channel_table(
367 | private_channels,
368 | terminal_web,
369 | show_remote_fees,
370 | show_chan_ids,
371 | show_forwarding_stats,
372 | show_minmax_htlc,
373 | show_disabled,
374 | )
375 | private_info = channelcount_info_box(len(private_channels), "private")
376 | console.print(private_table)
377 | console.print(private_info)
378 | console.print()
379 |
380 | else:
381 | if channels == "public":
382 | show_channels = [c for c in ln.channels.values() if not c.private]
383 | elif channels == "private":
384 | show_channels = [c for c in ln.channels.values() if c.private]
385 | else: # all
386 | show_channels = ln.channels.values()
387 |
388 | if len(show_channels) > 0:
389 | table = channel_table(
390 | show_channels,
391 | terminal_web,
392 | show_remote_fees,
393 | show_chan_ids,
394 | show_forwarding_stats,
395 | show_minmax_htlc,
396 | show_disabled,
397 | )
398 | console.print(table)
399 |
--------------------------------------------------------------------------------
/terminal_web.py:
--------------------------------------------------------------------------------
1 | import requests
2 |
3 |
4 | class TerminalWeb:
5 | def __init__(self, local_pubkey, show_scores, show_good_peers):
6 | self.local_pubkey = local_pubkey
7 | self.show_scores = show_scores
8 | self.show_good_peers = show_good_peers
9 | if show_scores or show_good_peers:
10 | try:
11 | r = requests.get(
12 | "https://ln-scores.prod.lightningcluster.com/availability/v3/btc_summary.json",
13 | headers={"referer": "https://terminal.lightning.engineering/"},
14 | )
15 | j = r.json()
16 | self.nodes = j["scored"]
17 | self.local_node = self.nodes.get(local_pubkey)
18 | except:
19 | self.nodes = {}
20 | self.local_node = None
21 |
22 | def is_good_inbound_peer(self, remote_pubkey):
23 | if not self.local_node or "good_inbound_peers" not in self.local_node:
24 | return False
25 | return remote_pubkey in self.local_node["good_inbound_peers"]
26 |
27 | def is_good_outbound_peer(self, remote_pubkey):
28 | if not self.local_node or "good_outbound_peers" not in self.local_node:
29 | return False
30 | return remote_pubkey in self.local_node["good_outbound_peers"]
31 |
32 | def get_score(self, pubkey):
33 | node = self.nodes.get(pubkey)
34 | return node["score"] if node else None
35 |
--------------------------------------------------------------------------------