use float instead of decimal for now

This commit is contained in:
Lex Berezhny 2019-01-25 22:42:12 -05:00
parent cced217e43
commit aa1405887e
2 changed files with 11 additions and 6 deletions

View file

@ -4,7 +4,6 @@ import sys
import typing import typing
import logging import logging
import yaml import yaml
import decimal
from argparse import ArgumentParser from argparse import ArgumentParser
from contextlib import contextmanager from contextlib import contextmanager
from appdirs import user_data_dir, user_config_dir from appdirs import user_data_dir, user_config_dir
@ -117,12 +116,18 @@ class Integer(Setting[int]):
assert isinstance(val, int), \ assert isinstance(val, int), \
f"Setting '{self.name}' must be an integer." f"Setting '{self.name}' must be an integer."
def deserialize(self, value):
return int(value)
class Float(Setting[float]): class Float(Setting[float]):
def validate(self, val): def validate(self, val):
assert isinstance(val, float), \ assert isinstance(val, float), \
f"Setting '{self.name}' must be a decimal." f"Setting '{self.name}' must be a decimal."
def deserialize(self, value):
return float(value)
class Toggle(Setting[bool]): class Toggle(Setting[bool]):
def validate(self, val): def validate(self, val):
@ -169,8 +174,8 @@ class MaxKeyFee(Setting[dict]):
def _parse_list(l): def _parse_list(l):
assert len(l) == 2, 'Max key fee is made up of two values: "AMOUNT CURRENCY".' assert len(l) == 2, 'Max key fee is made up of two values: "AMOUNT CURRENCY".'
try: try:
amount = decimal.Decimal(l[0]) amount = float(l[0])
except decimal.InvalidOperation: except ValueError:
raise AssertionError('First value in max key fee is a decimal: "AMOUNT CURRENCY"') raise AssertionError('First value in max key fee is a decimal: "AMOUNT CURRENCY"')
currency = str(l[1]).upper() currency = str(l[1]).upper()
if currency not in CURRENCIES: if currency not in CURRENCIES:
@ -183,7 +188,7 @@ class MaxKeyFee(Setting[dict]):
if isinstance(value, dict): if isinstance(value, dict):
return { return {
'currency': value['currency'], 'currency': value['currency'],
'amount': decimal.Decimal(value['amount']), 'amount': float(value['amount']),
} }
if isinstance(value, str): if isinstance(value, str):
value = value.split() value = value.split()

View file

@ -780,7 +780,7 @@ class Daemon(metaclass=JSONRPCServerType):
--data_rate=<data_rate> : (float) 0.0001 --data_rate=<data_rate> : (float) 0.0001
--download_timeout=<download_timeout> : (int) 180 --download_timeout=<download_timeout> : (int) 180
--peer_port=<peer_port> : (int) 3333 --peer_port=<peer_port> : (int) 3333
--max_key_fee=<max_key_fee> : (dict) maximum key fee for downloads, --max_key_fee=<max_key_fee> : (str) maximum key fee for downloads,
in the format: '<amount> <currency>' in the format: '<amount> <currency>'
Supported currency symbols: LBC, USD, BTC Supported currency symbols: LBC, USD, BTC
--no_max_key_fee : (bool) Disable max key fee. --no_max_key_fee : (bool) Disable max key fee.
@ -801,7 +801,7 @@ class Daemon(metaclass=JSONRPCServerType):
(dict) Updated dictionary of daemon settings (dict) Updated dictionary of daemon settings
""" """
with self.conf.update_config() as c: with self.conf.update_config() as c:
for key, value in kwargs: for key, value in kwargs.items():
attr: Setting = getattr(type(c), key) attr: Setting = getattr(type(c), key)
setattr(c, key, attr.deserialize(value)) setattr(c, key, attr.deserialize(value))
return self.jsonrpc_settings_get() return self.jsonrpc_settings_get()