-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
include tron token info on validation (#84)
- Loading branch information
1 parent
acae5a2
commit 0ca1ce5
Showing
3 changed files
with
80 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
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,38 @@ | ||
package external | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/trustwallet/assets-go-libs/http" | ||
) | ||
|
||
const trc10APIURL = "https://apilist.tronscan.io/api/token?id=%s" | ||
|
||
type TRC10TokensResponse struct { | ||
Data []struct { | ||
Symbol string `json:"abbr"` | ||
Decimals int `json:"precision"` | ||
HoldersCount int `json:"nrOfTokenHolders"` | ||
} `json:"data"` | ||
} | ||
|
||
func GetTokenInfoForTRC10(tokenID string) (*TokenInfo, error) { | ||
url := fmt.Sprintf(trc10APIURL, tokenID) | ||
|
||
var res TRC10TokensResponse | ||
err := http.GetHTTPResponse(url, &res) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(res.Data) == 0 { | ||
return nil, errors.New("not found") | ||
} | ||
|
||
return &TokenInfo{ | ||
Symbol: res.Data[0].Symbol, | ||
Decimals: res.Data[0].Decimals, | ||
HoldersCount: res.Data[0].HoldersCount, | ||
}, nil | ||
} |
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,38 @@ | ||
package external | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/trustwallet/assets-go-libs/http" | ||
) | ||
|
||
const trc20APIURL = "https://apilist.tronscan.io/api/token_trc20?contract=%s" | ||
|
||
type TRC20TokensResponse struct { | ||
TRC20Tokens []struct { | ||
Symbol string `json:"symbol"` | ||
Decimals int `json:"decimals"` | ||
HoldersCount int `json:"holders_count"` | ||
} `json:"trc20_tokens"` | ||
} | ||
|
||
func GetTokenInfoForTRC20(tokenID string) (*TokenInfo, error) { | ||
url := fmt.Sprintf(trc20APIURL, tokenID) | ||
|
||
var res TRC20TokensResponse | ||
err := http.GetHTTPResponse(url, &res) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(res.TRC20Tokens) == 0 { | ||
return nil, errors.New("not found") | ||
} | ||
|
||
return &TokenInfo{ | ||
Symbol: res.TRC20Tokens[0].Symbol, | ||
Decimals: res.TRC20Tokens[0].Decimals, | ||
HoldersCount: res.TRC20Tokens[0].HoldersCount, | ||
}, nil | ||
} |