mirror of
https://github.com/luxfi/assets.git
synced 2026-07-27 04:37:14 +00:00
* Create logo .png * Create logo.png * Create info.json * Create logo.png * Create info.json * Create info.json * Create logo.png * Create info.json * Create logo.png * Create info.json * Update info.json * Update info.json * Update info.json * Update info.json * Update info.json * Create logo.png * Delete logo .png * tokens * tokens * tokens * tokens * tokens * tokens --------- Co-authored-by: Denis <136321897+defisaur@users.noreply.github.com>
38 lines
737 B
Go
38 lines
737 B
Go
package external
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/trustwallet/assets-go-libs/http"
|
|
)
|
|
|
|
const splAPIURL = "https://public-api.solscan.io/token/holders?tokenAddress=%s"
|
|
|
|
type TokenInfoSPL struct {
|
|
Data []Data `json:"data"`
|
|
HoldersCount int `json:"total"`
|
|
}
|
|
|
|
type Data struct {
|
|
Decimals int `json:"decimals"`
|
|
}
|
|
|
|
func GetTokenInfoForSPL(tokenID string) (*TokenInfo, error) {
|
|
url := fmt.Sprintf(splAPIURL, tokenID)
|
|
|
|
var result TokenInfoSPL
|
|
err := http.GetHTTPResponse(url, &result)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if len(result.Data) == 0 {
|
|
return nil, fmt.Errorf("failed to get token info for SPL token")
|
|
}
|
|
|
|
return &TokenInfo{
|
|
Decimals: result.Data[0].Decimals,
|
|
HoldersCount: result.HoldersCount,
|
|
}, nil
|
|
}
|