Skip to content

Commit

Permalink
Add asset pkg with logo and info functions (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
unanoc authored Nov 30, 2021
1 parent be98393 commit 5f41310
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

jobs:
test:
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.17
require (
github.com/sirupsen/logrus v1.8.1
github.com/trustwallet/go-libs v0.2.17
github.com/trustwallet/go-primitives v0.0.11
github.com/trustwallet/go-primitives v0.0.14-0.20211130135322-c76db95f1406
)

require (
Expand All @@ -15,7 +15,6 @@ require (
github.com/magiconair/properties v1.8.5 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/pelletier/go-toml v1.9.3 // indirect
github.com/pkg/errors v0.9.1
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTK
github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ=
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down Expand Up @@ -276,6 +274,8 @@ github.com/trustwallet/go-libs v0.2.17 h1:l2zr5Ow19GTPnoWbhjExAhTbz7xLcYPXBa10EI
github.com/trustwallet/go-libs v0.2.17/go.mod h1:gBDrDkN5wOY+8kwlU6pnv3l/seGJy2qH1OpTKe7NnXA=
github.com/trustwallet/go-primitives v0.0.11 h1:uVjm1IssSrur5MjnSbl+LerljnaU8pvgoBxq7krjNvI=
github.com/trustwallet/go-primitives v0.0.11/go.mod h1:XPY046lWNrCZ67ZsCeQlJYbKTMDpulc9y7hiRjnL9R4=
github.com/trustwallet/go-primitives v0.0.14-0.20211130135322-c76db95f1406 h1:lezUwyiPYCChVu12XPGlc51cG4GE6hE0ONrKNG/UDQ8=
github.com/trustwallet/go-primitives v0.0.14-0.20211130135322-c76db95f1406/go.mod h1:jLqd7rm+4EYG5JdpxhngM9HwbqfEXzKy/wK4vUB7STs=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
12 changes: 12 additions & 0 deletions pkg/asset/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package asset

import "fmt"

func GetAssetInfoPath(chain, tokenID string) string {
return fmt.Sprintf("blockchains/%s/assets/%s/info.json", chain, tokenID)
}

func GetAssetInfoURL(repoOwner, repoName, branch, chain, tokenID string) string {
return fmt.Sprintf("https://raw.githubusercontent.com/%s/%s/%s/blockchains/%s/assets/%s/info.json",
repoOwner, repoName, branch, chain, tokenID)
}
46 changes: 46 additions & 0 deletions pkg/asset/logo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package asset

import (
"fmt"
"strings"

"github.com/trustwallet/go-primitives/types"
)

func GetAssetLogoPath(chain, tokenID string) string {
return fmt.Sprintf("blockchains/%s/assets/%s/logo.png", chain, tokenID)
}

func GetAssetLogoURL(repoOwner, repoName, branch, chain, tokenID string) string {
return fmt.Sprintf("https://raw.githubusercontent.com/%s/%s/%s/blockchains/%s/assets/%s/logo.png",
repoOwner, repoName, branch, chain, tokenID)
}

func GetTokenFromAssetLogoPath(path string) (tokenID, tokenType string, err error) {
for _, t := range types.GetTokenTypes() {
chain, err := types.GetChainFromAssetType(string(t))
if err != nil {
continue
}

prefix := fmt.Sprintf("blockchains/%s/assets/", chain.Handle)
suffix := "/logo.png"

if strings.HasPrefix(path, prefix) && strings.HasSuffix(path, suffix) {
tokenType = string(t)
tokenID = path[len(prefix):(len(path) - len(suffix))]

break
}
}

if tokenType == "TRC20" && strings.HasPrefix(tokenID, "10") {
tokenType = "TRC10"
}

if tokenID == "" && tokenType == "" {
return tokenID, tokenType, fmt.Errorf("couldn't get token id and token type")
}

return tokenID, tokenType, nil
}
25 changes: 25 additions & 0 deletions pkg/files.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package pkg

import (
"strings"
)

func IsFileAllowedInPR(path string) bool {
if strings.HasSuffix(path, "tokenlist.json") {
return false
}
if strings.HasPrefix(path, "blockchains") && strings.Index(path, "assets") > 0 {
return true
}
if strings.HasPrefix(path, "blockchains") && strings.HasSuffix(path, "allowlist.json") {
return true
}
if strings.HasPrefix(path, "blockchains") && strings.HasSuffix(path, "validators/list.json") {
return true
}
if strings.HasPrefix(path, "dapps") {
return true
}

return false
}

0 comments on commit 5f41310

Please sign in to comment.