diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 78dcecb..f161d77 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,9 @@ name: CI on: push: - branches: [ master ] + branches: [ main ] pull_request: - branches: [ master ] + branches: [ main ] jobs: test: diff --git a/go.mod b/go.mod index e7e5cbe..59cc72b 100644 --- a/go.mod +++ b/go.mod @@ -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 ( @@ -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 diff --git a/go.sum b/go.sum index 6b57baa..b8ad0ba 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/pkg/asset/info.go b/pkg/asset/info.go new file mode 100644 index 0000000..144339c --- /dev/null +++ b/pkg/asset/info.go @@ -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) +} diff --git a/pkg/asset/logo.go b/pkg/asset/logo.go new file mode 100644 index 0000000..73b9ef7 --- /dev/null +++ b/pkg/asset/logo.go @@ -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 +} diff --git a/pkg/files.go b/pkg/files.go new file mode 100644 index 0000000..3bfed7f --- /dev/null +++ b/pkg/files.go @@ -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 +}