From c86c5353ec7f4c5e86adb183a6667ab15998c5c7 Mon Sep 17 00:00:00 2001 From: Codegnosis Date: Mon, 18 Sep 2023 12:41:07 +0100 Subject: [PATCH] go-ooo - ensure token symbols are not empty --- go-ooo/ooo_api/dex/db.go | 41 ++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/go-ooo/ooo_api/dex/db.go b/go-ooo/ooo_api/dex/db.go index d6385c3..d51abf7 100644 --- a/go-ooo/ooo_api/dex/db.go +++ b/go-ooo/ooo_api/dex/db.go @@ -1,24 +1,45 @@ package dex import ( + "go-ooo/logger" "go-ooo/ooo_api/dex/types" "go-ooo/utils" + "strings" ) +func pairIsClean(pair types.DexPair) bool { + // check if Token symbols are empty/only whitespace + if strings.TrimSpace(pair.Token0.Symbol) == "" || pair.Token0.Symbol == " " { + return false + } + if strings.TrimSpace(pair.Token1.Symbol) == "" || pair.Token1.Symbol == " " { + return false + } + + return true +} + func (dm *Manager) updatePairsInDb(pairs []types.DexPair, dex, chain string) { for _, pair := range pairs { - // pair.Token0.Id is the token's contract address - t0Db, _ := dm.db.FindOrInsertNewTokenContract(pair.Token0.Symbol, pair.Token0.Id, chain) - t1Db, _ := dm.db.FindOrInsertNewTokenContract(pair.Token1.Symbol, pair.Token1.Id, chain) + if pairIsClean(pair) { + // pair.Token0.Id is the token's contract address + t0Db, _ := dm.db.FindOrInsertNewTokenContract(pair.Token0.Symbol, pair.Token0.Id, chain) + t1Db, _ := dm.db.FindOrInsertNewTokenContract(pair.Token1.Symbol, pair.Token1.Id, chain) - t0DtDb, _ := dm.db.FindOrInsertNewDexToken(pair.Token0.Symbol, t0Db.ID, dex, chain) - t1DtDb, _ := dm.db.FindOrInsertNewDexToken(pair.Token1.Symbol, t1Db.ID, dex, chain) + t0DtDb, _ := dm.db.FindOrInsertNewDexToken(pair.Token0.Symbol, t0Db.ID, dex, chain) + t1DtDb, _ := dm.db.FindOrInsertNewDexToken(pair.Token1.Symbol, t1Db.ID, dex, chain) - // store liquidity - reserve, _ := utils.ParseBigFloat(pair.ReserveUSD) - reserveUsd, _ := reserve.Float64() + // store liquidity + reserve, _ := utils.ParseBigFloat(pair.ReserveUSD) + reserveUsd, _ := reserve.Float64() - // todo - update latest liquidity - _, _ = dm.db.FindOrInsertNewDexPair(pair.Token0.Symbol, pair.Token1.Symbol, pair.Id, dex, t0DtDb.ID, t1DtDb.ID, reserveUsd) + // todo - update latest liquidity + _, _ = dm.db.FindOrInsertNewDexPair(pair.Token0.Symbol, pair.Token1.Symbol, pair.Id, dex, t0DtDb.ID, t1DtDb.ID, reserveUsd) + } else { + logger.Debug("dex", "updatePairsInDb", "", "pair not clean", logger.Fields{ + "Token0.Symbol": pair.Token0.Symbol, + "Token1.Symbol": pair.Token1.Symbol, + }) + } } }