Skip to content

Commit

Permalink
Fix the format for response string when wawaka method invocations fail
Browse files Browse the repository at this point in the history
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 <mic.bowman@intel.com>
cmickeyb authored and prakashngit committed Aug 16, 2022
1 parent f425c25 commit cd993a6
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions common/interpreter/InvocationHelpers.cpp
Original file line number Diff line number Diff line change
@@ -86,6 +86,21 @@ void pc::parse_invocation_response(
const JSON_Value* response_value = json_object_get_value(parsed_object, "Response");
pe::ThrowIfNull(response_value, "invalid response string; missing Response field");

// status
outStatus = (json_object_dotget_boolean(parsed_object, "Status") == 1);
if (! outStatus) {
pe::ThrowIf<pe::RuntimeError>(
json_type(response_value) != JSONString,
"invalid invocation response; failure result must be a string");
outResponse = json_string(response_value);
outStateChanged = false;
return;
}

// state changed
outStateChanged = (json_object_dotget_boolean(parsed_object, "StateChanged") == 1);

// result
size_t serialized_size = json_serialization_size(response_value);
ByteArray serialized_response_value;
serialized_response_value.resize(serialized_size);
@@ -110,12 +125,6 @@ void pc::parse_invocation_response(
const char* state_hash = json_object_dotget_string(dependency, "StateHash");
outDependencies[contract_id] = state_hash;
}

// status
outStatus = (json_object_dotget_boolean(parsed_object, "Status") == 1);

// state changed
outStateChanged = (json_object_dotget_boolean(parsed_object, "StateChanged") == 1);
}

// -----------------------------------------------------------------

0 comments on commit cd993a6

Please sign in to comment.