Add ReadCoinMetadata API

Add ReadCoinMetadata API
This commit is contained in:
jiang
2022-12-21 16:54:15 +08:00
parent 1a01796094
commit 199b0b6147
2 changed files with 35 additions and 0 deletions

View File

@@ -64,3 +64,16 @@ type TryGetPastObjectResponse struct {
Reference sui_types.SuiObjectRef `json:"reference"`
} `json:"details"`
}
type GetCoinMetadataRequest struct {
CoinType string
}
type GetCoinMetadataResponse struct {
Decimals uint8 `json:"decimals"`
Description string `json:"description"`
IconUrl string `json:"iconUrl,omitempty"`
Id string `json:"id"`
Name string `json:"name"`
Symbol string `json:"symbol"`
}

View File

@@ -16,6 +16,7 @@ type IReadObjectFromSuiAPI interface {
GetObjectsOwnedByObject(ctx context.Context, req models.GetObjectsOwnedByObjectRequest, opts ...interface{}) (models.GetObjectsOwnedByObjectResponse, error)
GetRawObject(ctx context.Context, req models.GetRawObjectRequest, opts ...interface{}) (models.GetRawObjectResponse, error)
TryGetPastObject(ctx context.Context, req models.TryGetPastObjectRequest, opt ...interface{}) (models.TryGetPastObjectResponse, error)
GetCoinMetadata(ctx context.Context, req models.GetCoinMetadataRequest, opt ...interface{}) (models.GetCoinMetadataResponse, error)
}
type suiReadObjectFromSuiImpl struct {
@@ -139,3 +140,24 @@ func (s *suiReadObjectFromSuiImpl) TryGetPastObject(ctx context.Context, req mod
}
return rsp, nil
}
func (s *suiReadObjectFromSuiImpl) GetCoinMetadata(ctx context.Context, req models.GetCoinMetadataRequest, opt ...interface{}) (models.GetCoinMetadataResponse, error) {
var rsp models.GetCoinMetadataResponse
respBytes, err := s.cli.Request(ctx, models.Operation{
Method: "sui_getCoinMetadata",
Params: []interface{}{
req.CoinType,
},
})
if err != nil {
return models.GetCoinMetadataResponse{}, err
}
if gjson.ParseBytes(respBytes).Get("error").Exists() {
return models.GetCoinMetadataResponse{}, errors.New(gjson.ParseBytes(respBytes).Get("error").String())
}
err = json.Unmarshal([]byte(gjson.ParseBytes(respBytes).Get("result").String()), &rsp)
if err != nil {
return models.GetCoinMetadataResponse{}, err
}
return rsp, nil
}