Skip to content

Commit

Permalink
Update assets-go-libs version (trustwallet#16703)
Browse files Browse the repository at this point in the history
  • Loading branch information
unanoc authored Dec 20, 2021
1 parent 31eeb8e commit 675478e
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 56 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
7 changes: 3 additions & 4 deletions internal/file/path.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down Expand Up @@ -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
})
Expand Down
24 changes: 13 additions & 11 deletions internal/processor/fixers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion internal/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 15 additions & 14 deletions internal/processor/updaters_auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
}
Expand All @@ -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),
Expand Down Expand Up @@ -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)
}
18 changes: 9 additions & 9 deletions internal/processor/updaters_manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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) {
Expand Down
13 changes: 6 additions & 7 deletions internal/processor/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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())
Expand Down
12 changes: 3 additions & 9 deletions internal/service/service.go
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 675478e

Please sign in to comment.