mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 10:46:58 +01:00
test plugins/coin_moves: clean up/tidy coin moves plugin logic
removes unused in-memory stash of coin-moves; don't write the entire set of coinmoves out on every update.
This commit is contained in:
parent
ec991e3af7
commit
f169597a02
1 changed files with 3 additions and 16 deletions
|
@ -9,36 +9,23 @@ import os.path
|
|||
plugin = Plugin()
|
||||
|
||||
|
||||
@plugin.init()
|
||||
def init(configuration, options, plugin):
|
||||
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")
|
||||
def notify_coin_movement(plugin, coin_movement, **kwargs):
|
||||
plugin.log("coin movement: {}".format(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))
|
||||
with open('moves.json', 'a') as f:
|
||||
f.write(json.dumps(coin_movement) + ',')
|
||||
|
||||
|
||||
@plugin.method('listcoinmoves_plugin')
|
||||
def return_moves(plugin):
|
||||
result = []
|
||||
if os.path.exists('moves.json'):
|
||||
jd = {}
|
||||
with open('moves.json', 'r') as f:
|
||||
jd = f.read()
|
||||
result = json.loads(jd)
|
||||
result = json.loads('[' + jd[:-1] + ']')
|
||||
return {'coin_moves': result}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue