Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow replacing of an asset in the DB with another one #2898

Closed
LefterisJP opened this issue May 11, 2021 · 2 comments
Closed

Allow replacing of an asset in the DB with another one #2898

LefterisJP opened this issue May 11, 2021 · 2 comments
Assignees
Milestone

Comments

@LefterisJP
Copy link
Member

Abstract

At the moment for DB asset upgrades we have a problem. There is no proper way to distinguish between a non-ethereum asset added manually by the user and one we add ourselves.

That is since the identifier for those assets is not determnistic. (Link to issue to figure out a deterministic way for non ethereum assets).

The identifier is a uuid that is generated by the backend at asset addition.

rotki/rotkehlchen/api/rest.py

Lines 1315 to 1347 in 88d0299

def add_custom_asset(asset_type: AssetType, **kwargs: Any) -> Response:
globaldb = GlobalDBHandler()
# There is no good way to figure out if an asset already exists in the DB
# Best approximation we can do is this.
identifiers = globaldb.check_asset_exists(
asset_type=asset_type,
name=kwargs['name'], # no key error possible. Checked by marshmallow
symbol=kwargs['symbol'], # no key error possible. Checked by marshmallow
)
if identifiers is not None:
return api_response(
result=wrap_in_fail_result(
f'Failed to add {str(asset_type)} {kwargs["name"]} '
f'since it already exists. Existing ids: {",".join(identifiers)}'),
status_code=HTTPStatus.CONFLICT,
)
# asset id needs to be unique but no combination of asset data is guaranteed to be unique.
# And especially with the ability to edit assets we need an external uuid
asset_id = str(uuid4())
try:
GlobalDBHandler().add_asset(
asset_id=asset_id,
asset_type=asset_type,
data=kwargs,
)
except InputError as e:
return api_response(wrap_in_fail_result(str(e)), status_code=HTTPStatus.CONFLICT)
return api_response(
_wrap_in_ok_result({'identifier': asset_id}),
status_code=HTTPStatus.OK,
)

The reasoning for this is that there is no unique combination of fields that uniquely identify an asset such as the ethereum address for ethereum tokens. And ... if an asset's name changes so should the identifier. So there is a problem there.

The way we need to address the problem right now is to allow users who have already added a non ethereum asset and have a manual balance or trade for it to replace it with a different one if we introduce the asset in the canonical DB (since that would probably also be used in the exchanges mapping).

Task

  • Create an api endpoint that takes 2 assets and replaces one with the other in both the global and the user DB. One asset, would be the source asset, the one the user had added on their own, and the other the target asset, the one we introduced. The asset should be replaced both in the global DB AND in all occurences of the user's DB.
  • Create an api endpoint that does the same, but just takes an identifier from/to and not full assets. This would be to fix a broken user database. If for example you end up having a manual trade or an asset in the user DB with an unidentified asset, you could use this endpoint to tell it to change the identifier to something new.
  • Expose the above in the frontend.
@LefterisJP LefterisJP added this to the v1.17.0 milestone May 11, 2021
@LefterisJP
Copy link
Member Author

This requires: #2906

@LefterisJP
Copy link
Member Author

Actually this is not finished. Requires frontend + changelog which will be done by @kelsos, presumably here: #2943

@LefterisJP LefterisJP reopened this May 22, 2021
@kelsos kelsos closed this as completed in ffc6076 May 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant