![]() |
![]()
| ![]() |
![]()
NAMElightningd-rpc -- Lightning Daemon RPC Protocols SYNOPSIS~/.lightning/bitcoin/lightning-rpc DESCRIPTIONlightningd(8) communicates via RPC, especially JSONRPC over the UNIX domain socket (by default $HOME/.lightning/bitcoin/lightning-rpc, but configuable with lightningd-config(5)). JSON WIRE FORMATJSON RPC is defined at https://www.jsonrpc.org/specification and generally involves writing a JSON request with a unique ID, and receiving a response containing that ID. Every response given by lightningd(8) is followed by two '\n' characters, which should not appear in normal JSON (though plugins may produce them). This means efficient code can simply read until it sees two '\n' characters, and then attempt to parse the JSON (if the JSON is incomplete, it should continue reading and file a bug). JSON COMMANDSWe support "params" as an array (ordered parameters) or a dictionary (named parameters). In the array case, JSON "null" is treated as if the parameter was not specified (if that is allowed). You should probably prefer named parameters if possible, as they have generally been shown to be less confusing for complex commands and more robust when fields are deprecated. The $ lightning-cli(1) tool uses ordered parameters by default, but named parameters if explicitly specified or the first parameter contains an '='. JSON IDSJSON id fields in requests are used to match requests and responses. These used to be simple numbers, but with modern plugins that is deprecated: we use a specific format, which makes them very useful for debugging and tracking the cause of commands: JSONID := IDPART ['/' IDPART]* IDPART := PREFIX ':' METHOD '#' NUMBER PREFIX is cln for the main daemon, cli for $ lightning-cli, and should be the plugin name for plugins. METHOD is an internal identifier, indicating what caused the request: for cli it's simply the method it's invoking, but for plugins it may be the routine which created the request. And NUMBER ensures uniqueness (it's usually a simple increment). Importantly for plugins, incoming requests often trigger outgoing requests, and for these, the outgoing request id is created by appending a / and another id part into the incoming. This makes the chain of responsibility much clearer. e.g, this shows the JSON id of a sendrawtransaction RPC call, and we can tell that $ lightning-cli has invoked the withdraw command, which lightningd passes through to the txprepare plugin, which called sendrawtransaction. cli:withdraw#123/cln:withdraw#7/txprepare:sendpsbt#1/cln:sendrawtransaction#9 JSON REPLIESAll JSON replies are wrapped in an object; this allows fields to be added in future. You should safely ignore any unknown fields. Any field name which starts with "warning" is a specific warning, and should be documented in the commands' manual page. Each warning field has an associated human-readable string, but it's redudant, as each separate warning should have a distinct field name (e.g. warning_offer_unknown_currency and warning_offer_missing_description). JSON TYPESThe exact specification for (most!) commands is specified in doc/schemas/ in the source directory. This is also used to generate part of the documentation for each command; the following types are referred to in addition to simple JSON types:
The following forms of msat are supported as parameters:
JSON NOTIFICATIONSNotifications are (per JSONRPC spec) JSON commands without an "id" field. They give information about ongoing commands, but you need to enable them. See lightning-notifications(7). FIELD FILTERINGYou can restrict what fields are in the output of any command, by including a "filter" member in your request, alongside the standard "method" and "params" fields. filter is a template, with keys indicating what fields are to be output (values must be true). Only fields which appear in the template will be output. For example, here is a normal result of listtransactions: "result": { If we only wanted the output amounts and types, we would create a filter like so: "filter": {"transactions": [{"outputs": [{"amount_msat": true, "type": true}]}]} The result would be: "result": { Note: "filter" doesn't change the order, just which fields are printed. Any fields not explicitly mentioned are omitted from the output, but plugins which don't support filter (and some routines doing simple JSON transfers) may ignore "filter", so you should treat it as an optimazation only). Note: if you specify an array where an object is specified or vice versa, the response may include a warning_parameter_filter field which describes the problem. DEALING WITH FORMAT CHANGESFields can be added to the JSON output at any time, but to remove (or, very rarely) change a field requires a minimum deprecation period of 6 months and two releases. Usually a new field will be added if one is deprecated, so both will be present in transition. To test that you're not using deprecated fields, you can use the lightningd-config(5) option allow-deprecated-apis=false. You should only use this in internal tests: it is not recommended that users use this directly. The documentation tends to only refer to non-deprecated items, so if you seen an output field which is not documented, its either a bug (like that ever happens!) or a deprecated field you should ignore. DEBUGGINGYou can use log-level=io to see much of the JSON conversation (in hex) that occurs. It's extremely noisy though! AUTHORRusty Russell <rusty@rustcorp.com.au> wrote this man page, and much of the configuration language, but many others did the hard work of actually implementing these options. SEE ALSOlightningd-config(5), lightning-notifications(7), lightningd(8) RESOURCESMain web site: https://github.com/ElementsProject/lightning COPYINGNote: the modules in the ccan/ directory have their own licenses, but the rest of the code is covered by the BSD-style MIT license.
|