Fix BNB name, add coin checks to tokenlist validation and tokenlist pairs check (#17195)

* Fix BNB name, add coin checks to tokenlist validation

* Add tokenlist pairs check
This commit is contained in:
Daniel 2022-01-10 15:32:23 +03:00 committed by GitHub
parent f12f8d8e69
commit 8c949880b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 6 deletions

View File

@ -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/",

View File

@ -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 {