mirror of
https://github.com/Instadapp/trustwallet-assets.git
synced 2024-07-29 22:37:31 +00:00
2794a27cfb
* Add command for adding asset template * Fix explorer links for terra
70 lines
1.4 KiB
Go
70 lines
1.4 KiB
Go
package manager
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
libFile "github.com/trustwallet/assets-go-libs/file"
|
|
"github.com/trustwallet/assets-go-libs/path"
|
|
"github.com/trustwallet/assets-go-libs/validation/info"
|
|
"github.com/trustwallet/go-primitives/asset"
|
|
"github.com/trustwallet/go-primitives/coin"
|
|
)
|
|
|
|
func CreateAssetInfoJSONTemplate(token string) error {
|
|
c, tokenID, err := asset.ParseID(token)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to parse token id: %v", err)
|
|
}
|
|
|
|
chain, ok := coin.Coins[c]
|
|
if !ok {
|
|
return fmt.Errorf("invalid token")
|
|
}
|
|
|
|
assetInfoPath := path.GetAssetInfoPath(chain.Handle, tokenID)
|
|
|
|
var emptyStr string
|
|
var emptyInt int
|
|
assetInfoModel := info.AssetModel{
|
|
Name: &emptyStr,
|
|
Type: &emptyStr,
|
|
Symbol: &emptyStr,
|
|
Decimals: &emptyInt,
|
|
Website: &emptyStr,
|
|
Explorer: &emptyStr,
|
|
Status: &emptyStr,
|
|
ID: &tokenID,
|
|
Links: []info.Link{
|
|
{
|
|
Name: &emptyStr,
|
|
URL: &emptyStr,
|
|
},
|
|
},
|
|
Tags: []string{""},
|
|
}
|
|
|
|
bytes, err := json.Marshal(&assetInfoModel)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to marshal json: %v", err)
|
|
}
|
|
|
|
f, err := libFile.CreateFileWithPath(assetInfoPath)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to create file: %v", err)
|
|
}
|
|
defer f.Close()
|
|
|
|
_, err = f.Write(bytes)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to write bytes to file")
|
|
}
|
|
|
|
err = libFile.FormatJSONFile(assetInfoPath)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to format json file")
|
|
}
|
|
|
|
return nil
|
|
}
|