From 675478e12254394d77b96f7bea405a57e73c3523 Mon Sep 17 00:00:00 2001
From: Daniel <24758309+leedaniil@users.noreply.github.com>
Date: Mon, 20 Dec 2021 18:03:08 +0300
Subject: [PATCH] Update assets-go-libs version (#16703)

---
 go.mod                                |  2 +-
 go.sum                                |  8 ++++++++
 internal/file/path.go                 |  7 +++----
 internal/processor/fixers.go          | 24 ++++++++++++----------
 internal/processor/processor.go       |  1 -
 internal/processor/updaters_auto.go   | 29 ++++++++++++++-------------
 internal/processor/updaters_manual.go | 18 ++++++++---------
 internal/processor/validators.go      | 13 ++++++------
 internal/service/service.go           | 12 +++--------
 9 files changed, 58 insertions(+), 56 deletions(-)

diff --git a/go.mod b/go.mod
index 32bb67edd..6e0042ac6 100644
--- a/go.mod
+++ b/go.mod
@@ -4,7 +4,7 @@ go 1.17
 
 require (
 	github.com/sirupsen/logrus v1.8.1
-	github.com/trustwallet/assets-go-libs v0.0.16
+	github.com/trustwallet/assets-go-libs v0.0.17
 	github.com/trustwallet/go-libs v0.2.21-0.20211217144209-59d4828f9793
 	github.com/trustwallet/go-primitives v0.0.17
 )
diff --git a/go.sum b/go.sum
index ee2543191..615b8bf1d 100644
--- a/go.sum
+++ b/go.sum
@@ -42,6 +42,14 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s
 github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
 github.com/trustwallet/assets-go-libs v0.0.16 h1:nbKrf/pHKQCut4Q5Mdg5BinLdFxOqvzEeAgIgzX0/P8=
 github.com/trustwallet/assets-go-libs v0.0.16/go.mod h1:agKWTQ9ECSzQ++7P/9viSxJnG1Kp+WhfDyI3pAmtnVM=
+github.com/trustwallet/assets-go-libs v0.0.17-0.20211220141041-3b3a722649fa h1:d+FAYtxmN8mJK9jobkzOotwSEU2KPZ9H4gmuBg6dv3M=
+github.com/trustwallet/assets-go-libs v0.0.17-0.20211220141041-3b3a722649fa/go.mod h1:agKWTQ9ECSzQ++7P/9viSxJnG1Kp+WhfDyI3pAmtnVM=
+github.com/trustwallet/assets-go-libs v0.0.17-0.20211220141745-408afc4f7467 h1:JYCmTXnQfR/RElBY9aFppwLVwvy7wuBNbtW5f31j1Vs=
+github.com/trustwallet/assets-go-libs v0.0.17-0.20211220141745-408afc4f7467/go.mod h1:agKWTQ9ECSzQ++7P/9viSxJnG1Kp+WhfDyI3pAmtnVM=
+github.com/trustwallet/assets-go-libs v0.0.17-0.20211220144503-44a66d3a5e92 h1:TT3IFY3cBZBQAMdoVA8bzdH8q58d8hkiiVpBAmZJ+J8=
+github.com/trustwallet/assets-go-libs v0.0.17-0.20211220144503-44a66d3a5e92/go.mod h1:agKWTQ9ECSzQ++7P/9viSxJnG1Kp+WhfDyI3pAmtnVM=
+github.com/trustwallet/assets-go-libs v0.0.17 h1:s/XF4C7peyFuKadoRr9YhjfMoWAx9yKzk2IFmtT5ZpM=
+github.com/trustwallet/assets-go-libs v0.0.17/go.mod h1:agKWTQ9ECSzQ++7P/9viSxJnG1Kp+WhfDyI3pAmtnVM=
 github.com/trustwallet/go-libs v0.2.21-0.20211217144209-59d4828f9793 h1:KFtyLpBPbMyUdeCth/Zcej/SSgAFIo6fxdS2eEPEg3I=
 github.com/trustwallet/go-libs v0.2.21-0.20211217144209-59d4828f9793/go.mod h1:7QdAp1lcteKKI0DYqGoaO8KO4eTNYjGmg8vHy0YXkKc=
 github.com/trustwallet/go-primitives v0.0.17 h1:1fBxZMKGCHdHtgdUzsqdFlD21+1GneIk/sxN6jxYBds=
diff --git a/internal/file/path.go b/internal/file/path.go
index 16d576f85..bb893f8b8 100644
--- a/internal/file/path.go
+++ b/internal/file/path.go
@@ -1,12 +1,11 @@
 package file
 
 import (
-	"fmt"
 	"os"
 	"path/filepath"
 	"regexp"
 
-	"github.com/trustwallet/assets-go-libs/pkg"
+	"github.com/trustwallet/assets-go-libs/strings"
 	"github.com/trustwallet/go-primitives/coin"
 )
 
@@ -144,11 +143,11 @@ func ReadLocalFileStructure(root string, filesToSkip []string) ([]string, error)
 				return err
 			}
 
-			if pkg.Contains(path, filesToSkip) {
+			if strings.Contains(path, filesToSkip) {
 				return nil
 			}
 
-			paths = append(paths, fmt.Sprintf("./%s", path))
+			paths = append(paths, path)
 
 			return nil
 		})
diff --git a/internal/processor/fixers.go b/internal/processor/fixers.go
index eefe51aa4..95075e018 100644
--- a/internal/processor/fixers.go
+++ b/internal/processor/fixers.go
@@ -6,9 +6,11 @@ import (
 	"path/filepath"
 	"strings"
 
-	"github.com/trustwallet/assets-go-libs/pkg"
-	"github.com/trustwallet/assets-go-libs/pkg/validation"
-	"github.com/trustwallet/assets-go-libs/pkg/validation/info"
+	fileLib "github.com/trustwallet/assets-go-libs/file"
+	"github.com/trustwallet/assets-go-libs/image"
+	"github.com/trustwallet/assets-go-libs/path"
+	"github.com/trustwallet/assets-go-libs/validation"
+	"github.com/trustwallet/assets-go-libs/validation/info"
 	"github.com/trustwallet/assets/internal/file"
 	"github.com/trustwallet/go-primitives/address"
 	"github.com/trustwallet/go-primitives/coin"
@@ -18,7 +20,7 @@ import (
 )
 
 func (s *Service) FixJSON(f *file.AssetFile) error {
-	return pkg.FormatJSONFile(f.Path())
+	return fileLib.FormatJSONFile(f.Path())
 }
 
 func (s *Service) FixETHAddressChecksum(f *file.AssetFile) error {
@@ -35,7 +37,7 @@ func (s *Service) FixETHAddressChecksum(f *file.AssetFile) error {
 			return fmt.Errorf("failed to get checksum: %s", e)
 		}
 
-		newName := fmt.Sprintf("blockchains/%s/assets/%s", f.Chain().Handle, checksum)
+		newName := path.GetAssetPath(f.Chain().Handle, checksum)
 
 		if e = os.Rename(f.Path(), newName); e != nil {
 			return fmt.Errorf("failed to rename dir: %s", e)
@@ -52,7 +54,7 @@ func (s *Service) FixETHAddressChecksum(f *file.AssetFile) error {
 }
 
 func (s *Service) FixLogo(f *file.AssetFile) error {
-	width, height, err := pkg.GetPNGImageDimensions(f.Path())
+	width, height, err := image.GetPNGImageDimensions(f.Path())
 	if err != nil {
 		return err
 	}
@@ -67,7 +69,7 @@ func (s *Service) FixLogo(f *file.AssetFile) error {
 
 		targetW, targetH := calculateTargetDimension(width, height)
 
-		err = pkg.ResizePNG(f.Path(), targetW, targetH)
+		err = image.ResizePNG(f.Path(), targetW, targetH)
 		if err != nil {
 			return err
 		}
@@ -101,7 +103,7 @@ func calculateTargetDimension(width, height int) (targetW, targetH int) {
 func (s *Service) FixChainInfoJSON(f *file.AssetFile) error {
 	chainInfo := info.CoinModel{}
 
-	err := pkg.ReadJSONFile(f.Path(), &chainInfo)
+	err := fileLib.ReadJSONFile(f.Path(), &chainInfo)
 	if err != nil {
 		return err
 	}
@@ -110,7 +112,7 @@ func (s *Service) FixChainInfoJSON(f *file.AssetFile) error {
 	if chainInfo.Type == nil || *chainInfo.Type != expectedType {
 		chainInfo.Type = &expectedType
 
-		return pkg.CreateJSONFile(f.Path(), &chainInfo)
+		return fileLib.CreateJSONFile(f.Path(), &chainInfo)
 	}
 
 	return nil
@@ -119,7 +121,7 @@ func (s *Service) FixChainInfoJSON(f *file.AssetFile) error {
 func (s *Service) FixAssetInfoJSON(file *file.AssetFile) error {
 	assetInfo := info.AssetModel{}
 
-	err := pkg.ReadJSONFile(file.Path(), &assetInfo)
+	err := fileLib.ReadJSONFile(file.Path(), &assetInfo)
 	if err != nil {
 		return err
 	}
@@ -164,7 +166,7 @@ func (s *Service) FixAssetInfoJSON(file *file.AssetFile) error {
 	}
 
 	if isModified {
-		return pkg.CreateJSONFile(file.Path(), &assetInfo)
+		return fileLib.CreateJSONFile(file.Path(), &assetInfo)
 	}
 
 	return nil
diff --git a/internal/processor/processor.go b/internal/processor/processor.go
index 5e2bf98ce..022f10236 100644
--- a/internal/processor/processor.go
+++ b/internal/processor/processor.go
@@ -12,7 +12,6 @@ func NewService(fileProvider *file.Service) *Service {
 	return &Service{fileService: fileProvider}
 }
 
-// nolint:funlen
 func (s *Service) GetValidator(f *file.AssetFile) *Validator {
 	switch f.Type() {
 	case file.TypeRootFolder:
diff --git a/internal/processor/updaters_auto.go b/internal/processor/updaters_auto.go
index d605b98ac..03448f19f 100644
--- a/internal/processor/updaters_auto.go
+++ b/internal/processor/updaters_auto.go
@@ -7,9 +7,10 @@ import (
 	"strconv"
 	"time"
 
-	"github.com/trustwallet/assets-go-libs/pkg"
-	"github.com/trustwallet/assets-go-libs/pkg/asset"
-	"github.com/trustwallet/assets-go-libs/pkg/validation/info"
+	fileLib "github.com/trustwallet/assets-go-libs/file"
+	"github.com/trustwallet/assets-go-libs/image"
+	"github.com/trustwallet/assets-go-libs/path"
+	"github.com/trustwallet/assets-go-libs/validation/info"
 	"github.com/trustwallet/assets/internal/config"
 	"github.com/trustwallet/go-libs/blockchain/binance"
 	"github.com/trustwallet/go-libs/blockchain/binance/explorer"
@@ -68,8 +69,8 @@ func fetchMissingAssets(chain coin.Coin, assets []explorer.Bep2Asset) error {
 			continue
 		}
 
-		assetLogoPath := asset.GetAssetLogoPath(chain.Handle, a.Asset)
-		if pkg.FileExists(assetLogoPath) {
+		assetLogoPath := path.GetAssetLogoPath(chain.Handle, a.Asset)
+		if fileLib.FileExists(assetLogoPath) {
 			continue
 		}
 
@@ -86,12 +87,12 @@ func fetchMissingAssets(chain coin.Coin, assets []explorer.Bep2Asset) error {
 }
 
 func createLogo(assetLogoPath string, a explorer.Bep2Asset) error {
-	err := pkg.CreateDirPath(assetLogoPath)
+	err := fileLib.CreateDirPath(assetLogoPath)
 	if err != nil {
 		return err
 	}
 
-	return pkg.CreatePNGFromURL(a.AssetImg, assetLogoPath)
+	return image.CreatePNGFromURL(a.AssetImg, assetLogoPath)
 }
 
 func createInfoJSON(chain coin.Coin, a explorer.Bep2Asset) error {
@@ -117,9 +118,9 @@ func createInfoJSON(chain coin.Coin, a explorer.Bep2Asset) error {
 		ID:          &a.Asset,
 	}
 
-	assetInfoPath := asset.GetAssetInfoPath(chain.Handle, a.Asset)
+	assetInfoPath := path.GetAssetInfoPath(chain.Handle, a.Asset)
 
-	return pkg.CreateJSONFile(assetInfoPath, &assetInfo)
+	return fileLib.CreateJSONFile(assetInfoPath, &assetInfo)
 }
 
 func createTokenListJSON(chain coin.Coin, marketPairs []binance.MarketPair, tokenList binance.Tokens) error {
@@ -128,10 +129,10 @@ func createTokenListJSON(chain coin.Coin, marketPairs []binance.MarketPair, toke
 		return nil
 	}
 
-	tokenListPath := fmt.Sprintf("blockchains/%s/tokenlist.json", chain.Handle)
+	tokenListPath := path.GetTokenListPath(chain.Handle)
 
 	var oldTokenList TokenList
-	err = pkg.ReadJSONFile(tokenListPath, &oldTokenList)
+	err = fileLib.ReadJSONFile(tokenListPath, &oldTokenList)
 	if err != nil {
 		return nil
 	}
@@ -143,7 +144,7 @@ func createTokenListJSON(chain coin.Coin, marketPairs []binance.MarketPair, toke
 	}
 
 	if len(tokens) > 0 {
-		return pkg.CreateJSONFile(tokenListPath, &TokenList{
+		return fileLib.CreateJSONFile(tokenListPath, &TokenList{
 			Name:      fmt.Sprintf("Trust Wallet: %s", coin.Coins[coin.BINANCE].Symbol),
 			LogoURI:   twLogoURL,
 			Timestamp: time.Now().Format(timestampFormat),
@@ -254,8 +255,8 @@ func getTokenType(symbol string, nativeCoinSymbol string, tokenType string) stri
 
 func getLogoURI(id, githubChainFolder, nativeCoinSymbol string) string {
 	if id == nativeCoinSymbol {
-		return fmt.Sprintf("%s/blockchains/%s/info/logo.png", config.Default.URLs.TWAssetsApp, githubChainFolder)
+		return path.GetChainLogoURL(config.Default.URLs.TWAssetsApp, githubChainFolder)
 	}
 
-	return fmt.Sprintf("%s/blockchains/%s/assets/%s/logo.png", config.Default.URLs.TWAssetsApp, githubChainFolder, id)
+	return path.GetAssetLogoURL(config.Default.URLs.TWAssetsApp, githubChainFolder, id)
 }
diff --git a/internal/processor/updaters_manual.go b/internal/processor/updaters_manual.go
index f1c49c6f3..3fdcdbbdb 100644
--- a/internal/processor/updaters_manual.go
+++ b/internal/processor/updaters_manual.go
@@ -2,14 +2,14 @@ package processor
 
 import (
 	"encoding/json"
-	"fmt"
 	"strconv"
 	"strings"
 
 	log "github.com/sirupsen/logrus"
 
-	"github.com/trustwallet/assets-go-libs/pkg"
-	"github.com/trustwallet/assets-go-libs/pkg/asset"
+	fileLib "github.com/trustwallet/assets-go-libs/file"
+	"github.com/trustwallet/assets-go-libs/http"
+	"github.com/trustwallet/assets-go-libs/path"
 	"github.com/trustwallet/assets/internal/config"
 	"github.com/trustwallet/go-libs/client/api/backend"
 	"github.com/trustwallet/go-primitives/address"
@@ -205,7 +205,7 @@ func fetchTradingPairs(url string, query map[string]string) (*TradingPairs, erro
 	log.WithField("url", url).Debug("Retrieving trading pair infos")
 
 	var result TradingPairs
-	err = pkg.PostHTTPResponse(url, jsonValue, &result)
+	err = http.PostHTTPResponse(url, jsonValue, &result)
 	if err != nil {
 		return nil, err
 	}
@@ -411,10 +411,10 @@ func rebuildTokenList(chain coin.Coin, pairs [][]TokenItem, forceExcludeList []s
 
 	log.Debugf("%d unsupported tokens filtered out, %d pairs", filteredCount, len(pairs2))
 
-	tokenListPath := fmt.Sprintf("blockchains/%s/tokenlist.json", chain.Handle)
+	tokenListPath := path.GetTokenListPath(chain.Handle)
 
 	var list TokenList
-	err := pkg.ReadJSONFile(tokenListPath, &list)
+	err := fileLib.ReadJSONFile(tokenListPath, &list)
 	if err != nil {
 		return nil
 	}
@@ -439,13 +439,13 @@ func rebuildTokenList(chain coin.Coin, pairs [][]TokenItem, forceExcludeList []s
 	log.Debugf("Tokenlist: list with %d tokens and %d pairs written to %s.",
 		len(list.Tokens), totalPairs, tokenListPath)
 
-	return pkg.CreateJSONFile(tokenListPath, list)
+	return fileLib.CreateJSONFile(tokenListPath, list)
 }
 
 func checkTokenExists(chain, tokenID string) bool {
-	logoPath := asset.GetAssetLogoPath(chain, tokenID)
+	logoPath := path.GetAssetLogoPath(chain, tokenID)
 
-	return pkg.FileExists(logoPath)
+	return fileLib.FileExists(logoPath)
 }
 
 func removeAllPairs(list *TokenList) {
diff --git a/internal/processor/validators.go b/internal/processor/validators.go
index 642848d99..8ce9e744f 100644
--- a/internal/processor/validators.go
+++ b/internal/processor/validators.go
@@ -7,9 +7,10 @@ import (
 	"io"
 	"os"
 
-	"github.com/trustwallet/assets-go-libs/pkg/validation"
-	"github.com/trustwallet/assets-go-libs/pkg/validation/info"
-	"github.com/trustwallet/assets-go-libs/pkg/validation/list"
+	"github.com/trustwallet/assets-go-libs/path"
+	"github.com/trustwallet/assets-go-libs/validation"
+	"github.com/trustwallet/assets-go-libs/validation/info"
+	"github.com/trustwallet/assets-go-libs/validation/list"
 	"github.com/trustwallet/assets/internal/config"
 	"github.com/trustwallet/assets/internal/file"
 	"github.com/trustwallet/go-primitives/coin"
@@ -121,9 +122,7 @@ func (s *Service) ValidateAssetFolder(f *file.AssetFile) error {
 	errLogo := validation.ValidateHasFiles(dirFiles, []string{"logo.png"})
 
 	if errLogo != nil || errInfo != nil {
-		infoFile := s.fileService.GetAssetFile(fmt.Sprintf("%s/info.json", f.Path()))
-
-		file2, err := os.Open(infoFile.Path())
+		file2, err := os.Open(path.GetAssetInfoPath(f.Chain().Handle, f.Asset()))
 		if err != nil {
 			return err
 		}
@@ -304,7 +303,7 @@ func (s *Service) ValidateValidatorsListFile(f *file.AssetFile) error {
 		listIDs[i] = *listItem.ID
 	}
 
-	assetsPath := fmt.Sprintf("blockchains/%s/validators/assets", f.Chain().Handle)
+	assetsPath := path.GetValidatorAssetsPath(f.Chain().Handle)
 	assetFolder := s.fileService.GetAssetFile(assetsPath)
 
 	file2, err := os.Open(assetFolder.Path())
diff --git a/internal/service/service.go b/internal/service/service.go
index 233df6a87..37ed63784 100644
--- a/internal/service/service.go
+++ b/internal/service/service.go
@@ -1,7 +1,7 @@
 package service
 
 import (
-	"github.com/trustwallet/assets-go-libs/pkg/validation"
+	"github.com/trustwallet/assets-go-libs/validation"
 	"github.com/trustwallet/assets/internal/file"
 	"github.com/trustwallet/assets/internal/processor"
 
@@ -71,19 +71,13 @@ func HandleError(err error, info *file.AssetFile, valName string) {
 	errors := UnwrapComposite(err)
 
 	for _, err := range errors {
-		logFields := log.Fields{
+		log.WithFields(log.Fields{
 			"type":       info.Type(),
 			"chain":      info.Chain().Handle,
 			"asset":      info.Asset(),
 			"path":       info.Path(),
 			"validation": valName,
-		}
-
-		if warn, ok := err.(*validation.Warning); ok {
-			log.WithFields(logFields).Warning(warn)
-		} else {
-			log.WithFields(logFields).Error(err)
-		}
+		}).Error(err)
 	}
 }