-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} | ||
} |