From 963249d6a92fe8f73b1dee8425279cf52fe18b0c Mon Sep 17 00:00:00 2001 From: ZhmakAS Date: Tue, 6 Aug 2024 09:24:45 +0200 Subject: [PATCH] Added additional check on transform constructing (#109) * Added check for execution results building --- types/execution_result.go | 6 +++++- types/transform.go | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/types/execution_result.go b/types/execution_result.go index dd90890..d12016b 100644 --- a/types/execution_result.go +++ b/types/execution_result.go @@ -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 diff --git a/types/transform.go b/types/transform.go index 1a59033..2ebe6aa 100644 --- a/types/transform.go +++ b/types/transform.go @@ -63,7 +63,7 @@ func (t *TransformKind) IsWriteTransfer() bool { func (t *TransformKind) ParseAsWriteTransfer() (*WriteTransfer, error) { type RawWriteTransferTransform struct { - WriteTransfer `json:"WriteTransfer"` + WriteTransfer *WriteTransfer `json:"WriteTransfer"` } jsonRes := RawWriteTransferTransform{} @@ -71,7 +71,11 @@ func (t *TransformKind) ParseAsWriteTransfer() (*WriteTransfer, error) { 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 { @@ -298,7 +302,7 @@ 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{} @@ -306,7 +310,11 @@ func (t *TransformKind) ParseAsWriteDeployInfo() (*DeployInfo, error) { 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) {