Skip to content

Commit cd993a6

Browse files
cmickeybprakashngit
authored andcommitted
Fix the format for response string when wawaka method invocations fail
The response message for failed method invocations was an encoded JSON string while other messages were simply a string. Now, when a method fails the result must be a string value and it will be returned immediately, without JSON encoding. Signed-off-by: Mic Bowman <[email protected]>
1 parent f425c25 commit cd993a6

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

common/interpreter/InvocationHelpers.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,21 @@ void pc::parse_invocation_response(
8686
const JSON_Value* response_value = json_object_get_value(parsed_object, "Response");
8787
pe::ThrowIfNull(response_value, "invalid response string; missing Response field");
8888

89+
// status
90+
outStatus = (json_object_dotget_boolean(parsed_object, "Status") == 1);
91+
if (! outStatus) {
92+
pe::ThrowIf<pe::RuntimeError>(
93+
json_type(response_value) != JSONString,
94+
"invalid invocation response; failure result must be a string");
95+
outResponse = json_string(response_value);
96+
outStateChanged = false;
97+
return;
98+
}
99+
100+
// state changed
101+
outStateChanged = (json_object_dotget_boolean(parsed_object, "StateChanged") == 1);
102+
103+
// result
89104
size_t serialized_size = json_serialization_size(response_value);
90105
ByteArray serialized_response_value;
91106
serialized_response_value.resize(serialized_size);
@@ -110,12 +125,6 @@ void pc::parse_invocation_response(
110125
const char* state_hash = json_object_dotget_string(dependency, "StateHash");
111126
outDependencies[contract_id] = state_hash;
112127
}
113-
114-
// status
115-
outStatus = (json_object_dotget_boolean(parsed_object, "Status") == 1);
116-
117-
// state changed
118-
outStateChanged = (json_object_dotget_boolean(parsed_object, "StateChanged") == 1);
119128
}
120129

121130
// -----------------------------------------------------------------

0 commit comments

Comments
 (0)