Exemple #1
0
def test_purge_ethereum_transaction_data(rotkehlchen_api_server):
    rotki = rotkehlchen_api_server.rest_api.rotkehlchen
    addr1 = make_ethereum_address()
    rotki.data.db.add_blockchain_accounts(
        blockchain=SupportedBlockchain.ETHEREUM,
        account_data=[
            BlockchainAccountData(address=addr1),
        ],
    )
    db = DBEthTx(rotki.data.db)
    db.add_ethereum_transactions(
        [
            EthereumTransaction(
                tx_hash=make_evm_tx_hash(bytes()),
                timestamp=1,
                block_number=1,
                from_address=addr1,
                to_address=make_ethereum_address(),
                value=FVal(1),
                gas=FVal(1),
                gas_price=FVal(1),
                gas_used=FVal(1),
                input_data=bytes(),
                nonce=1,
            )
        ],
        relevant_address=addr1,
    )
    filter_ = ETHTransactionsFilterQuery.make()

    result, filter_count = db.get_ethereum_transactions_and_limit_info(
        filter_, True)
    assert len(result) == 1
    assert filter_count == 1
    response = requests.delete(
        api_url_for(
            rotkehlchen_api_server,
            'ethereumtransactionsresource',
        ), )
    assert_simple_ok_response(response)
    result, filter_count = db.get_ethereum_transactions_and_limit_info(
        filter_, True)
    assert len(result) == 0
    assert filter_count == 0
    def query(
        self,
        filter_query: ETHTransactionsFilterQuery,
        has_premium: bool = False,
        only_cache: bool = False,
    ) -> Tuple[List[EthereumTransaction], int]:
        """Queries for all transactions of an ethereum address or of all addresses.

        Returns a list of all transactions filtered and sorted according to the parameters.

        May raise:
        - RemoteError if etherscan is used and there is a problem with reaching it or
        with parsing the response.
        - pysqlcipher3.dbapi2.OperationalError if the SQL query fails due to
        invalid filtering arguments.
        """
        query_addresses = filter_query.addresses

        if query_addresses is not None:
            accounts = query_addresses
        else:
            accounts = self.database.get_blockchain_accounts().eth

        if only_cache is False:
            f_from_ts = filter_query.from_ts
            f_to_ts = filter_query.to_ts
            from_ts = Timestamp(0) if f_from_ts is None else f_from_ts
            to_ts = ts_now() if f_to_ts is None else f_to_ts
            for address in accounts:
                self.single_address_query_transactions(
                    address=address,
                    start_ts=from_ts,
                    end_ts=to_ts,
                )

        dbethtx = DBEthTx(self.database)
        return dbethtx.get_ethereum_transactions_and_limit_info(
            filter_=filter_query,
            has_premium=has_premium,
        )