mirror of
https://github.com/Instadapp/trustwallet-assets.git
synced 2024-07-29 22:37:31 +00:00
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:
parent
f12f8d8e69
commit
8c949880b1
|
@ -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/",
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user