Skip to content

Commit

Permalink
Refactor code (trustwallet#17251)
Browse files Browse the repository at this point in the history
  • Loading branch information
unanoc authored Jan 12, 2022
1 parent 35ad6cb commit cec78fe
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 49 deletions.
38 changes: 19 additions & 19 deletions internal/file/types.go
Original file line number Diff line number Diff line change
@@ -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"

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"
TypeUnknown = "unknown_file"
)
61 changes: 31 additions & 30 deletions internal/processor/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
case file.TypeChainInfoFolder:
return []Validator{
{Name: "Logos (size, dimension)", Run: s.ValidateImage},
{Name: "Chain Info Folder (has files)", Run: s.ValidateInfoFolder},
}
case file.TypeAssetFolder:
case file.TypeDappsFolder:
return []Validator{
{Name: "Each asset folder has valid asset address and contains logo/info", Run: s.ValidateAssetFolder},
{Name: "Dapps folder contains only allowed png files in lowercase", Run: s.ValidateDappsFolder},
}
case file.TypeDappsFolder:
case file.TypeRootFolder:
return []Validator{
{Name: "Dapps folder (allowed only png files, lowercase)", Run: s.ValidateDappsFolder},
{Name: "Root folder contains only allowed files", Run: s.ValidateRootFolder},
}
case file.TypeAssetInfoFile:
case file.TypeValidatorsAssetFolder:
return []Validator{
jsonValidator,
{Name: "Asset info", Run: s.ValidateAssetInfoFile},
{Name: "Validators asset folder has logo and valid asset address)", Run: s.ValidateValidatorsAssetFolder},
}
case file.TypeChainInfoFile:

case file.TypeAssetLogoFile, file.TypeChainLogoFile, file.TypeDappsLogoFile, file.TypeValidatorsLogoFile:
return []Validator{
{Name: "Chain Info", Run: s.ValidateChainInfoFile},
{Name: "Logos size and dimension are valid", Run: s.ValidateImage},
}
case file.TypeValidatorsListFile:
case file.TypeAssetInfoFile:
return []Validator{
jsonValidator,
{Name: "Validators list file", Run: s.ValidateValidatorsListFile},
{Name: "Asset info file is valid", Run: s.ValidateAssetInfoFile},
}
case file.TypeTokenListFile:
case file.TypeChainInfoFile:
return []Validator{
jsonValidator,
{Name: "Token list", Run: s.ValidateTokenListFile},
{Name: "Chain info file is valid", Run: s.ValidateChainInfoFile},
}
case file.TypeChainInfoFolder:
case file.TypeTokenListFile:
return []Validator{
{Name: "Chain Info Folder (has files)", Run: s.ValidateInfoFolder},
jsonValidator,
{Name: "Tokenlist file is valid", Run: s.ValidateTokenListFile},
}
case file.TypeValidatorsAssetFolder:
case file.TypeValidatorsListFile:
return []Validator{
{Name: "Validators asset folder (has logo, valid asset address)", Run: s.ValidateValidatorsAssetFolder},
jsonValidator,
{Name: "Validators list file is valid", Run: s.ValidateValidatorsListFile},
}
}

Expand All @@ -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
Expand Down

0 comments on commit cec78fe

Please sign in to comment.