From f169597a0235c03ffda53486bd16c602cace677f Mon Sep 17 00:00:00 2001 From: niftynei Date: Thu, 9 Dec 2021 11:46:26 -0600 Subject: [PATCH] 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. --- tests/plugins/coin_movements.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/tests/plugins/coin_movements.py b/tests/plugins/coin_movements.py index ce617a770..2c0f3983d 100755 --- a/tests/plugins/coin_movements.py +++ b/tests/plugins/coin_movements.py @@ -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}