Exemplo n.º 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)
Exemplo n.º 2
0
    def _deserialize(
            self,
            value: str,
            attr: Optional[str],  # pylint: disable=unused-argument
            data: Optional[Mapping[str, Any]],  # pylint: disable=unused-argument
            **_kwargs: Any,
    ) -> HistoricalPriceOracle:
        try:
            historical_price_oracle = HistoricalPriceOracle.deserialize(value)
        except DeserializationError as e:
            raise ValidationError(f'Invalid historical price oracle: {value}') from e

        return historical_price_oracle
Exemplo n.º 3
0
    def get_historical_price_data(source: HistoricalPriceOracle) -> List[Dict[str, Any]]:
        """Return a list of assets and first/last ts

        Only used by the API so just returning it as List of dicts from here"""
        connection = GlobalDBHandler()._conn
        cursor = connection.cursor()
        query = cursor.execute(
            'SELECT from_asset, to_asset, MIN(timestamp), MAX(timestamp) FROM '
            'price_history WHERE source_type=? GROUP BY from_asset, to_asset',
            (source.serialize_for_db(),),
        )
        return [
            {'from_asset': entry[0],
             'to_asset': entry[1],
             'from_timestamp': entry[2],
             'to_timestamp': entry[3],
             } for entry in query]
Exemplo n.º 4
0
def test_historical_price_oracle_deserialize(value, result):
    assert HistoricalPriceOracle.deserialize(value) == result