|
@ -2,12 +2,22 @@ |
|
|
|
|
|
|
|
|
from pyln.client import Plugin |
|
|
from pyln.client import Plugin |
|
|
|
|
|
|
|
|
|
|
|
import json |
|
|
|
|
|
import os.path |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugin = Plugin() |
|
|
plugin = Plugin() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@plugin.init() |
|
|
@plugin.init() |
|
|
def init(configuration, options, plugin): |
|
|
def init(configuration, options, plugin): |
|
|
plugin.coin_moves = [] |
|
|
if os.path.exists('moves.json'): |
|
|
|
|
|
jd = {} |
|
|
|
|
|
with open('moves.json', 'r') as f: |
|
|
|
|
|
jd = f.read() |
|
|
|
|
|
plugin.coin_moves = json.loads(jd) |
|
|
|
|
|
else: |
|
|
|
|
|
plugin.coin_moves = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@plugin.subscribe("coin_movement") |
|
|
@plugin.subscribe("coin_movement") |
|
@ -30,10 +40,21 @@ def notify_coin_movement(plugin, coin_movement, **kwargs): |
|
|
|
|
|
|
|
|
plugin.coin_moves.append(coin_movement) |
|
|
plugin.coin_moves.append(coin_movement) |
|
|
|
|
|
|
|
|
|
|
|
# we save to disk so that we don't get borked if the node restarts |
|
|
|
|
|
# assumes notification calls are synchronous (not thread safe) |
|
|
|
|
|
with open('moves.json', 'w') as f: |
|
|
|
|
|
f.write(json.dumps(plugin.coin_moves)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@plugin.method('listcoinmoves_plugin') |
|
|
@plugin.method('listcoinmoves_plugin') |
|
|
def return_moves(plugin): |
|
|
def return_moves(plugin): |
|
|
return {'coin_moves': plugin.coin_moves} |
|
|
result = [] |
|
|
|
|
|
if os.path.exists('moves.json'): |
|
|
|
|
|
jd = {} |
|
|
|
|
|
with open('moves.json', 'r') as f: |
|
|
|
|
|
jd = f.read() |
|
|
|
|
|
result = json.loads(jd) |
|
|
|
|
|
return {'coin_moves': result} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugin.run() |
|
|
plugin.run() |
|
|