From 193b17f0e4db5dd6e86d14c8e8391f24673f874a Mon Sep 17 00:00:00 2001 From: bitromortac Date: Thu, 24 Sep 2020 07:14:21 +0200 Subject: [PATCH] util: move json_normalize to util --- electrum/commands.py | 11 ++--------- electrum/util.py | 7 +++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/electrum/commands.py b/electrum/commands.py index 2d4a8d32e..ac1d030f1 100644 --- a/electrum/commands.py +++ b/electrum/commands.py @@ -39,8 +39,8 @@ from decimal import Decimal from typing import Optional, TYPE_CHECKING, Dict, List from .import util, ecc -from .util import bfh, bh2u, format_satoshis, json_decode, json_encode, is_hash256_str, is_hex_str, to_bytes, timestamp_to_datetime -from .util import standardize_path +from .util import (bfh, bh2u, format_satoshis, json_decode, json_normalize, + is_hash256_str, is_hex_str, to_bytes) from . import bitcoin from .bitcoin import is_address, hash_160, COIN from .bip32 import BIP32Node @@ -82,13 +82,6 @@ def satoshis(amount): def format_satoshis(x): return str(Decimal(x)/COIN) if x is not None else None -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): diff --git a/electrum/util.py b/electrum/util.py index cdce4e7b3..81a251586 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -379,6 +379,13 @@ def json_decode(x): except: return x +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)) + # taken from Django Source Code def constant_time_compare(val1, val2):