Skip to content

Commit

Permalink
Add Meter to coin package (#75)
Browse files Browse the repository at this point in the history
* Add meter to token type

* Add specific test for the new token type

Co-authored-by: Ivan Bozhytskyi <[email protected]>
  • Loading branch information
hewigovens and covain authored Jul 11, 2022
1 parent cd79efc commit 297c9c7
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 4 deletions.
25 changes: 24 additions & 1 deletion coin/coins.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion coin/coins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -510,4 +510,10 @@
symbol: KAVA
handle: kavaevm
name: KavaEvm
decimals: 18
decimals: 18

- id: 18000
symbol: MTR
handle: meter
name: Meter
decimals: 18
5 changes: 4 additions & 1 deletion coin/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ func IsEVM(coinID uint) bool {
KCC,
AURORA,
ARBITRUM,
KAVAEVM:
KAVAEVM,
METER:
return true
}

Expand Down Expand Up @@ -130,6 +131,8 @@ func GetCoinExploreURL(c Coin, tokenID, tokenType string) (string, error) {
return fmt.Sprintf("https://algoexplorer.io/asset/%s", tokenID), nil
case KAVAEVM:
return fmt.Sprintf("https://explorer.kava.io/token/%s", tokenID), nil
case METER:
return fmt.Sprintf("https://scan.meter.io/address/%s", tokenID), nil
}

return "", errors.New("no explorer for coin: " + c.Handle)
Expand Down
10 changes: 10 additions & 0 deletions coin/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ func TestGetCoinExploreURL(t *testing.T) {
want: "https://explorer.kava.io/token/test",
wantErr: false,
},
{
name: "Test Meter",
args: args{
addr: "test",
tokenType: "METER",
chain: Meter(),
},
want: "https://scan.meter.io/address/test",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions types/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func GetChainFromAssetType(assetType string) (coin.Coin, error) {
return coin.Algorand(), nil
case KAVAERC20:
return coin.Kavaevm(), nil
case METER:
return coin.Meter(), nil
}

return coin.Coin{}, errors.New("unknown asset type: " + assetType)
Expand Down
6 changes: 5 additions & 1 deletion types/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const (
AURORA TokenType = "AURORA"
ALGORAND TokenType = "ALGORAND"
KAVAERC20 TokenType = "KAVAERC20"
METER TokenType = "METER"
)

const (
Expand Down Expand Up @@ -140,6 +141,7 @@ func GetTokenTypes() []TokenType {
AURORA,
ALGORAND,
KAVAERC20,
METER,
}
}

Expand Down Expand Up @@ -242,7 +244,7 @@ func GetTokenVersion(tokenType string) (TokenVersion, error) {
return TokenVersionV10, nil
case RONIN, AURORA:
return TokenVersionV11, nil
case ERC721, ERC1155, EOS, NEP5, VET, ONTOLOGY, THETA, TOMO, POA, OASIS, ALGORAND, KAVAERC20:
case ERC721, ERC1155, EOS, NEP5, VET, ONTOLOGY, THETA, TOMO, POA, OASIS, ALGORAND, KAVAERC20, METER:
return TokenVersionUndefined, nil
default:
// This should not happen, as it is guarded by TestGetTokenVersionImplementEverySupportedTokenTypes
Expand Down Expand Up @@ -306,6 +308,8 @@ func GetEthereumTokenTypeByIndex(coinIndex uint) (TokenType, error) {
tokenType = ARBITRUM
case coin.KAVAEVM:
tokenType = KAVAERC20
case coin.METER:
tokenType = METER
}

if tokenType == "" {
Expand Down
6 changes: 6 additions & 0 deletions types/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,12 @@ func TestGetTokenVersion(t *testing.T) {
TokenVersionUndefined,
ErrUnknownTokenType,
},
{
"Meter token version",
args{t: string(METER)},
TokenVersionUndefined,
nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 297c9c7

Please sign in to comment.