mirror of
https://github.com/Instadapp/trustwallet-assets.git
synced 2024-07-29 22:37:31 +00:00
Add tokenlist-extended validation (#17864)
This commit is contained in:
parent
d926569f68
commit
143d32cf5b
|
@ -17,7 +17,8 @@ var (
|
|||
regexChainInfoFile = regexp.MustCompile(`./blockchains/(\w+[\-]\w+|\w+)/info/info.json$`)
|
||||
regexChainLogoFile = regexp.MustCompile(`./blockchains/(\w+[\-]\w+|\w+)/info/logo.png$`)
|
||||
|
||||
regexTokenListFile = regexp.MustCompile(`./blockchains/(\w+[\-]\w+|\w+)/tokenlist.json$`)
|
||||
regexTokenListFile = regexp.MustCompile(`./blockchains/(\w+[\-]\w+|\w+)/tokenlist.json$`)
|
||||
regexTokenListExtendedFile = regexp.MustCompile(`./blockchains/(\w+[\-]\w+|\w+)/tokenlist-extended.json$`)
|
||||
|
||||
regexValidatorsAssetLogo = regexp.MustCompile(
|
||||
`./blockchains/(\w+[\-]\w+|\w+)/validators/assets/(\w+[\-]\w+|\w+)/logo.png$`)
|
||||
|
@ -50,7 +51,8 @@ var regexes = map[string]*regexp.Regexp{
|
|||
TypeChainInfoFile: regexChainInfoFile,
|
||||
TypeChainLogoFile: regexChainLogoFile,
|
||||
|
||||
TypeTokenListFile: regexTokenListFile,
|
||||
TypeTokenListFile: regexTokenListFile,
|
||||
TypeTokenListExtendedFile: regexTokenListExtendedFile,
|
||||
|
||||
TypeValidatorsListFile: regexValidatorsList,
|
||||
TypeValidatorsLogoFile: regexValidatorsAssetLogo,
|
||||
|
|
|
@ -12,14 +12,15 @@ const (
|
|||
TypeValidatorsAssetFolder = "validators_asset_folder"
|
||||
TypeValidatorsAssetsFolder = "validators_assets_folder"
|
||||
|
||||
TypeAssetInfoFile = "asset_info_file"
|
||||
TypeAssetLogoFile = "asset_logo_file"
|
||||
TypeChainInfoFile = "chain_info_file"
|
||||
TypeChainLogoFile = "chain_logo_file"
|
||||
TypeTokenListFile = "chain_tokenlist_file"
|
||||
TypeDappsLogoFile = "dapps_logo_file"
|
||||
TypeValidatorsListFile = "validators_list_file"
|
||||
TypeValidatorsLogoFile = "validators_logo_file"
|
||||
TypeAssetInfoFile = "asset_info_file"
|
||||
TypeAssetLogoFile = "asset_logo_file"
|
||||
TypeChainInfoFile = "chain_info_file"
|
||||
TypeChainLogoFile = "chain_logo_file"
|
||||
TypeTokenListFile = "chain_tokenlist_file"
|
||||
TypeTokenListExtendedFile = "chain_tokenlist_extended_file"
|
||||
TypeDappsLogoFile = "dapps_logo_file"
|
||||
TypeValidatorsListFile = "validators_list_file"
|
||||
TypeValidatorsLogoFile = "validators_logo_file"
|
||||
|
||||
TypeUnknown = "unknown_file"
|
||||
)
|
||||
|
|
|
@ -65,6 +65,11 @@ func (s *Service) GetValidator(f *file.AssetFile) []Validator {
|
|||
jsonValidator,
|
||||
{Name: "Tokenlist file is valid", Run: s.ValidateTokenListFile},
|
||||
}
|
||||
case file.TypeTokenListExtendedFile:
|
||||
return []Validator{
|
||||
jsonValidator,
|
||||
{Name: "Tokenlist Extended file is valid", Run: s.ValidateTokenListExtendedFile},
|
||||
}
|
||||
case file.TypeValidatorsListFile:
|
||||
return []Validator{
|
||||
jsonValidator,
|
||||
|
|
|
@ -262,34 +262,47 @@ func isStackingChain(c coin.Coin) bool {
|
|||
}
|
||||
|
||||
func (s *Service) ValidateTokenListFile(f *file.AssetFile) error {
|
||||
var tokenList tokenlist.Model
|
||||
err := filelib.ReadJSONFile(f.Path(), &tokenList)
|
||||
tokenListPath := f.Path()
|
||||
tokenListExtendedPath := path.GetTokenListPath(f.Chain().Handle, path.TokenlistExtended)
|
||||
|
||||
return validateTokenList(tokenListPath, tokenListExtendedPath, f.Chain())
|
||||
}
|
||||
|
||||
func (s *Service) ValidateTokenListExtendedFile(f *file.AssetFile) error {
|
||||
tokenListPathExtended := f.Path()
|
||||
tokenListPath := path.GetTokenListPath(f.Chain().Handle, path.TokenlistDefault)
|
||||
|
||||
return validateTokenList(tokenListPathExtended, tokenListPath, f.Chain())
|
||||
}
|
||||
|
||||
func validateTokenList(path1, path2 string, chain1 coin.Coin) error {
|
||||
var tokenList1 tokenlist.Model
|
||||
err := filelib.ReadJSONFile(path1, &tokenList1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tokenListExtendedPath := path.GetTokenListPath(f.Chain().Handle, path.TokenlistExtended)
|
||||
if filelib.Exists(tokenListExtendedPath) {
|
||||
var tokenListExtended tokenlist.Model
|
||||
err = filelib.ReadJSONFile(tokenListExtendedPath, &tokenListExtended)
|
||||
if filelib.Exists(path2) {
|
||||
var tokenList2 tokenlist.Model
|
||||
err = filelib.ReadJSONFile(path2, &tokenList2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tokensMap := make(map[string]bool)
|
||||
for _, token := range tokenListExtended.Tokens {
|
||||
for _, token := range tokenList2.Tokens {
|
||||
tokensMap[token.Asset] = true
|
||||
}
|
||||
|
||||
for _, token := range tokenList.Tokens {
|
||||
for _, token := range tokenList1.Tokens {
|
||||
if _, exists := tokensMap[token.Asset]; exists {
|
||||
return fmt.Errorf("duplicate asset: %s from %s, already exist in %s",
|
||||
token.Asset, f.Path(), tokenListExtendedPath)
|
||||
token.Asset, path1, path2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err = tokenlist.ValidateTokenList(tokenList, f.Chain(), f.Path())
|
||||
err = tokenlist.ValidateTokenList(tokenList1, chain1, path1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user