Skip to content

Commit

Permalink
fix: Fix the error jsonp format in vm_message (#1160)
Browse files Browse the repository at this point in the history
* fix the error jsonp format

* fix lint

---------

Co-authored-by: Terry <[email protected]>
  • Loading branch information
Terryhung and Terry authored Mar 15, 2023
1 parent e832048 commit 1b14b45
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lens/util/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func init() {

var log = logging.Logger("lily/lens")

type CBORByteArray struct {
Params string
}

func ParseVmMessageParams(params []byte, paramsCodec uint64, method abi.MethodNum, actCode cid.Cid) (string, string, error) {
m, found := ActorRegistry.Methods[actCode][method]
if !found {
Expand All @@ -52,7 +56,11 @@ func ParseVmMessageParams(params []byte, paramsCodec uint64, method abi.MethodNu
// If the codec is 0, the parameters/return value are "empty".
// If the codec is 0x55, it's bytes.
if paramsCodec == 0 || paramsCodec == 0x55 {
return string(params), m.Name, nil
paramj, err := json.Marshal(CBORByteArray{Params: string(params)})
if err != nil {
return "", "", err
}
return string(paramj), m.Name, nil
}
return ParseParams(params, method, actCode)
}
Expand All @@ -74,7 +82,11 @@ func ParseVmMessageReturn(ret []byte, retCodec uint64, method abi.MethodNum, act
// If the codec is 0, the parameters/return value are "empty".
// If the codec is 0x55, it's bytes.
if retCodec == 0 || retCodec == 0x55 {
return string(ret), m.Name, nil
retj, err := json.Marshal(CBORByteArray{Params: string(ret)})
if err != nil {
return "", "", err
}
return string(retj), m.Name, nil
}
return ParseReturn(ret, method, actCode)
}
Expand Down

0 comments on commit 1b14b45

Please sign in to comment.