Add ReadCoinMetadata API
Add ReadCoinMetadata API
This commit is contained in:
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user