2020-03-19 00:46:17 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
from pyln.client import Plugin
|
|
|
|
|
2020-04-02 05:02:08 +02:00
|
|
|
import json
|
|
|
|
import os.path
|
|
|
|
|
|
|
|
|
2020-03-19 00:46:17 +01:00
|
|
|
plugin = Plugin()
|
|
|
|
|
|
|
|
|
|
|
|
@plugin.subscribe("coin_movement")
|
|
|
|
def notify_coin_movement(plugin, coin_movement, **kwargs):
|
2021-12-01 16:32:55 +01:00
|
|
|
plugin.log("coin movement: {}".format(coin_movement))
|
2020-03-19 00:46:17 +01:00
|
|
|
|
2020-04-02 05:02:08 +02:00
|
|
|
# we save to disk so that we don't get borked if the node restarts
|
|
|
|
# assumes notification calls are synchronous (not thread safe)
|
2021-12-09 18:46:26 +01:00
|
|
|
with open('moves.json', 'a') as f:
|
|
|
|
f.write(json.dumps(coin_movement) + ',')
|
2020-04-02 05:02:08 +02:00
|
|
|
|
2020-03-19 00:46:17 +01:00
|
|
|
|
|
|
|
@plugin.method('listcoinmoves_plugin')
|
|
|
|
def return_moves(plugin):
|
2020-04-02 05:02:08 +02:00
|
|
|
result = []
|
|
|
|
if os.path.exists('moves.json'):
|
|
|
|
with open('moves.json', 'r') as f:
|
|
|
|
jd = f.read()
|
2021-12-09 18:46:26 +01:00
|
|
|
result = json.loads('[' + jd[:-1] + ']')
|
2020-04-02 05:02:08 +02:00
|
|
|
return {'coin_moves': result}
|
2020-03-19 00:46:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
plugin.run()
|