Skip to content

Commit

Permalink
Fix update-auto & upgrade assets-go-libs (trustwallet#21016)
Browse files Browse the repository at this point in the history
  • Loading branch information
covain authored Jun 14, 2022
1 parent f0a07c4 commit 989189e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
7 changes: 6 additions & 1 deletion internal/manager/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 12 additions & 2 deletions internal/processor/fixers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
28 changes: 16 additions & 12 deletions internal/processor/updaters_auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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),
Expand All @@ -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],
})
}

Expand Down

0 comments on commit 989189e

Please sign in to comment.