Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mj committed May 7, 2023
2 parents bddfe8b + a535f6c commit aacfa4f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
2 changes: 1 addition & 1 deletion adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
type logoPathPattern func(path string) string

// adaptLogoPath will format all logo paths of chains and assets by using specific pattern
func (a *Asset) adaptLogoPath(patternFunc logoPathPattern) {
func (a *AssetRepo) adaptLogoPath(patternFunc logoPathPattern) {
var wg sync.WaitGroup

adaptedChains := make(chan *entity.Chain)
Expand Down
14 changes: 7 additions & 7 deletions asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/GoFarsi/assets/entity"
)

type Asset struct {
type AssetRepo struct {
Chains []*entity.Chain
}

Expand All @@ -17,11 +17,11 @@ type Option struct {
*Pagination
}

func New(assetsRepo string) *Asset {
func New(repoAddress string) *AssetRepo {
chains := parseAssetsByteToArray()
asset := &Asset{Chains: chains}
asset := &AssetRepo{Chains: chains}

switch assetsRepo {
switch repoAddress {
case GithubRepoUrl:
asset.adaptLogoPath(formatFilePathByGithubRepo)
}
Expand All @@ -30,18 +30,18 @@ func New(assetsRepo string) *Asset {
}

// GetTotalChainsSize return len of all chains in assets.yaml
func (a *Asset) GetTotalChainsSize() int {
func (a *AssetRepo) GetTotalChainsSize() int {
return len(a.Chains)
}

// GetTestChains return test chains (networks) in assets.yaml
func (a *Asset) GetTestChains(option *Option) ([]*entity.Chain, error) {
func (a *AssetRepo) GetTestChains(option *Option) ([]*entity.Chain, error) {
chains := getChainsByType(a.Chains, entity.TestChainType)
return applyOptionsOnChains(chains, option)
}

// GetMainChains return main chains (networks) in assets.yaml
func (a *Asset) GetMainChains(option *Option) ([]*entity.Chain, error) {
func (a *AssetRepo) GetMainChains(option *Option) ([]*entity.Chain, error) {
chains := getChainsByType(a.Chains, entity.MainChainType)
return applyOptionsOnChains(chains, option)
}
Expand Down
46 changes: 46 additions & 0 deletions entity/asset.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package entity

import "strings"

type ContractType string
type LinkType string

Expand Down Expand Up @@ -29,3 +31,47 @@ type Asset struct {
Types []string `yaml:"types"`
Standards []string `yaml:"standards"`
}

func (a *Asset) GetName() string {
return a.Name
}

func (a *Asset) GetSymbol() string {
return a.Symbol
}

func (a *Asset) GetPrimaryContractAddress() string {
return a.Contracts[PrimaryContractType]
}

func (a *Asset) GetProxyContractAddress() string {
return a.Contracts[ProxyContractType]
}

func (a *Asset) GetDecimals() int {
return a.Decimals
}

func (a *Asset) GetDescription() string {
return a.Description
}

func (a *Asset) hasErc20() bool {
for _, s := range a.Standards {
if strings.ToUpper(s) == "ERC20" {
return true
}
}

return false
}

func (a *Asset) hasErc721() bool {
for _, s := range a.Standards {
if strings.ToUpper(s) == "ERC721" {
return true
}
}

return false
}

0 comments on commit aacfa4f

Please sign in to comment.