Skip to content

Commit

Permalink
Add TokenType (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
vikmeup authored Nov 24, 2020
1 parent 3d9a5ce commit 076b9ba
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tokentype/tokentype.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package tokentype

import "github.com/trustwallet/golibs/coin"

type (
TokenType string
)

const (
ERC20 TokenType = "ERC20"
BEP2 TokenType = "BEP2"
BEP8 TokenType = "BEP8"
BEP20 TokenType = "BEP20"
TRC10 TokenType = "TRC10"
ETC20 TokenType = "ETC20"
POA20 TokenType = "POA20"
TRC20 TokenType = "TRC20"
TRC21 TokenType = "TRC21"
CLO20 TokenType = "CLO20"
GO20 TokenType = "G020"
WAN20 TokenType = "WAN20"
TT20 TokenType = "TT20"
KAVA TokenType = "KAVA"
)

func GetEthereumTokenTypeByIndex(coinIndex uint) TokenType {
var tokenType TokenType
switch coinIndex {
case coin.Ethereum().ID:
tokenType = ERC20
case coin.Classic().ID:
tokenType = ETC20
case coin.Poa().ID:
tokenType = POA20
case coin.Callisto().ID:
tokenType = CLO20
case coin.Wanchain().ID:
tokenType = WAN20
case coin.Thundertoken().ID:
tokenType = TT20
case coin.Gochain().ID:
tokenType = GO20
case coin.Tomochain().ID:
tokenType = TRC21
case coin.Bsc().ID, coin.Smartchain().ID:
tokenType = BEP20
default:
tokenType = ERC20
}
return tokenType
}

45 changes: 45 additions & 0 deletions tokentype/tokentype_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package tokentype

import (
"github.com/trustwallet/golibs/coin"
"testing"
)

func TestGetEthereumTokenTypeByIndex(t *testing.T) {
type args struct {
coinIndex uint
}
tests := []struct {
name string
args args
want TokenType
}{
{
"Ethereum ERC20",
args{coinIndex: coin.ETH},
ERC20,
},
{
"Ethereum Classic ETC20",
args{coinIndex: coin.ETC},
ETC20,
},
{
"TomoChain TRC21",
args{coinIndex: coin.TOMO},
TRC21,
},
{
"WanChain WAN20",
args{coinIndex: coin.WAN},
WAN20,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetEthereumTokenTypeByIndex(tt.args.coinIndex); got != tt.want {
t.Errorf("GetEthereumTokenTypeByIndex() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 076b9ba

Please sign in to comment.