Skip to content

Commit

Permalink
Added additional check on transform constructing (#109)
Browse files Browse the repository at this point in the history
* Added check for execution results building
  • Loading branch information
ZhmakAS authored Aug 6, 2024
1 parent fdac8c4 commit 963249d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 5 additions & 1 deletion types/execution_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,16 @@ func NewExecutionResultFromV1(v1 ExecutionResultV1) ExecutionResult {
for _, transform := range v1.Success.Effect.Transforms {
transforms = append(transforms, Transform{
Key: transform.Key,
Kind: TransformKind(transform.Transform),
Kind: transform.Transform,
})
}

transfers := make([]Transfer, 0)
for _, transform := range v1.Success.Effect.Transforms {
if !transform.Transform.IsWriteTransfer() {
continue
}

writeTransfer, err := transform.Transform.ParseAsWriteTransfer()
if err != nil {
continue
Expand Down
16 changes: 12 additions & 4 deletions types/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,19 @@ func (t *TransformKind) IsWriteTransfer() bool {

func (t *TransformKind) ParseAsWriteTransfer() (*WriteTransfer, error) {
type RawWriteTransferTransform struct {
WriteTransfer `json:"WriteTransfer"`
WriteTransfer *WriteTransfer `json:"WriteTransfer"`
}

jsonRes := RawWriteTransferTransform{}
if err := json.Unmarshal(*t, &jsonRes); err != nil {
return nil, err
}

return &jsonRes.WriteTransfer, nil
if jsonRes.WriteTransfer == nil {
return nil, errors.New("error: empty response")
}

return jsonRes.WriteTransfer, nil
}

func (t *TransformKind) IsWriteAccount() bool {
Expand Down Expand Up @@ -298,15 +302,19 @@ func (t *TransformKind) ParseAsUInt512() (*clvalue.UInt512, error) {

func (t *TransformKind) ParseAsWriteDeployInfo() (*DeployInfo, error) {
type RawWriteDeployInfo struct {
WriteDeployInfo DeployInfo `json:"WriteDeployInfo"`
WriteDeployInfo *DeployInfo `json:"WriteDeployInfo"`
}

jsonRes := RawWriteDeployInfo{}
if err := json.Unmarshal(*t, &jsonRes); err != nil {
return nil, err
}

return &jsonRes.WriteDeployInfo, nil
if jsonRes.WriteDeployInfo == nil {
return nil, errors.New("error: empty response")
}

return jsonRes.WriteDeployInfo, nil
}

func (t *TransformKind) ParseAsWriteCLValue() (*Argument, error) {
Expand Down

0 comments on commit 963249d

Please sign in to comment.