Skip to content

Commit

Permalink
Add Okc to coin package (#78)
Browse files Browse the repository at this point in the history
* Add Okc coins

* Add Okc coins

* Add Okc coins
  • Loading branch information
Smea1 authored Aug 1, 2022
1 parent 40a1ef6 commit cf3b5f6
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 2 deletions.
25 changes: 25 additions & 0 deletions coin/coins.go

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

9 changes: 8 additions & 1 deletion coin/coins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -607,4 +607,11 @@
handle: nativeevmos
name: NativeEvmos
decimals: 18
blockchain: Cosmos
blockchain: Cosmos

- id: 996
symbol: OKT
handle: okc
name: OKX Chain
decimals: 18
blockchain: Ethereum
2 changes: 2 additions & 0 deletions coin/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ func GetCoinExploreURL(c Coin, tokenID, tokenType string) (string, error) {
return fmt.Sprintf("https://scan.meter.io/address/%s", tokenID), nil
case EVMOS:
return fmt.Sprintf("https://evm.evmos.org/address/%s", tokenID), nil
case OKC:
return fmt.Sprintf("https://www.oklink.com/en/okc/address/%s", tokenID), nil
}

return "", errors.New("no explorer for coin: " + c.Handle)
Expand Down
11 changes: 11 additions & 0 deletions coin/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,16 @@ func TestGetCoinExploreURL(t *testing.T) {
want: "https://evm.evmos.org/address/test",
wantErr: false,
},
{
name: "Test Okc",
args: args{
addr: "test",
tokenType: "KIP20",
chain: Okc(),
},
want: "https://www.oklink.com/en/okc/address/test",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -224,6 +234,7 @@ var evmCoinsTestSet = map[uint]struct{}{
METER: {},
EVMOS: {},
CELO: {},
OKC: {},
}

// TestEvmCoinsList This test will automatically fail when new EVM chain is added to coins.yml
Expand Down
2 changes: 2 additions & 0 deletions types/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func GetChainFromAssetType(assetType string) (coin.Coin, error) {
return coin.Meter(), nil
case EVMOS_ERC20:
return coin.Evmos(), nil
case KIP20:
return coin.Okc(), nil
}

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

const (
Expand Down Expand Up @@ -144,6 +145,7 @@ func GetTokenTypes() []TokenType {
KAVAERC20,
METER,
EVMOS_ERC20,
KIP20,
}
}

Expand Down Expand Up @@ -203,6 +205,8 @@ func GetTokenType(c uint, tokenID string) (string, bool) {
return string(ESDT), true
case coin.EVMOS:
return string(EVMOS_ERC20), true
case coin.OKC:
return string(KIP20), true
default:
return "", false
}
Expand Down Expand Up @@ -248,7 +252,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, METER, EVMOS_ERC20:
case ERC721, ERC1155, EOS, NEP5, VET, ONTOLOGY, THETA, TOMO, POA, OASIS, ALGORAND, KAVAERC20, METER, EVMOS_ERC20, KIP20:
return TokenVersionUndefined, nil
default:
// This should not happen, as it is guarded by TestGetTokenVersionImplementEverySupportedTokenTypes
Expand Down Expand Up @@ -316,6 +320,8 @@ func GetEthereumTokenTypeByIndex(coinIndex uint) (TokenType, error) {
tokenType = METER
case coin.EVMOS:
tokenType = EVMOS_ERC20
case coin.OKC:
tokenType = KIP20
}

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 @@ -386,6 +386,12 @@ func TestGetTokenVersion(t *testing.T) {
TokenVersionUndefined,
nil,
},
{
"Okc token version",
args{t: string(KIP20)},
TokenVersionUndefined,
nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit cf3b5f6

Please sign in to comment.