Test and document 'channel_opened' notification

This commit is contained in:
darosior 2019-07-25 15:57:53 +02:00 committed by Christian Decker
parent 736651ba43
commit 2683170da8
3 changed files with 56 additions and 1 deletions

View File

@ -200,6 +200,23 @@ corresponding payloads are listed below.
### Notification Types
#### `channel_opened`
A notification for topic `channel_opened` is sent if a peer successfully funded a channel
with us. It contains the peer id, the funding amount (in millisatoshis), the funding
transaction id, and a boolean indicating if the funding transaction has been included
into a block.
```
{
"channel_opened": {
"id": "03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370e2c366597a3f8f",
"funding_satoshis": "100000000msat",
"funding_txid": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
"funding_locked": false
}
}
```
#### `connect`
A notification for topic `connect` is sent every time a new connection
@ -237,7 +254,6 @@ A notification for topic `invoice_payment` is sent every time an invoie is paid.
}
```
#### `warning`
A notification for topic `warning` is sent every time a new `BROKEN`
@ -266,6 +282,7 @@ forms:
`jcon fd <error_fd_to_jsonrpc>:`, `plugin-manager`;
4. `log` is the context of the original log entry.
## Hooks
Hooks allow a plugin to define custom behavior for `lightningd`

View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
"""Plugin to be used to test miscellaneous notifications.
Only used for 'channel_opened' for now.
"""
from lightning import Plugin
plugin = Plugin()
@plugin.init()
def init(plugin, options, configuration):
plugin.log("misc_notifications initialized")
@plugin.subscribe("channel_opened")
def channel_opened(plugin, channel_opened):
plugin.log("A channel was opened to us by {}, with an amount"
" of {} and the following funding transaction id: {}"
.format(channel_opened["id"], channel_opened["amount"],
channel_opened["funding_txid"]))
plugin.run()

View File

@ -494,3 +494,16 @@ def test_invoice_payment_notification(node_factory):
l2.daemon.wait_for_log(r"Received invoice_payment event for label {},"
" preimage {}, and amount of {}msat"
.format(label, preimage, msats))
def test_channel_opened_notification(node_factory):
"""
Test the 'channel_opened' notification sent at channel funding success.
"""
opts = [{}, {"plugin": "tests/plugins/misc_notifications.py"}]
amount = 10**6
l1, l2 = node_factory.line_graph(2, fundchannel=True, fundamount=amount,
opts=opts)
l2.daemon.wait_for_log(r"A channel was opened to us by {}, "
"with an amount of {}*"
.format(l1.info["id"], amount))