2021-12-19 21:39:53 +00:00
|
|
|
package processor
|
|
|
|
|
|
|
|
import (
|
2022-01-27 23:59:22 +00:00
|
|
|
assetsmanager "github.com/trustwallet/assets-go-libs/client/assets-manager"
|
2022-02-09 11:03:36 +00:00
|
|
|
"github.com/trustwallet/assets-go-libs/file"
|
2022-01-20 13:51:37 +00:00
|
|
|
"github.com/trustwallet/assets/internal/config"
|
2021-12-19 21:39:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Service struct {
|
2022-01-20 13:51:37 +00:00
|
|
|
fileService *file.Service
|
|
|
|
assetsManager assetsmanager.Client
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewService(fileProvider *file.Service) *Service {
|
2022-01-20 13:51:37 +00:00
|
|
|
return &Service{
|
|
|
|
fileService: fileProvider,
|
|
|
|
assetsManager: assetsmanager.InitClient(config.Default.ClientURLs.AssetsManagerAPI, nil),
|
|
|
|
}
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
|
|
|
|
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() {
|
2022-01-12 14:34:32 +00:00
|
|
|
case file.TypeAssetFolder:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
2022-01-12 14:34:32 +00:00
|
|
|
{Name: "Each asset folder has valid asset address and contains only allowed files", Run: s.ValidateAssetFolder},
|
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
|
|
|
}
|
2022-01-12 14:34:32 +00:00
|
|
|
case file.TypeChainInfoFolder:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
2022-01-12 14:34:32 +00:00
|
|
|
{Name: "Chain Info Folder (has files)", Run: s.ValidateInfoFolder},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
2022-01-12 14:34:32 +00:00
|
|
|
case file.TypeDappsFolder:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
2022-01-12 14:34:32 +00:00
|
|
|
{Name: "Dapps folder contains only allowed png files in lowercase", Run: s.ValidateDappsFolder},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
2022-01-12 14:34:32 +00:00
|
|
|
case file.TypeRootFolder:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
2022-01-12 14:34:32 +00:00
|
|
|
{Name: "Root folder contains only allowed files", Run: s.ValidateRootFolder},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
2022-01-12 14:34:32 +00:00
|
|
|
case file.TypeValidatorsAssetFolder:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
2022-01-12 14:34:32 +00:00
|
|
|
{Name: "Validators asset folder has logo and valid asset address)", Run: s.ValidateValidatorsAssetFolder},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
2022-01-12 14:34:32 +00:00
|
|
|
|
|
|
|
case file.TypeAssetLogoFile, file.TypeChainLogoFile, file.TypeDappsLogoFile, file.TypeValidatorsLogoFile:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
2022-01-12 14:34:32 +00:00
|
|
|
{Name: "Logos size and dimension are valid", Run: s.ValidateImage},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
2022-01-12 14:34:32 +00:00
|
|
|
case file.TypeAssetInfoFile:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
2022-01-07 13:02:59 +00:00
|
|
|
jsonValidator,
|
2022-01-12 14:34:32 +00:00
|
|
|
{Name: "Asset info file is valid", Run: s.ValidateAssetInfoFile},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
2022-01-12 14:34:32 +00:00
|
|
|
case file.TypeChainInfoFile:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
2022-01-12 14:34:32 +00:00
|
|
|
{Name: "Chain info file is valid", Run: s.ValidateChainInfoFile},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
2022-01-12 14:34:32 +00:00
|
|
|
case file.TypeTokenListFile:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
2022-01-12 14:34:32 +00:00
|
|
|
jsonValidator,
|
|
|
|
{Name: "Tokenlist file is valid", Run: s.ValidateTokenListFile},
|
2021-12-19 21:39:53 +00:00
|
|
|
}
|
2022-02-03 20:36:45 +00:00
|
|
|
case file.TypeTokenListExtendedFile:
|
|
|
|
return []Validator{
|
|
|
|
jsonValidator,
|
|
|
|
{Name: "Tokenlist Extended file is valid", Run: s.ValidateTokenListExtendedFile},
|
|
|
|
}
|
2022-01-12 14:34:32 +00:00
|
|
|
case file.TypeValidatorsListFile:
|
2022-01-07 11:45:16 +00:00
|
|
|
return []Validator{
|
2022-01-12 14:34:32 +00:00
|
|
|
jsonValidator,
|
|
|
|
{Name: "Validators list file is valid", Run: s.ValidateValidatorsListFile},
|
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() {
|
2022-01-12 14:34:32 +00:00
|
|
|
case file.TypeAssetFolder:
|
2021-12-19 21:39:53 +00:00
|
|
|
return []Fixer{
|
2022-01-12 14:34:32 +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.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
|
|
|
}
|
2022-01-12 14:34:32 +00:00
|
|
|
case file.TypeChainInfoFile:
|
2021-12-19 21:39:53 +00:00
|
|
|
return []Fixer{
|
2022-01-07 11:45:16 +00:00
|
|
|
jsonFixer,
|
2022-01-12 14:34:32 +00:00
|
|
|
{Name: "Fixing chain info.json files", Run: s.FixChainInfoJSON},
|
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
|
|
|
}
|
2022-01-12 14:34:32 +00:00
|
|
|
case file.TypeValidatorsListFile:
|
|
|
|
return []Fixer{
|
|
|
|
jsonFixer,
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|