Browse Source

util: move json_normalize to util

patch-4
bitromortac 4 years ago
parent
commit
193b17f0e4
No known key found for this signature in database GPG Key ID: 1965063FC13BEBE2
  1. 11
      electrum/commands.py
  2. 7
      electrum/util.py

11
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):

7
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):

Loading…
Cancel
Save