Commit Graph

40 Commits

Author SHA1 Message Date
Rusty Russell 9361b62e3a libplugin: add command_hook_success helper.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-02 10:38:04 +10:30
Rusty Russell 62c52fe868 libplugin: add support for before and after deps on hooks.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-11-09 15:22:33 -06:00
Rusty Russell 127811757f libplugin: support for sending notifications.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: libplugin: routines to send notification updates and progress.
2020-10-23 13:53:16 +10:30
Rusty Russell fc097b8b48 libplugin: allow commands and options to mark themselves deprecated.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-08-11 08:43:18 +09:30
Christian Decker eb322b114b plugin: Do not automatically initialize the RPC connection in bcli
Changelog-Fixed: plugin: `bcli` no longer logs a harmless warning about being unable to connect to the JSON-RPC interface.
Changelog-Added: plugin: Plugins can opt out of having an RPC connection automatically initialized on startup.
2020-07-23 10:14:21 +09:30
Christian Decker de75d3ac0c mpp: Add CLI option to opt-out of multi-part payments
Several tests are not well-suited for mpp, so I added a CLI option to opt-out
of the MPP support at startup time.
2020-07-15 11:32:58 +02:00
Christian Decker f557955515 paymod: Consolidate parsing RPC results in libplugin
We handle these in a number of different ways, and regularly get the parsing
and logic for optional fields wrong, so let's consolidate them here.
2020-07-07 23:25:45 +02:00
Christian Decker e03acd9663 libplugin: Add features to plugin_main and getmanifest 2020-04-16 18:03:35 +09:30
Rusty Russell 8cb364dd28 libplugin: demarshal and stash the feature set given by lightningd.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-04-03 13:13:21 +10:30
darosior 902edf56e6 libplugin: allow u32 options 2020-03-30 20:17:18 +10:30
darosior e7b0c24db2 libplugin: use a typesafe_cb for plugin_timer 2020-02-18 10:21:48 +10:30
darosior 3eb0f56f87 libplugin: generalize the plugin_timer callback type
We don't take the callback result into account, so it can better be void.
Having a general callback parameter is handy, because for bcli we want
to pass it the struct bcli.
2020-02-12 11:45:07 +10:30
darosior b0b55d36ef libplugin: add a 'still_pending' helper 2020-02-12 11:45:07 +10:30
darosior 2bff80e3de libplugin: use json_stream helpers for RPC calls
This adds helpers to start and send a jsonrpc request using json_stream
in order to benefit from the helpers.

This then simplifies existing plugins RPC requests by using json_stream
helpers.
2020-02-10 09:49:15 +10:30
darosior 45e9f53c6b libplugin: expose helpers to start and end a jsonrpc response
The usual json_stream starters and command_result enders.
2020-02-10 09:49:15 +10:30
darosior 4772025b5d libplugin don't expose the plugin struct 2020-02-05 17:05:56 +10:30
darosior b6b2e6727e libplugin: make deprecated_apis a global 2020-02-05 17:05:56 +10:30
darosior 02fe34ed95 libplugin: don't expose the rpc_conn struct 2020-02-04 13:24:32 +10:30
darosior b31e3b1541 libplugin: pass a pointer to plugin to send_outreq
autoclean needs to send outreqs from a timer cb, hence with cmd == NULL.
2020-02-04 13:24:32 +10:30
darosior c765a223f1 libplugin: use ccan/io for async Rpc requests 2020-02-04 13:24:32 +10:30
darosior 765626875e libplugin: use ccan/io for notifications 2020-02-04 13:24:32 +10:30
darosior 9ebfdf0b8c libplugin: add remaining globals to the global state
But not the outreqs helpers, which will be moved when passing
send_outreq_ to using ccan/io.
2020-02-04 13:24:32 +10:30
darosior 499dce1c38 libplugin: include the rpc conn into the global state
And rename the struct name, as it's now only used for RPC.
2020-02-04 13:24:32 +10:30
Vasil Dimov 55173a56b7 Use dedicated type for error codes
Before this patch we used `int` for error codes. The problem with
`int` is that we try to pass it to/from wire and the size of `int` is
not defined by the standard. So a sender with 4-byte `int` would write
4 bytes to the wire and a receiver with 2-byte `int` (for example) would
read just 2 bytes from the wire.

To resolve this:

* Introduce an error code type with a known size:
  `typedef s32 errcode_t`.

* Change all error code macros to constants of type `errcode_t`.
  Constants also play better with gdb - it would visualize the name of
  the constant instead of the numeric value.

* Change all functions that take error codes to take the new type
  `errcode_t` instead of `int`.

* Introduce towire / fromwire functions to send / receive the newly added
  type `errcode_t` and use it instead of `towire_int()`.

In addition:

* Remove the now unneeded `towire_int()`.

* Replace a hardcoded error code `-2` with a new constant
  `INVOICE_EXPIRED_DURING_WAIT` (903).

Changelog-Changed: The waitinvoice command would now return error code 903 to designate that the invoice expired during wait, instead of the previous -2
2020-01-31 06:02:47 +00:00
darosior fcbd11f0c5 plugins/libplugin: hook support
Changelog-Added: plugins: libplugin now supports writing plugins which register to hooks
2019-12-09 16:18:28 +01:00
darosior 3371f0cf78 plugins/libplugin: notifications support
Changelog-Added: plugins: libplugin now supports writing plugin which registers to notifications
2019-12-09 16:18:28 +01:00
Rusty Russell fe17acf07b TAGS: reformat to fix when PRINTF_FMT() used.
I was wondering why TAGS was missing some functions, and finally
tracked it down: PRINTF_FMT() confuses etags if it's at the start
of a function, and it ignores the rest of the file.

So we put PRINTF_FMT at the end, but that doesn't work for
*definitions*, only *declarations*.  So we remove it from definitions
and add gratuitous declarations in the few static places.1

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-11-01 17:27:20 -05:00
lisa neigut 2fe490294e libplugin: new helper method for passing a raw error
Makes it easier to stash an error and then return it after another
RPC call has been made.
2019-09-11 23:56:27 +00:00
lisa neigut f784863603 libplugin: add required import
libplugin seems to need the time include, so move it up from pay.
2019-09-11 23:56:27 +00:00
darosior 0cd3823c98 libplugin: pass configuration to plugin's 'init' callback
So that a plugin can, for example, know if it has been loaded on startup
2019-08-03 13:15:40 +02:00
darosior 017ee7c916 libplugin: Add 'getmanifest' 'dynamic' field 2019-08-03 13:15:40 +02:00
Rusty Russell c585f22711 libplugin: update API to use json_out.
We now hand around struct json_out members, rather than using formatted
strings, so plugins need to construct them properly.

There's no automatic conversion between ' and " any more, so those
are eliminated too.  pay still uses some manual construction of elements.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-06-12 02:00:15 +00:00
darosior 4640d18ef0 Plugins: allow to specify plugin option type in libplugin.c, then specify it to autoclean options 2019-06-03 00:06:12 +00:00
darosior 9d34121ec5 libplugin.c: Handle command categories then set them in pay and autoclean 2019-06-03 00:02:25 +00:00
Rusty Russell 44196e7d82 libplugin: logging support.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-05-22 00:18:29 +02:00
Rusty Russell 6a8cd9a016 libplugin: allow freeing in timer callback, clarify docs, allow nested timers.
1. Allow timers to be freed in their callback.
2. Clarify in header that we have to terminate our timer with timer_finished()
   eventually.
3. We don't currently have plugins with more than one outstanding timer, but
   it certainly would be possible, so fix in_timer to be a counter.

Suggested-by: @ZmnSCPxj
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-05-22 00:18:29 +02:00
Rusty Russell 9b61c19a20 libplugin: simple timer support.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-05-22 00:18:29 +02:00
Rusty Russell 688574b89c libplugin: support options.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-05-22 00:18:29 +02:00
Rusty Russell 26f60f83d5 libplugin: add deprecated_apis flag for plugins to access.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-23 05:45:25 +00:00
Rusty Russell de4043a32a plugin/libplugin: API for C plugins.
Doesn't do logging yet.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-01-17 13:02:24 +01:00