diff --git a/go.mod b/go.mod index 4c0855d73..00f38991c 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.18 require ( github.com/sirupsen/logrus v1.8.1 github.com/spf13/cobra v1.4.0 - github.com/trustwallet/assets-go-libs v0.2.0 + github.com/trustwallet/assets-go-libs v0.3.0 github.com/trustwallet/go-libs v0.3.13 github.com/trustwallet/go-primitives v0.0.50 ) diff --git a/go.sum b/go.sum index 6578af5da..72ed8bd57 100644 --- a/go.sum +++ b/go.sum @@ -51,6 +51,8 @@ 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.2.0 h1:TUBlCnbbJ55Sa4c2uG3amvAnxuzSRlgSj1GzlnOFav0= github.com/trustwallet/assets-go-libs v0.2.0/go.mod h1:IW7K3aJcVlsXnQWD61KyQ46Nvb5iIPrptsKuSDFYbj8= +github.com/trustwallet/assets-go-libs v0.3.0 h1:roDXZaUciPbTfwTbCQRajcDFwrFGkVhhCAxGelztjvU= +github.com/trustwallet/assets-go-libs v0.3.0/go.mod h1:IW7K3aJcVlsXnQWD61KyQ46Nvb5iIPrptsKuSDFYbj8= github.com/trustwallet/go-libs v0.3.13 h1:zB30WfP6Do+5Cf3+HgkUhawBf1fnOdvvC/eBfCHKBEw= github.com/trustwallet/go-libs v0.3.13/go.mod h1:FuDoyKxhE1IgLPWMfU1PFok87MqfYm/spJJx1QziWe8= github.com/trustwallet/go-primitives v0.0.45 h1:SFeAUgFc4slZGA26pcEGGaCKrqHvmZa5CFvSjbmv4KM= diff --git a/internal/manager/commands.go b/internal/manager/commands.go index cae122a5e..d52a6762e 100644 --- a/internal/manager/commands.go +++ b/internal/manager/commands.go @@ -118,13 +118,18 @@ func AddTokenToTokenListJSON(chain coin.Coin, assetID, tokenID string, tokenList } list.Tokens = append(list.Tokens, newToken) - return libFile.CreateJSONFile(tokenListPath, &tokenlist.Model{ + data, err := libFile.PrepareJSONData(&tokenlist.Model{ Name: fmt.Sprintf("Trust Wallet: %s", coin.Coins[chain.ID].Name), LogoURI: config.Default.URLs.Logo, Timestamp: time.Now().Format(config.Default.TimeFormat), Tokens: list.Tokens, Version: tokenlist.Version{Major: list.Version.Major + 1}, }) + if err != nil { + return err + } + + return libFile.CreateJSONFile(tokenListPath, data) } func getAssetInfo(chain coin.Coin, tokenID string) (*info.AssetModel, error) { diff --git a/internal/processor/fixers.go b/internal/processor/fixers.go index 896d41261..78f25bb45 100644 --- a/internal/processor/fixers.go +++ b/internal/processor/fixers.go @@ -111,7 +111,12 @@ func (s *Service) FixChainInfoJSON(f *file.AssetFile) error { if chainInfo.Type == nil || *chainInfo.Type != expectedType { chainInfo.Type = &expectedType - return file.CreateJSONFile(f.Path(), &chainInfo) + data, err := file.PrepareJSONData(&chainInfo) + if err != nil { + return err + } + + return file.CreateJSONFile(f.Path(), data) } return nil @@ -165,7 +170,12 @@ func (s *Service) FixAssetInfo(f *file.AssetFile) error { } if isModified { - return file.CreateJSONFile(f.Path(), &assetInfo) + data, err := file.PrepareJSONData(&assetInfo) + if err != nil { + return err + } + + return file.CreateJSONFile(f.Path(), data) } return nil diff --git a/internal/processor/updaters_auto.go b/internal/processor/updaters_auto.go index 59084bf64..f00a16ff6 100644 --- a/internal/processor/updaters_auto.go +++ b/internal/processor/updaters_auto.go @@ -130,7 +130,12 @@ func createInfoJSON(chain coin.Coin, a explorer.Bep2Asset) error { assetInfoPath := path.GetAssetInfoPath(chain.Handle, a.Asset) - return fileLib.CreateJSONFile(assetInfoPath, &assetInfo) + data, err := fileLib.PrepareJSONData(&assetInfo) + if err != nil { + return err + } + + return fileLib.CreateJSONFile(assetInfoPath, data) } func createTokenListJSON(chain coin.Coin, tokens []tokenlist.Token) error { @@ -150,16 +155,21 @@ func createTokenListJSON(chain coin.Coin, tokens []tokenlist.Token) error { return nil } - log.Debugf("Tokenlist: list with %d tokens and %d pairs written to %s.", - len(tokens), countTotalPairs(tokens), tokenListPath) - - return fileLib.CreateJSONFile(tokenListPath, &tokenlist.Model{ + data, err := fileLib.PrepareJSONData(&tokenlist.Model{ Name: fmt.Sprintf("Trust Wallet: %s", coin.Coins[chain.ID].Name), LogoURI: config.Default.URLs.Logo, Timestamp: time.Now().Format(config.Default.TimeFormat), Tokens: tokens, Version: tokenlist.Version{Major: oldTokenList.Version.Major + 1}, }) + if err != nil { + return err + } + + log.Debugf("Tokenlist: list with %d tokens and %d pairs written to %s.", + len(tokens), countTotalPairs(tokens), tokenListPath) + + return fileLib.CreateJSONFile(tokenListPath, data) } func countTotalPairs(tokens []tokenlist.Token) int { @@ -227,12 +237,6 @@ func generateTokenList(marketPairs []binance.MarketPair, tokenList binance.Token for pair := range pairsList { token := tokensMap[pair] - var pairs []tokenlist.Pair - pairs, exists := pairsMap[token.Symbol] - if !exists { - pairs = make([]tokenlist.Pair, 0) - } - tokenItems = append(tokenItems, tokenlist.Token{ Asset: getAssetIDSymbol(token.Symbol, coin.Coins[coin.BINANCE].Symbol, coin.BINANCE), Type: getTokenType(token.Symbol, coin.Coins[coin.BINANCE].Symbol, types.BEP2), @@ -241,7 +245,7 @@ func generateTokenList(marketPairs []binance.MarketPair, tokenList binance.Token Symbol: token.OriginalSymbol, Decimals: coin.Coins[coin.BINANCE].Decimals, LogoURI: getLogoURI(token.Symbol, coin.Coins[coin.BINANCE].Handle, coin.Coins[coin.BINANCE].Symbol), - Pairs: pairs, + Pairs: pairsMap[token.Symbol], }) }