Merge pull request #2514 from nspcc-dev/rpc/fix-exception-marshalling

rpc: always marshal FaultException
This commit is contained in:
Roman Khimov 2022-05-25 12:29:51 +03:00 committed by GitHub
commit 50222d768a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 12 deletions

View file

@ -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

View file

@ -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))