token upsert
This commit is contained in:
@@ -21,7 +21,15 @@ class AddressMetadata (TypedDict):
|
|||||||
def save_addrmeta(address: str, meta: AddressMetadata):
|
def save_addrmeta(address: str, meta: AddressMetadata):
|
||||||
if meta['type'] == 'Token':
|
if meta['type'] == 'Token':
|
||||||
meta: OldTokenDict
|
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':
|
elif meta['type'] == 'Pool':
|
||||||
meta: OldPoolDict
|
meta: OldPoolDict
|
||||||
# Pools had to be updated for a repair, so we must first check if the pool existed already before inserting.
|
# Pools had to be updated for a repair, so we must first check if the pool existed already before inserting.
|
||||||
|
|||||||
Reference in New Issue
Block a user