2021-12-19 21:39:53 +00:00
|
|
|
package processor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/trustwallet/assets/internal/file"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Service struct {
|
|
|
|
fileService *file.Service
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewService(fileProvider *file.Service) *Service {
|
|
|
|
return &Service{fileService: fileProvider}
|
|
|
|
}
|
|
|
|
|
2022-01-07 11:45:16 +00:00
|
|
|
func (s *Service) GetValidator(f *file.AssetFile) []Validator {
|
2022-01-07 13:02:59 +00:00
|
|
|
jsonValidator := Validator{Name: "JSON validation", Run: s.ValidateJSON}
|
|
|
|
|
2021-12-19 21:39:53 +00:00
|
|
|
switch f.Type() {
|
|
|
|
case file.TypeRootFolder:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
|
|
|
{Name: "Root folder contains only allowed files", Run: s.ValidateRootFolder},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
case file.TypeChainFolder:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
|
|
|
{Name: "Chain folders are lowercase and contains only allowed files", Run: s.ValidateChainFolder},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
case file.TypeChainLogoFile, file.TypeAssetLogoFile, file.TypeValidatorsLogoFile, file.TypeDappsLogoFile:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
|
|
|
{Name: "Logos (size, dimension)", Run: s.ValidateImage},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
case file.TypeAssetFolder:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
|
|
|
{Name: "Each asset folder has valid asset address and contains logo/info", Run: s.ValidateAssetFolder},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
case file.TypeDappsFolder:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
|
|
|
{Name: "Dapps folder (allowed only png files, lowercase)", Run: s.ValidateDappsFolder},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
case file.TypeAssetInfoFile:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
2022-01-07 13:02:59 +00:00
|
|
|
jsonValidator,
|
|
|
|
{Name: "Asset info", Run: s.ValidateAssetInfoFile},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
case file.TypeChainInfoFile:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
2022-01-07 13:02:59 +00:00
|
|
|
{Name: "Chain Info", Run: s.ValidateChainInfoFile},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
case file.TypeValidatorsListFile:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
2022-01-07 13:02:59 +00:00
|
|
|
jsonValidator,
|
2022-01-07 11:45:16 +00:00
|
|
|
{Name: "Validators list file", Run: s.ValidateValidatorsListFile},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
case file.TypeTokenListFile:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
2022-01-07 13:02:59 +00:00
|
|
|
jsonValidator,
|
2022-01-09 20:30:49 +00:00
|
|
|
{Name: "Token list", Run: s.ValidateTokenListFile},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
case file.TypeChainInfoFolder:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
|
|
|
{Name: "Chain Info Folder (has files)", Run: s.ValidateInfoFolder},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
case file.TypeValidatorsAssetFolder:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
|
|
|
{Name: "Validators asset folder (has logo, valid asset address)", Run: s.ValidateValidatorsAssetFolder},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) GetFixers(f *file.AssetFile) []Fixer {
|
2022-01-07 11:45:16 +00:00
|
|
|
jsonFixer := Fixer{
|
|
|
|
Name: "Formatting all json files",
|
2021-12-19 21:39:53 +00:00
|
|
|
Run: s.FixJSON,
|
|
|
|
}
|
|
|
|
|
|
|
|
switch f.Type() {
|
|
|
|
case file.TypeChainInfoFile:
|
|
|
|
return []Fixer{
|
2022-01-07 11:45:16 +00:00
|
|
|
jsonFixer,
|
|
|
|
{Name: "Fixing chain info.json files", Run: s.FixChainInfoJSON},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
case file.TypeAssetInfoFile:
|
|
|
|
return []Fixer{
|
2022-01-07 11:45:16 +00:00
|
|
|
jsonFixer,
|
2022-01-09 20:30:49 +00:00
|
|
|
{Name: "Fixing asset info.json files", Run: s.FixAssetInfo},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
case file.TypeValidatorsListFile:
|
|
|
|
return []Fixer{
|
2022-01-07 11:45:16 +00:00
|
|
|
jsonFixer,
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
case file.TypeAssetFolder:
|
|
|
|
return []Fixer{
|
2022-01-07 11:45:16 +00:00
|
|
|
{Name: "Renaming EVM's asset folder to valid address checksum", Run: s.FixETHAddressChecksum},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
case file.TypeChainLogoFile, file.TypeAssetLogoFile, file.TypeValidatorsLogoFile, file.TypeDappsLogoFile:
|
|
|
|
return []Fixer{
|
2022-01-07 11:45:16 +00:00
|
|
|
{Name: "Resizing and compressing logo images", Run: s.FixLogo},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) GetUpdatersAuto() []Updater {
|
|
|
|
return []Updater{
|
2022-01-07 11:45:16 +00:00
|
|
|
{Name: "Retrieving missing token images, creating binance token list.", Run: s.UpdateBinanceTokens},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) GetUpdatersManual() []Updater {
|
|
|
|
return []Updater{
|
2022-01-07 11:45:16 +00:00
|
|
|
{Name: "Update tokenlist.json for Ethereum", Run: s.UpdateEthereumTokenlist},
|
|
|
|
{Name: "Update tokenlist.json for Smartchain", Run: s.UpdateSmartchainTokenlist},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
}
|