From 98b5e2b3538af80bf94d18364f745bc9ef0a843b Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 25 May 2022 10:48:58 +0300 Subject: [PATCH] rpc: always marshal FaultException --- pkg/rpc/response/result/invoke.go | 29 +++++++++++++++----------- pkg/rpc/response/result/invoke_test.go | 1 + 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/pkg/rpc/response/result/invoke.go b/pkg/rpc/response/result/invoke.go index 37cbbab05..dd2e436e8 100644 --- a/pkg/rpc/response/result/invoke.go +++ b/pkg/rpc/response/result/invoke.go @@ -66,7 +66,7 @@ type invokeAux struct { GasConsumed int64 `json:"gasconsumed,string"` Script []byte `json:"script"` Stack json.RawMessage `json:"stack"` - FaultException string `json:"exception,omitempty"` + FaultException *string `json:"exception"` Notifications []state.NotificationEvent `json:"notifications"` Transaction []byte `json:"tx,omitempty"` Diagnostics *InvokeDiag `json:"diagnostics,omitempty"` @@ -145,16 +145,19 @@ arrloop: if r.Transaction != nil { txbytes = r.Transaction.Bytes() } - return json.Marshal(&invokeAux{ - GasConsumed: r.GasConsumed, - Script: r.Script, - State: r.State, - Stack: st, - FaultException: r.FaultException, - Notifications: r.Notifications, - Transaction: txbytes, - Diagnostics: r.Diagnostics, - }) + aux := &invokeAux{ + GasConsumed: r.GasConsumed, + Script: r.Script, + State: r.State, + Stack: st, + Notifications: r.Notifications, + Transaction: txbytes, + Diagnostics: r.Diagnostics, + } + if len(r.FaultException) != 0 { + aux.FaultException = &r.FaultException + } + return json.Marshal(aux) } // UnmarshalJSON implements the json.Unmarshaler. @@ -207,7 +210,9 @@ func (r *Invoke) UnmarshalJSON(data []byte) error { r.GasConsumed = aux.GasConsumed r.Script = aux.Script r.State = aux.State - r.FaultException = aux.FaultException + if aux.FaultException != nil { + r.FaultException = *aux.FaultException + } r.Notifications = aux.Notifications r.Transaction = tx r.Diagnostics = aux.Diagnostics diff --git a/pkg/rpc/response/result/invoke_test.go b/pkg/rpc/response/result/invoke_test.go index ba4387773..09dc588dc 100644 --- a/pkg/rpc/response/result/invoke_test.go +++ b/pkg/rpc/response/result/invoke_test.go @@ -40,6 +40,7 @@ func TestInvoke_MarshalJSON(t *testing.T) { {"type":"Integer","value":"1"} ], "notifications":[], + "exception": null, "tx":"` + base64.StdEncoding.EncodeToString(tx.Bytes()) + `" }` require.JSONEq(t, expected, string(data))