From fdcc0e043d8335a7c21159e2567df1dd3e789d7d Mon Sep 17 00:00:00 2001 From: JaydenLink Date: Tue, 31 Oct 2023 18:40:12 +0800 Subject: [PATCH] Update sui_getobject response --- models/objects.go | 10 +++------- sui/read_obj_api.go | 17 ++++------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/models/objects.go b/models/objects.go index 290d197..fb2aa66 100644 --- a/models/objects.go +++ b/models/objects.go @@ -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 { diff --git a/sui/read_obj_api.go b/sui/read_obj_api.go index 6cd8785..1e70e86 100644 --- a/sui/read_obj_api.go +++ b/sui/read_obj_api.go @@ -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) @@ -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", @@ -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 }