mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
split runSendTransaction in Hedera and Mysql Version
use a much shorter version for runSendTransactionMysql as initially in SigningTransaction was used
This commit is contained in:
parent
3cffee31ce
commit
13cfbb32ec
@ -11,6 +11,7 @@
|
||||
|
||||
#include "../lib/DataTypeConverter.h"
|
||||
#include "../lib/Profiler.h"
|
||||
#include "../lib/JsonRequest.h"
|
||||
|
||||
#include "../hedera/Transaction.h"
|
||||
#include "../hedera/TransactionId.h"
|
||||
@ -613,6 +614,21 @@ namespace model {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mTransactionBody->isHederaBlockchain()) {
|
||||
return runSendTransactionHedera();
|
||||
}
|
||||
else if (mTransactionBody->isMysqlBlockchain()) {
|
||||
return runSendTransactionMysql();
|
||||
}
|
||||
addError(new ParamError(function_name, "not implemented blockchain type", mTransactionBody->getBlockchainTypeString()));
|
||||
return -10;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int Transaction::runSendTransactionHedera()
|
||||
{
|
||||
static const char* function_name = "Transaction::runSendTransactionHedera";
|
||||
// send transaction via hedera
|
||||
auto network_type = ServerConfig::g_HederaNetworkType;
|
||||
// TODO: get correct topic id for user group
|
||||
@ -641,27 +657,15 @@ namespace model {
|
||||
std::string base64_message = DataTypeConverter::binToBase64((const unsigned char*)raw_message.data(), raw_message.size(), sodium_base64_VARIANT_URLSAFE_NO_PADDING);
|
||||
if (json_message != "")
|
||||
{
|
||||
FILE* f = fopen("transactions_log.txt", "at");
|
||||
if (f) {
|
||||
fwrite(dateTimeString.data(), sizeof(char), dateTimeString.size(), f);
|
||||
fwrite(json_message.data(), sizeof(char), json_message.size(), f);
|
||||
fclose(f);
|
||||
}
|
||||
else {
|
||||
printf("[%s] cannot open transactions_log.txt\n", function_name);
|
||||
}
|
||||
Poco::Logger& transactions_log = Poco::Logger::get("transactions_log");
|
||||
transactions_log.information(dateTimeString);
|
||||
transactions_log.information(json_message);
|
||||
}
|
||||
if (base64_message != "")
|
||||
{
|
||||
FILE* f2 = fopen("transaction_log_base64.txt", "at");
|
||||
if (f2) {
|
||||
fwrite(dateTimeString.data(), sizeof(char), dateTimeString.size(), f2);
|
||||
fwrite(base64_message.data(), sizeof(char), base64_message.size(), f2);
|
||||
fclose(f2);
|
||||
}
|
||||
else {
|
||||
printf("[%s] cannot open transaction_log_base64.txt\n", function_name);
|
||||
}
|
||||
Poco::Logger& transaction_log_base64 = Poco::Logger::get("transactions_log_base64");
|
||||
transaction_log_base64.information(dateTimeString);
|
||||
transaction_log_base64.information(base64_message);
|
||||
}
|
||||
}
|
||||
else if (ServerConfig::HEDERA_CONSENSUS_FORMAT_BASE64_URLSAVE_NO_PADDING == ServerConfig::g_ConsensusMessageFormat) {
|
||||
@ -707,9 +711,14 @@ namespace model {
|
||||
auto precheck_code = hedera_transaction_response->getPrecheckCode();
|
||||
auto cost = hedera_transaction_response->getCost();
|
||||
|
||||
printf("hedera response: %s, cost: %" PRIu64 ", type: %s\n",
|
||||
// for showing in docker
|
||||
std::clog << "hedera response: " << hedera_precheck_code_string
|
||||
<< ", cost: " << cost
|
||||
<< ", type: " << TransactionBody::transactionTypeToString(mTransactionBody->getType())
|
||||
<< std::endl;
|
||||
/*printf("hedera response: %s, cost: %" PRIu64 ", type: %s\n",
|
||||
hedera_precheck_code_string.data(), cost,
|
||||
TransactionBody::transactionTypeToString(mTransactionBody->getType()));
|
||||
TransactionBody::transactionTypeToString(mTransactionBody->getType()));*/
|
||||
if (precheck_code == proto::INVALID_TRANSACTION_START) {
|
||||
int zahl = 0;
|
||||
return -5;
|
||||
@ -754,8 +763,50 @@ namespace model {
|
||||
return -4;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
int Transaction::runSendTransactionMysql()
|
||||
{
|
||||
static const char* function_name = "Transaction::runSendTransactionMysql";
|
||||
auto mm = MemoryManager::getInstance();
|
||||
std::string raw_message = mProtoTransaction.SerializeAsString();
|
||||
if (raw_message == "") {
|
||||
addError(new Error("SigningTransaction", "error serializing final transaction"));
|
||||
return -6;
|
||||
}
|
||||
|
||||
// finale to base64
|
||||
auto base_64_message = DataTypeConverter::binToBase64(raw_message, sodium_base64_VARIANT_URLSAFE_NO_PADDING);
|
||||
|
||||
if (base_64_message == "") {
|
||||
addError(new Error(function_name, "error convert final transaction to base64"));
|
||||
return -7;
|
||||
}
|
||||
|
||||
|
||||
// create json request
|
||||
auto user = getUser();
|
||||
if (user.isNull()) {
|
||||
addError(new Error(function_name, "user is zero"));
|
||||
return -8;
|
||||
}
|
||||
auto group = user->getGroup();
|
||||
if (group.isNull()) {
|
||||
addError(new Error(function_name, "group is zero"));
|
||||
return -9;
|
||||
}
|
||||
auto json_request = group->createJsonRequest();
|
||||
|
||||
Poco::Net::NameValueCollection param;
|
||||
param.set("transaction", base_64_message);
|
||||
auto result = json_request.request("putTransaction", param);
|
||||
if (JSON_REQUEST_RETURN_OK == result) {
|
||||
return 1;
|
||||
}
|
||||
getErrors(&json_request);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string Transaction::getTransactionAsJson(bool replaceBase64WithHex/* = false*/)
|
||||
@ -844,6 +895,9 @@ namespace model {
|
||||
model->setResultJson(errors);
|
||||
model->updateFinishedAndResult();
|
||||
}
|
||||
if (result < -1) {
|
||||
mTransaction->sendErrorsAsEmail();
|
||||
}
|
||||
// delete because succeed, maybe change later
|
||||
if (1 == result) {
|
||||
//mTransaction->deleteFromDB();
|
||||
|
||||
@ -90,6 +90,10 @@ namespace model {
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
int runSendTransactionHedera();
|
||||
int runSendTransactionMysql();
|
||||
|
||||
Poco::AutoPtr<Transaction> mPairedTransaction;
|
||||
|
||||
Poco::AutoPtr<TransactionBody> mTransactionBody;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user