diff --git a/blockchains/binance/info/info.json b/blockchains/binance/info/info.json index b4128f6fb..2b1c3ad1a 100644 --- a/blockchains/binance/info/info.json +++ b/blockchains/binance/info/info.json @@ -1,5 +1,5 @@ { - "name": "BNB coin", + "name": "Binance Chain Native Token", "website": "https://binance.org/", "description": "Fast and secure decentralized digital asset exchange. The new crypto currency trading standard is here.", "explorer": "https://explorer.binance.org/", diff --git a/internal/processor/validators.go b/internal/processor/validators.go index b36ec06bd..d80592342 100644 --- a/internal/processor/validators.go +++ b/internal/processor/validators.go @@ -342,7 +342,6 @@ func isStackingChain(c coin.Coin) bool { return false } -// nolint:funlen func (s *Service) ValidateTokenListFile(f *file.AssetFile) error { file, err := os.Open(f.Path()) if err != nil { @@ -361,14 +360,30 @@ func (s *Service) ValidateTokenListFile(f *file.AssetFile) error { return err } + err = checkTokenListAssets(model, f) + if err != nil { + return err + } + + err = checkTokenListPairs(model) + if err != nil { + return err + } + + return nil +} + +func checkTokenListAssets(model TokenList, f *file.AssetFile) error { compErr := validation.NewErrComposite() for _, token := range model.Tokens { - if token.Type == types.Coin { - continue - } + var assetPath string - assetPath := path.GetAssetInfoPath(f.Chain().Handle, token.Address) + if token.Type == types.Coin { + assetPath = path.GetChainInfoPath(f.Chain().Handle) + } else { + assetPath = path.GetAssetInfoPath(f.Chain().Handle, token.Address) + } infoFile, err := os.Open(assetPath) if err != nil { @@ -420,6 +435,34 @@ func (s *Service) ValidateTokenListFile(f *file.AssetFile) error { return nil } +func checkTokenListPairs(model TokenList) error { + compErr := validation.NewErrComposite() + + tokensMap := make(map[string]struct{}) + for _, t := range model.Tokens { + tokensMap[t.Asset] = struct{}{} + } + + pairs := make(map[string]string) + for _, t := range model.Tokens { + for _, pair := range t.Pairs { + pairs[pair.Base] = t.Address + } + } + + for pairToken, token := range pairs { + if _, exists := tokensMap[pairToken]; !exists { + compErr.Append(fmt.Errorf("token '%s' contains non-existing pair token '%s'", token, pairToken)) + } + } + + if compErr.Len() > 0 { + return compErr + } + + return nil +} + func (s *Service) ValidateInfoFolder(f *file.AssetFile) error { file, err := os.Open(f.Path()) if err != nil {