ElementsProject / lightning

Core Lightning — Lightning Network implementation focusing on spec compliance and performance
Other
2.87k stars 906 forks source link

Constant variables in pyln for API key words in JSON-RPC #3718

Open renepickhardt opened 4 years ago

renepickhardt commented 4 years ago

When using pyln I have calls like channels = plugin.rpc.listfunds()["channels"] it is really a pitty that I have to type those strings when accessing the JSON fields. In particular my LAPPS and Plugins would break if for whatever reason lightning should change those keys. But more problematic is that I could have typos or similar.

It would be really nice to have constants in pyln that can be used to access keys in the results from the JSON rpc and to ship this with plyln

cdecker commented 4 years ago

I thought about offering an additional layer on top of the raw API, that parses the results into python objects (allowing things like node.peers[0].channels[0].short_channel_id instead of walking just anonymous dicts. If we annotate the classes with type decorators we can even statically check access.

Does that sound reasonable?