fix: rewrite ObjectOwner UnmarshalJSON

This commit is contained in:
miancan
2024-05-31 15:23:13 +08:00
parent 50509636ea
commit d51dbdb85d
2 changed files with 23 additions and 2 deletions

View File

@@ -89,7 +89,28 @@ type SuiObjectResponseError struct {
Digest string `json:"digest"`
}
type ObjectOwner struct {
func (o *ObjectOwner) UnmarshalJSON(data []byte) error {
res := gjson.ParseBytes(data)
if !res.IsObject() {
o.ObjectType = res.String()
return nil
}
o.AddressOwner = res.Get("AddressOwner").String()
o.ObjectOwner = res.Get("ObjectOwner").String()
shard := res.Get("Shared").String()
if shard != "" {
var objectShare ObjectShare
err := json.Unmarshal([]byte(shard), &objectShare)
if err != nil {
return err
}
o.Shared = objectShare
}
return nil
}
type ObjectOwner struct { //This struct has its own UnmarshalJSON method !!!
ObjectType string `json:"ObjectType"` //if Immutable return Immutable
// the owner's Sui address
AddressOwner string `json:"AddressOwner"`
ObjectOwner string `json:"ObjectOwner"`

View File

@@ -189,7 +189,7 @@ type SuiTransactionBlockResponse struct {
type ObjectChange struct {
Type string `json:"type"`
Sender string `json:"sender"`
Owner interface{} `json:"owner"` //sometime string,sometime object
Owner ObjectOwner `json:"owner"`
ObjectType string `json:"objectType"`
ObjectId string `json:"objectId"`
PackageId string `json:"packageId"`