Skip to content

Commit

Permalink
Update sui_getobject response
Browse files Browse the repository at this point in the history
  • Loading branch information
JaydenLink committed Oct 31, 2023
1 parent f336813 commit fdcc0e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
10 changes: 3 additions & 7 deletions models/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ type SuiObjectInfo struct {
}

type SuiMoveObject struct {
Type string `json:"type"`
Fields json.RawMessage `json:"fields"`
HasPublicTransfer bool `json:"hasPublicTransfer"`
}

func (v SuiMoveObject) Field(field string) gjson.Result {
return gjson.GetBytes(v.Fields, field)
Type string `json:"type"`
Fields map[string]interface{} `json:"fields"`
HasPublicTransfer bool `json:"hasPublicTransfer"`
}

type SuiMovePackage struct {
Expand Down
17 changes: 4 additions & 13 deletions sui/read_obj_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/block-vision/sui-go-sdk/common/httpconn"
"github.com/block-vision/sui-go-sdk/models"
"github.com/tidwall/gjson"
)

type IReadObjectFromSuiAPI interface {
SuiGetObject(ctx context.Context, req models.SuiGetObjectRequest) (models.SuiObjectData, error)
SuiGetObject(ctx context.Context, req models.SuiGetObjectRequest) (models.SuiObjectResponse, error)
SuiXGetOwnedObjects(ctx context.Context, req models.SuiXGetOwnedObjectsRequest) (models.PaginatedObjectsResponse, error)
SuiMultiGetObjects(ctx context.Context, req models.SuiMultiGetObjectsRequest) ([]*models.SuiObjectResponse, error)
SuiXGetDynamicField(ctx context.Context, req models.SuiXGetDynamicFieldRequest) (models.PaginatedDynamicFieldInfoResponse, error)
Expand All @@ -29,8 +28,8 @@ type suiReadObjectFromSuiImpl struct {
}

// SuiGetObject implements the method `sui_getObject`, gets the object information for a specified object.
func (s *suiReadObjectFromSuiImpl) SuiGetObject(ctx context.Context, req models.SuiGetObjectRequest) (models.SuiObjectData, error) {
var rsp models.SuiObjectData
func (s *suiReadObjectFromSuiImpl) SuiGetObject(ctx context.Context, req models.SuiGetObjectRequest) (models.SuiObjectResponse, error) {
var rsp models.SuiObjectResponse

respBytes, err := s.conn.Request(ctx, httpconn.Operation{
Method: "sui_getObject",
Expand All @@ -43,15 +42,7 @@ func (s *suiReadObjectFromSuiImpl) SuiGetObject(ctx context.Context, req models.
return rsp, err
}

if gjson.ParseBytes(respBytes).Get("error").Exists() {
return rsp, errors.New(gjson.ParseBytes(respBytes).Get("error").String())
}

if gjson.ParseBytes(respBytes).Get("result.error.code").Exists() {
return rsp, errors.New(fmt.Sprintf("the object is %s", gjson.ParseBytes(respBytes).Get("result.error.code").String()))
}

err = json.Unmarshal([]byte(gjson.ParseBytes(respBytes).Get("result.data").String()), &rsp)
err = json.Unmarshal([]byte(gjson.ParseBytes(respBytes).Get("result").String()), &rsp)
if err != nil {
return rsp, err
}
Expand Down

0 comments on commit fdcc0e0

Please sign in to comment.