diff --git a/adapter.go b/adapter.go index 33d5e1a2..3e7532d2 100644 --- a/adapter.go +++ b/adapter.go @@ -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) diff --git a/asset.go b/asset.go index 36089f08..0dfe6149 100644 --- a/asset.go +++ b/asset.go @@ -4,7 +4,7 @@ import ( "github.com/GoFarsi/assets/entity" ) -type Asset struct { +type AssetRepo struct { Chains []*entity.Chain } @@ -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) } @@ -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) } diff --git a/entity/asset.go b/entity/asset.go index 347b7102..cf83b437 100644 --- a/entity/asset.go +++ b/entity/asset.go @@ -1,5 +1,7 @@ package entity +import "strings" + type ContractType string type LinkType string @@ -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 +}