-
Notifications
You must be signed in to change notification settings - Fork 974
[plugin] Plugin that depicts the off- and onchain funds in a nicer overview #2139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
plugins/funds.py
Outdated
| from lightning.lightning import LightningRpc | ||
| from os.path import expanduser | ||
|
|
||
| path = expanduser("~/.lightning/lightning-rpc") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was talking explicitly about this line. My feeling is that I should be able to send RPC calls via json directly to the lightningdaemon. However I don't know the format of the json and it is not documented yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2131 will contain a configuration field in the configure call that'll explicitly tell you were to connect 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2131 didn't? I have a patch which adds a 'rpc_filename' to the init msg however, will push (I needed this too, of course)!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I will be able to find this in def json_init() in the options argument?
How can I look at these variables? Since stdout is sent to lightningd I can't print variables to inspect them which is annoying
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, where did that patch end up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I stashed it... I'll reapply it
plugins/funds.py
Outdated
|
|
||
|
|
||
| def json_get_funds(request, unit="s"): | ||
| if unit.lower() == "bitcoin" or unit.lower() == "btc": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about creating a dict that maps the long form to the short form? If you do the reverse step, you can also create the inverse map with a simple dict comprehension :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah dict will be more python style
plugins/funds.py
Outdated
| m, milli, btc to depict milliBitcoin | ||
| B, bitcoin, btc to depict Bitcoins | ||
|
|
||
| When not using Satshis (default) the comma values are rounded off.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: Satshis -> Satoshis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No millisatoshi option?
plugins/funds.py
Outdated
| outputs = funds["outputs"] | ||
| onchain_value = 0 | ||
| for output in outputs: | ||
| onchain_value += int(output["value"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing wrong with this code, but fyi, you can also use list comprehensions to shorten this down a bit to something like:
onchain_value = sum([int(output['value']) for output in funds['outputs']])
offchain_value = sum([int(channel["channel_sat"]) for channel in funds['channels']])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I will do that since I have to touch the code once more anyway (:
|
Cool! There should be lots of nice simple plugins that can be added, and it's nice to have a reference for a 'standard' plugin Would also be nice to add unconfirmed balance later if #2104 is implemented, but I understand this may just be a sample. As a general question to @cdecker and @rustyrussell .... Is there a general idea or documentation in mind for some 'standard' plugins to be released with c-lightning? Something like Sorry to hijack the comments @renepickhardt - Looking forward to seeing the autopilot revived :) |
1d915c1 to
2f19975
Compare
|
I rebased the master and have made the requested changes and also merged #2141 in this branch as this plugin relies on the fact that the deamon is giving us the location of the RPC interface in the init message. I thought this is the best way to do so otherwise we would have to touch this plugin again once #2141 is merged |
Well, |
2f19975 to
d14baa4
Compare
|
@cdecker @rustyrussell I have force pushed the code once more to have the plugin in the required location and I have also taken back my early merge of #2141 . I guess this plugin should now be ready to be merged (: On the way I have created a more complex (in the sense of more third party technologies that have been used) plugin over at #2152 . Once these two are merged I guess I will be able to transfer the code of #1888 to the plugin architecture. Should the autopilot be placed in |
d14baa4 to
681c40d
Compare
|
I have yet updated the plugin to the new python bindings which makes use of the decorators so that there is no more boilerplate code left in the plugin code. If everything is fine now and the plugin can be merged I would love to create the educational video about the plugin system soon (: |
cdecker
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor comments, and improvements.
As discussed on IRC, I'm considering to add a new repository that serves as a nursery for these tiny plugins, and only bundle a few very select plugins into the c-lightning distribution by default.
contrib/plugins/funds/funds.py
Outdated
| plugin.log("Funds Plugin successfully initialezed") | ||
|
|
||
|
|
||
| plugin.add_option('funds', 'funds', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This option doesn't really seem to do anything. From the description I take it that it's supposed to be the @plugin.method call above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you could do instead is provide the default unit here, so that on startup we can chose whether we'd like to display in satoshis, bits, mBTC or BTC by default.
Another option that would make sense is the number of decimal places to show.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I did not understand the add_option() call correctly. I had the feeling this was similar to the entry in the get_manifest that I had to be used previously. I guess I got that wrong. Will take a closer look at the implementation tomorrow. default display is satoshis btw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_option will add command line options to lightningd when starting the daemon and the option values will be passed to the plugin on init. So this declaration would result in a command line option funds with default value funds for the lightningd. So this would be perfectly fine:
lightningd --funds=bla
But then you don't extract and store the value of that option, so it's not being used at all 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn it I already knew that. But with the frequent api changes I oversaw that. Well certainly fix that (:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also I am just happy that I made this mistake. I will try to change the code so that I will add an argument ---fundsunit=s to lightningd which would set the standard value for the command line tool. this is also good for educational purpose to see the difference and both methods
|
Will fix those changes. I have uploaded the current version (before I saw your feedback) and with regard to the conversation in the irc to https://github.com/renepickhardt/c-lightning-plugin-collection (where I would also publish the donation plugin and the autopilot) |
Absolutely, my plan is to externally curate a list somewhere and pull plugins in as they grow in popularity. Maybe some sort of plugin manager might be in order. But I'll definitely bundle things like the autopilot at least during release. |
…dard unit via an argument of lightningd
|
I have changed the requested changes (besides replacing As a side effect I have opened #2217 which still seems like a pitty to me. |
|
The following has just occurred in playing with another balance plugin:
For this reason, I think the plugin will 'count' a closed channel into the "offchain" (channel) balance, as well as the "onchain" balance at the same time. The correct behavior would be to not count a closed channel as part of the channel balance. If calculating from Should If it's still desired to list it, perhaps it makes sense to add the channel state so people have to the context to know its closed / closing. |
|
btw - working on a 'balance of every possible thing' plugin here if anyone reading is interested. https://github.com/conscott/c-lightning-plugins/blob/master/balance.py |
|
Since we now have quite a few plugins that will address this I think I'll close this 😉 |
the plugins directory doesn't seem to work yet. I had to call the plugin explicitly with
lightningd --plugin=/Users/rpickhardt/hacken/lightning/plugins/funds.pynot sure though weather this plugin should be a standard plugin anyway.you can test the plugin with:
lightning-cli fundsand the output should be similar to this:{"total_sat": 200000, "onchain_sat": 100000, "offchain_sat": 100000}if you call the plugin with the
margument the ammounts are depicted in millibitoins (other units are available via help) eg:I will probably use this plugin as a tutorial for next Mondays youtube video, so that people can learn how easy it is to create plugins in c-lightning (chapeau for @cdecker )
I have prepared a couple more plugins (for example for channel balance overview, an invoice server for donations, maybe even the spontaneous payments one) but I would like to have feedback on this "quicky" first instead of pushing several plugins.
Once the easy ones are there I will transfer my autopilot code to the plugin system.
I have also some feedback where the current system could be improved to ease up the life of developers. Should I do this as a pull request?
Also is there a better way to talk to the RPC interface (for example directly via stdout) so that the plugin does not need to know where the rpc-interface is located?