コード例 #1
0
def db_settings_from_dict(
    settings_dict: Dict[str, Any],
    msg_aggregator: MessagesAggregator,
) -> DBSettings:
    specified_args: Dict[str, Any] = {}
    for key, value in settings_dict.items():
        if key in BOOLEAN_KEYS:
            specified_args[key] = read_boolean(value)
        elif key in INTEGER_KEYS:
            specified_args[key] = int(value)
        elif key in STRING_KEYS:
            specified_args[key] = str(value)
        elif key == 'taxfree_after_period':
            # taxfree_after_period can also be None, to signify disabled setting
            if value is None:
                specified_args[key] = value
            else:
                int_value = int(value)
                if int_value <= 0:
                    value = None
                    msg_aggregator.add_warning(
                        f'A negative or zero value ({int_value}) for taxfree_after_period '
                        f'ended up in the DB. Setting it to None. Please open an issue in '
                        f'Github: https://github.com/rotki/rotki/issues/new/choose',
                    )

                else:
                    value = int_value

                specified_args[key] = value
        elif key == 'main_currency':
            specified_args[key] = Asset(str(value))
        elif key in TIMESTAMP_KEYS:
            specified_args[key] = Timestamp(int(value))
        elif key == 'kraken_account_type':
            specified_args[key] = KrakenAccountType.deserialize(value)
        elif key == 'active_modules':
            specified_args[key] = json.loads(value)
        elif key == 'current_price_oracles':
            oracles = json.loads(value)
            specified_args[key] = [
                CurrentPriceOracle.deserialize(oracle) for oracle in oracles
            ]
        elif key == 'historical_price_oracles':
            oracles = json.loads(value)
            specified_args[key] = [
                HistoricalPriceOracle.deserialize(oracle) for oracle in oracles
            ]
        elif key == 'taxable_ledger_actions':
            values = json.loads(value)
            specified_args[key] = [
                LedgerActionType.deserialize(x) for x in values
            ]
        else:
            msg_aggregator.add_warning(
                f'Unknown DB setting {key} given. Ignoring it. Should not '
                f'happen so please open an issue in Github.', )

    return DBSettings(**specified_args)
コード例 #2
0
ファイル: encoding.py プロジェクト: yairash/rotki
    def _deserialize(
            self,
            value: str,
            attr: Optional[str],  # pylint: disable=unused-argument
            data: Optional[Mapping[str, Any]],  # pylint: disable=unused-argument
            **_kwargs: Any,
    ) -> KrakenAccountType:
        try:
            acc_type = KrakenAccountType.deserialize(value)
        except DeserializationError:
            raise ValidationError(f'{value} is not a valid kraken account type')

        return acc_type
コード例 #3
0
ファイル: settings.py プロジェクト: tiemonl/rotki
def db_settings_from_dict(
    settings_dict: Dict[str, Any],
    msg_aggregator: MessagesAggregator,
) -> DBSettings:
    specified_args: Dict[str, Any] = {}
    for key, value in settings_dict.items():
        if key == 'have_premium':
            specified_args[key] = read_boolean(value)
        elif key == 'version':
            specified_args[key] = int(value)
        elif key == 'historical_data_start':
            specified_args[key] = str(value)
        elif key == 'eth_rpc_endpoint':
            specified_args[key] = str(value)
        elif key == 'ui_floating_precision':
            specified_args[key] = int(value)
        elif key == 'include_crypto2crypto':
            specified_args[key] = read_boolean(value)
        elif key == 'taxfree_after_period':
            # taxfree_after_period can also be None, to signify disabled setting
            if value is None:
                specified_args[key] = value
            else:
                int_value = int(value)
                if int_value <= 0:
                    value = None
                    msg_aggregator.add_warning(
                        f'A negative or zero value ({int_value}) for taxfree_after_period '
                        f'ended up in the DB. Setting it to None. Please open an issue in '
                        f'Github: https://github.com/rotki/rotki/issues/new/choose',
                    )

                else:
                    value = int_value

                specified_args[key] = value
        elif key == 'balance_save_frequency':
            specified_args[key] = int(value)
        elif key == 'main_currency':
            specified_args[key] = Asset(str(value))
        elif key == 'anonymized_logs':
            specified_args[key] = read_boolean(value)
        elif key == 'include_gas_costs':
            specified_args[key] = read_boolean(value)
        elif key == 'date_display_format':
            specified_args[key] = str(value)
        elif key == 'thousand_separator':
            specified_args[key] = str(value)
        elif key == 'decimal_separator':
            specified_args[key] = str(value)
        elif key == 'currency_location':
            specified_args[key] = str(value)
        elif key == 'premium_should_sync':
            specified_args[key] = read_boolean(value)
        elif key == 'last_write_ts':
            specified_args[key] = Timestamp(int(value))
        elif key == 'last_data_upload_ts':
            specified_args[key] = Timestamp(int(value))
        elif key == 'last_balance_save':
            specified_args[key] = Timestamp(int(value))
        elif key == 'submit_usage_analytics':
            specified_args[key] = read_boolean(value)
        elif key == 'kraken_account_type':
            specified_args[key] = KrakenAccountType.deserialize(value)
        elif key == 'active_modules':
            specified_args[key] = json.loads(value)
        elif key == 'frontend_settings':
            specified_args[key] = str(value)
        else:
            msg_aggregator.add_warning(
                f'Unknown DB setting {key} given. Ignoring it. Should not '
                f'happen so please open an issue in Github.', )

    return DBSettings(**specified_args)