Refactor code (#17251)

This commit is contained in:
Daniel 2022-01-12 17:34:32 +03:00 committed by GitHub
parent 35ad6cb9fa
commit cec78fe487
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 61 deletions

View File

@ -1,25 +1,25 @@
package file
const (
TypeAssetInfoFile = "asset_info"
TypeAssetLogoFile = "asset_logo"
TypeChainInfoFile = "chain_info"
TypeChainLogoFile = "chain_logo"
TypeTokenListFile = "chain_token_list"
TypeValidatorsListFile = "validators_list"
TypeValidatorsLogoFile = "validators_logo"
TypeDappsLogoFile = "dapps_logo"
TypeAssetFolder = "asset"
TypeAssetsFolder = "assets"
TypeChainFolder = "chain"
TypeChainsFolder = "chains"
TypeDappsFolder = "dapps"
TypeRootFolder = "root"
TypeAssetFolder = "asset_folder"
TypeAssetsFolder = "assets_folder"
TypeChainFolder = "chain_folder"
TypeChainInfoFolder = "chain_info_folder"
TypeValidatorsFolder = "validators"
TypeValidatorsAssetFolder = "validators_asset"
TypeValidatorsAssetsFolder = "validators_assets"
TypeChainsFolder = "chains_folder"
TypeDappsFolder = "dapps_folder"
TypeRootFolder = "root_folder"
TypeValidatorsFolder = "validators_folder"
TypeValidatorsAssetFolder = "validators_asset_folder"
TypeValidatorsAssetsFolder = "validators_assets_folder"
TypeUnknown = "unknown"
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"
TypeUnknown = "unknown_file"
)

View File

@ -16,52 +16,53 @@ func (s *Service) GetValidator(f *file.AssetFile) []Validator {
jsonValidator := Validator{Name: "JSON validation", Run: s.ValidateJSON}
switch f.Type() {
case file.TypeRootFolder:
case file.TypeAssetFolder:
return []Validator{
{Name: "Root folder contains only allowed files", Run: s.ValidateRootFolder},
{Name: "Each asset folder has valid asset address and contains only allowed files", Run: s.ValidateAssetFolder},
}
case file.TypeChainFolder:
return []Validator{
{Name: "Chain folders are lowercase and contains only allowed files", Run: s.ValidateChainFolder},
}
case file.TypeChainLogoFile, file.TypeAssetLogoFile, file.TypeValidatorsLogoFile, file.TypeDappsLogoFile:
return []Validator{
{Name: "Logos (size, dimension)", Run: s.ValidateImage},
}
case file.TypeAssetFolder:
return []Validator{
{Name: "Each asset folder has valid asset address and contains logo/info", Run: s.ValidateAssetFolder},
}
case file.TypeDappsFolder:
return []Validator{
{Name: "Dapps folder (allowed only png files, lowercase)", Run: s.ValidateDappsFolder},
}
case file.TypeAssetInfoFile:
return []Validator{
jsonValidator,
{Name: "Asset info", Run: s.ValidateAssetInfoFile},
}
case file.TypeChainInfoFile:
return []Validator{
{Name: "Chain Info", Run: s.ValidateChainInfoFile},
}
case file.TypeValidatorsListFile:
return []Validator{
jsonValidator,
{Name: "Validators list file", Run: s.ValidateValidatorsListFile},
}
case file.TypeTokenListFile:
return []Validator{
jsonValidator,
{Name: "Token list", Run: s.ValidateTokenListFile},
}
case file.TypeChainInfoFolder:
return []Validator{
{Name: "Chain Info Folder (has files)", Run: s.ValidateInfoFolder},
}
case file.TypeDappsFolder:
return []Validator{
{Name: "Dapps folder contains only allowed png files in lowercase", Run: s.ValidateDappsFolder},
}
case file.TypeRootFolder:
return []Validator{
{Name: "Root folder contains only allowed files", Run: s.ValidateRootFolder},
}
case file.TypeValidatorsAssetFolder:
return []Validator{
{Name: "Validators asset folder (has logo, valid asset address)", Run: s.ValidateValidatorsAssetFolder},
{Name: "Validators asset folder has logo and valid asset address)", Run: s.ValidateValidatorsAssetFolder},
}
case file.TypeAssetLogoFile, file.TypeChainLogoFile, file.TypeDappsLogoFile, file.TypeValidatorsLogoFile:
return []Validator{
{Name: "Logos size and dimension are valid", Run: s.ValidateImage},
}
case file.TypeAssetInfoFile:
return []Validator{
jsonValidator,
{Name: "Asset info file is valid", Run: s.ValidateAssetInfoFile},
}
case file.TypeChainInfoFile:
return []Validator{
{Name: "Chain info file is valid", Run: s.ValidateChainInfoFile},
}
case file.TypeTokenListFile:
return []Validator{
jsonValidator,
{Name: "Tokenlist file is valid", Run: s.ValidateTokenListFile},
}
case file.TypeValidatorsListFile:
return []Validator{
jsonValidator,
{Name: "Validators list file is valid", Run: s.ValidateValidatorsListFile},
}
}
@ -75,28 +76,28 @@ func (s *Service) GetFixers(f *file.AssetFile) []Fixer {
}
switch f.Type() {
case file.TypeChainInfoFile:
case file.TypeAssetFolder:
return []Fixer{
jsonFixer,
{Name: "Fixing chain info.json files", Run: s.FixChainInfoJSON},
{Name: "Renaming EVM's asset folder to valid address checksum", Run: s.FixETHAddressChecksum},
}
case file.TypeAssetInfoFile:
return []Fixer{
jsonFixer,
{Name: "Fixing asset info.json files", Run: s.FixAssetInfo},
}
case file.TypeValidatorsListFile:
case file.TypeChainInfoFile:
return []Fixer{
jsonFixer,
}
case file.TypeAssetFolder:
return []Fixer{
{Name: "Renaming EVM's asset folder to valid address checksum", Run: s.FixETHAddressChecksum},
{Name: "Fixing chain info.json files", Run: s.FixChainInfoJSON},
}
case file.TypeChainLogoFile, file.TypeAssetLogoFile, file.TypeValidatorsLogoFile, file.TypeDappsLogoFile:
return []Fixer{
{Name: "Resizing and compressing logo images", Run: s.FixLogo},
}
case file.TypeValidatorsListFile:
return []Fixer{
jsonFixer,
}
}
return nil