tcli: history commands: only json-encode once - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 3835157f419d0f0139ed05a589c6a10b3f1a7e99 DIR parent dbceed26474ba4a1ef7da22cd0fa0e5fde8e6a3c HTML Author: SomberNight <somber.night@protonmail.com> Date: Tue, 4 Feb 2020 17:56:52 +0100 cli: history commands: only json-encode once closes #5868 closes #5931 Diffstat: M electrum/commands.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- DIR diff --git a/electrum/commands.py b/electrum/commands.py t@@ -73,6 +73,14 @@ def satoshis(amount): return int(COIN*Decimal(amount)) if amount not in ['!', None] else amount +def json_normalize(x): + # note: The return value of commands, when going through the JSON-RPC interface, + # is json-encoded. The encoder used there cannot handle some types, e.g. electrum.util.Satoshis. + # note: We should not simply do "json_encode(x)" here, as then later x would get doubly json-encoded. + # see #5868 + return json_decode(json_encode(x)) + + class Command: def __init__(self, func, s): self.name = func.__name__ t@@ -638,7 +646,7 @@ class Commands: from .exchange_rate import FxThread fx = FxThread(self.config, None) kwargs['fx'] = fx - return json_encode(wallet.get_detailed_history(**kwargs)) + return json_normalize(wallet.get_detailed_history(**kwargs)) @command('w') async def init_lightning(self, wallet: Abstract_Wallet = None): t@@ -655,7 +663,7 @@ class Commands: async def lightning_history(self, show_fiat=False, wallet: Abstract_Wallet = None): """ lightning history """ lightning_history = wallet.lnworker.get_history() if wallet.lnworker else [] - return json_encode(lightning_history) + return json_normalize(lightning_history) @command('w') async def setlabel(self, key, label, wallet: Abstract_Wallet = None):