core-lightning/tests/plugins/bookkeeper_custom_coins.py
niftynei 0e99f2e718 bkpr: add two custom notifications that we listen for
It might be nice to let the bookkeeper keep track of external accounts
as well as the internal onchain wallet? To this end, we add some new
custom notifications, which the bookkeeper will ingest and add to its
ledger.

Suggested-By: @chrisguida

Changelog-Added: PLUGINS: `bookkeeper` now listens for two custom events: `utxo_deposit` and `utxo_spend`. This allows for 3rd party plugins to send onchain coin events to the `bookkeeper`.  See the new plugins/bkpr/README.md for details on how these work!
2024-08-09 10:21:44 +09:30

52 lines
1.2 KiB
Python
Executable file

#!/usr/bin/env python3
from pyln.client import Plugin
plugin = Plugin()
UTXO_DEPOSIT_TAG = "utxo_deposit"
UTXO_SPEND_TAG = "utxo_spend"
@plugin.method("sendspend")
def emit_spend(plugin, acct, outpoint, txid, amount, **kwargs):
"""Emit a 'utxo_spend' movement
"""
utxo_spend = {
"account": acct,
"outpoint": outpoint,
"spending_txid": txid,
"amount_msat": amount,
"coin_type": "bcrt",
"timestamp": 1679955976,
"blockheight": 111,
}
plugin.notify(UTXO_SPEND_TAG, {UTXO_SPEND_TAG: utxo_spend})
@plugin.method("senddeposit")
def emit_deposit(plugin, acct, is_withdraw, outpoint, amount, **kwargs):
"""Emit a 'utxo_deposit' movement
"""
transfer_from = None
if is_withdraw:
acct = "external"
transfer_from = acct
utxo_deposit = {
"account": acct,
"transfer_from": transfer_from,
"outpoint": outpoint,
"amount_msat": amount,
"coin_type": "bcrt",
"timestamp": 1679955976,
"blockheight": 111,
}
plugin.notify(UTXO_DEPOSIT_TAG, {UTXO_DEPOSIT_TAG: utxo_deposit})
plugin.add_notification_topic(UTXO_DEPOSIT_TAG)
plugin.add_notification_topic(UTXO_SPEND_TAG)
plugin.run()