token upsert

This commit is contained in:
tim
2024-10-19 15:57:46 -04:00
parent 06a87d5a73
commit 5efc1fa82e

View File

@@ -21,7 +21,15 @@ class AddressMetadata (TypedDict):
def save_addrmeta(address: str, meta: AddressMetadata):
if meta['type'] == 'Token':
meta: OldTokenDict
db.session.add(Token.load(meta))
updated = Token.load(meta)
token = db.session.get(Token, (current_chain.get().id, address))
if token is None:
db.session.add(updated)
else:
token.name = updated.name
token.symbol = updated.symbol
token.decimals = updated.decimals
token.approved = updated.approved
elif meta['type'] == 'Pool':
meta: OldPoolDict
# Pools had to be updated for a repair, so we must first check if the pool existed already before inserting.