From 4ccb6c3009e4e8d5b6d7485b3a67711a525d7d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CDongLieu=E2=80=9D?= Date: Wed, 13 Nov 2024 10:38:05 +0700 Subject: [PATCH] fix duplicate symbol oracle --- x/oracle/keeper/band_oracle.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/x/oracle/keeper/band_oracle.go b/x/oracle/keeper/band_oracle.go index 17e3783..379f468 100644 --- a/x/oracle/keeper/band_oracle.go +++ b/x/oracle/keeper/band_oracle.go @@ -3,6 +3,7 @@ package keeper import ( "context" "fmt" + "slices" "strconv" "time" @@ -269,11 +270,13 @@ func (k Keeper) AddNewSymbolToBandOracleRequest(ctx context.Context, symbol stri // check if new symbol's oracle script id is existing for _, req := range allBandOracleRequests { if req.OracleScriptId == oracleScriptId { - req.Symbols = append(req.Symbols, symbol) - err := k.SetBandOracleRequest(ctx, *req) - if err != nil { - return errorsmod.Wrapf(types.ErrSetBandOracleRequest, "can not set symbol %s with oracle script id %v", symbol, oracleScriptId) + if !slices.Contains(req.Symbols, symbol) { + req.Symbols = append(req.Symbols, symbol) + if err := k.SetBandOracleRequest(ctx, *req); err != nil { + return errorsmod.Wrapf(types.ErrSetBandOracleRequest, "can not set symbol %s with oracle script id %v", symbol, oracleScriptId) + } } + return nil } }