1
0

interface: check server response for some methods

some basic sanity checks

Previously if the server sent back a malformed response, it could partially corrupt a wallet file.
(as sometimes the response would get persisted, and issues would only arise later when the values were used)
This commit is contained in:
SomberNight
2020-07-02 15:31:35 +02:00
parent 3393ff757e
commit d19ff43266
4 changed files with 200 additions and 43 deletions

View File

@@ -582,6 +582,30 @@ def is_non_negative_integer(val) -> bool:
return False
def is_integer(val) -> bool:
try:
int(val)
except:
return False
else:
return True
def is_real_number(val, *, as_str: bool = False) -> bool:
if as_str: # only accept str
if not isinstance(val, str):
return False
else: # only accept int/float/etc.
if isinstance(val, str):
return False
try:
Decimal(val)
except:
return False
else:
return True
def chunks(items, size: int):
"""Break up items, an iterable, into chunks of length size."""
if size < 1: