move dump transaction to json in extra function

This commit is contained in:
Dario 2020-12-15 09:31:58 +01:00 committed by Ulf Gebhardt
parent b7e0c14999
commit afe0500a88
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD
2 changed files with 40 additions and 24 deletions

View File

@ -487,34 +487,15 @@ namespace model {
consensus_submit_message.setMessage(DataTypeConverter::binToBase64((const unsigned char*)raw_message.data(), raw_message.size(), sodium_base64_VARIANT_URLSAFE_NO_PADDING));
}
else if (ServerConfig::HEDERA_CONSENSUS_FORMAT_JSON == ServerConfig::g_ConsensusMessageFormat) {
std::string json_message = "";
std::string json_message_body = "";
google::protobuf::util::JsonPrintOptions options;
options.add_whitespace = true;
options.always_print_primitive_fields = true;
auto status = google::protobuf::util::MessageToJsonString(mProtoTransaction, &json_message, options);
if (!status.ok()) {
addError(new ParamError(function_name, "error by parsing transaction message to json", status.ToString()));
addError(new ParamError(function_name, "pending task id: ", getModel()->getID()));
std::string json_message = getTransactionAsJson();
if (json_message != "") {
consensus_submit_message.setMessage(json_message);
}
else {
sendErrorsAsEmail();
return -7;
}
status = google::protobuf::util::MessageToJsonString(*mTransactionBody->getBody(), &json_message_body, options);
if (!status.ok()) {
addError(new ParamError(function_name, "error by parsing transaction body message to json", status.ToString()));
addError(new ParamError(function_name, "pending task id: ", getModel()->getID()));
sendErrorsAsEmail();
return -8;
}
//\"bodyBytes\": \"MigKIC7Sihz14RbYNhVAa8V3FSIhwvd0pWVvZqDnVA91dtcbIgRnZGQx\"
int startBodyBytes = json_message.find("bodyBytes") + std::string("\"bodyBytes\": \"").size()-2;
int endCur = json_message.find_first_of('\"', startBodyBytes+2)+1;
json_message.replace(startBodyBytes, endCur - startBodyBytes, json_message_body);
//printf("json: %s\n", json_message.data());
consensus_submit_message.setMessage(json_message);
}
// if using testnet, transfer message base64 encoded to check messages in hedera block explorer
//if (network_type == table::HEDERA_TESTNET) {
@ -580,6 +561,38 @@ namespace model {
}
}
std::string Transaction::getTransactionAsJson()
{
static const char* function_name = "Transaction::getTransactionAsJson";
std::string json_message = "";
std::string json_message_body = "";
google::protobuf::util::JsonPrintOptions options;
options.add_whitespace = true;
options.always_print_primitive_fields = true;
auto status = google::protobuf::util::MessageToJsonString(mProtoTransaction, &json_message, options);
if (!status.ok()) {
addError(new ParamError(function_name, "error by parsing transaction message to json", status.ToString()));
addError(new ParamError(function_name, "pending task id: ", getModel()->getID()));
return "";
}
status = google::protobuf::util::MessageToJsonString(*mTransactionBody->getBody(), &json_message_body, options);
if (!status.ok()) {
addError(new ParamError(function_name, "error by parsing transaction body message to json", status.ToString()));
addError(new ParamError(function_name, "pending task id: ", getModel()->getID()));
return "";
}
//\"bodyBytes\": \"MigKIC7Sihz14RbYNhVAa8V3FSIhwvd0pWVvZqDnVA91dtcbIgRnZGQx\"
int startBodyBytes = json_message.find("bodyBytes") + std::string("\"bodyBytes\": \"").size() - 2;
int endCur = json_message.find_first_of('\"', startBodyBytes + 2) + 1;
json_message.replace(startBodyBytes, endCur - startBodyBytes, json_message_body);
//printf("json: %s\n", json_message.data());
return json_message;
}
/// TASK ////////////////////////

View File

@ -59,6 +59,9 @@ namespace model {
bool needSomeoneToSign(Poco::AutoPtr<controller::User> user);
protected:
std::string getTransactionAsJson();
Poco::AutoPtr<TransactionBody> mTransactionBody;
proto::gradido::GradidoTransaction mProtoTransaction;
HASH mBodyBytesHash;