mirror of
https://github.com/IT4Change/gradido.git
synced 2026-01-20 20:01:31 +00:00
update pending task save and load param and result
also: - fix base64ToBin using strlen instead of encodedSize len (by encodedSize php decoder failed) - insertIntoDB remove async, return also by second attempt true if succed, else false
This commit is contained in:
parent
a9975d4bac
commit
5974473276
@ -169,13 +169,39 @@ namespace controller {
|
||||
return true;
|
||||
}
|
||||
|
||||
void PendingTask::finishSuccess()
|
||||
{
|
||||
getModel()->setFinished(Poco::DateTime());
|
||||
setResult("state", "success", true);
|
||||
}
|
||||
|
||||
bool PendingTask::setResult(const std::string& key, const Poco::Dynamic::Var& value, bool saveIntoDB /*= false*/)
|
||||
{
|
||||
auto model = getModel();
|
||||
auto param = model->getResultJson();
|
||||
param->set(key, value);
|
||||
model->setResultJson(param);
|
||||
if (saveIntoDB) {
|
||||
return model->updateFinishedAndResult();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int PendingTask::getIntParam(const std::string& key)
|
||||
{
|
||||
auto model = getModel();
|
||||
auto param = model->getParamJson();
|
||||
auto paramVar = param->get(key);
|
||||
if (!paramVar.isEmpty() && paramVar.isInteger()) {
|
||||
return paramVar.extract<int>();
|
||||
try {
|
||||
return paramVar.extract<Poco::Int64>();
|
||||
}
|
||||
catch (Poco::Exception& ex) {
|
||||
NotificationList error;
|
||||
error.addError(new ParamError("PendingTask::getIntParam", "poco exception: ", ex.displayText()));
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -44,6 +44,9 @@ namespace controller {
|
||||
|
||||
Poco::AutoPtr<controller::User> getUser();
|
||||
|
||||
void finishSuccess();
|
||||
|
||||
bool setResult(const std::string& key, const Poco::Dynamic::Var& value, bool saveIntoDB = false);
|
||||
bool setParam(const std::string& key, const Poco::Dynamic::Var& value, bool saveIntoDB = false);
|
||||
int getIntParam(const std::string& key);
|
||||
|
||||
|
||||
@ -209,14 +209,12 @@ namespace DataTypeConverter
|
||||
auto base64 = mm->getFreeMemory(encodedSize);
|
||||
memset(*base64, 0, encodedSize);
|
||||
|
||||
size_t resultBinSize = 0;
|
||||
|
||||
if (nullptr == sodium_bin2base64(*base64, encodedSize, data, size, variant)) {
|
||||
mm->releaseMemory(base64);
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string base64String((const char*)*base64, encodedSize);
|
||||
std::string base64String((const char*)*base64);
|
||||
mm->releaseMemory(base64);
|
||||
return base64String;
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ namespace model {
|
||||
}
|
||||
mTransactionBody = TransactionBody::load(mProtoTransaction.body_bytes());
|
||||
auto blockchain_type = getIntParam("blockchain_type");
|
||||
if (blockchain_type >= 0) {
|
||||
if (blockchain_type > 0) {
|
||||
mTransactionBody->setBlockchainType((BlockchainType)blockchain_type);
|
||||
}
|
||||
auto body_bytes = mTransactionBody->getBodyBytes();
|
||||
@ -101,19 +101,24 @@ namespace model {
|
||||
}
|
||||
auto network_type = ServerConfig::g_HederaNetworkType;
|
||||
auto receiver_model = receiver->getModel();
|
||||
auto topic_id = controller::HederaId::find(receiver_model->getGroupId(), network_type);
|
||||
|
||||
if (topic_id.isNull()) {
|
||||
em->addError(new ParamError(function_name, "could'n find topic for group: ", receiver_model->getGroupId()));
|
||||
em->addError(new ParamError(function_name, "network type: ", network_type));
|
||||
em->sendErrorsAsEmail();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto body = TransactionBody::create(memo, receiver, amount, targetDate, blockchainType);
|
||||
Poco::AutoPtr<Transaction> result = new Transaction(body);
|
||||
result->setParam("blockchain_type", blockchainType);
|
||||
|
||||
result->setParam("blockchain_type", (int)blockchainType);
|
||||
auto model = result->getModel();
|
||||
model->setHederaId(topic_id->getModel()->getID());
|
||||
if (blockchainType == BLOCKCHAIN_HEDERA) {
|
||||
auto topic_id = controller::HederaId::find(receiver_model->getGroupId(), network_type);
|
||||
|
||||
if (topic_id.isNull()) {
|
||||
em->addError(new ParamError(function_name, "could'n find topic for group: ", receiver_model->getGroupId()));
|
||||
em->addError(new ParamError(function_name, "network type: ", network_type));
|
||||
em->sendErrorsAsEmail();
|
||||
return nullptr;
|
||||
}
|
||||
model->setHederaId(topic_id->getModel()->getID());
|
||||
}
|
||||
|
||||
result->insertPendingTaskIntoDB(receiver, model::table::TASK_TYPE_CREATION);
|
||||
PendingTasksManager::getInstance()->addTask(result);
|
||||
return result;
|
||||
@ -207,7 +212,7 @@ namespace model {
|
||||
|
||||
for (auto it = results.begin(); it != results.end(); it++) {
|
||||
if (!(*it)->getTransactionBody()->getTransferTransaction()->isInbound()) {
|
||||
(*it)->setParam("blockchain_type", blockchainType);
|
||||
(*it)->setParam("blockchain_type", (int)blockchainType);
|
||||
(*it)->insertPendingTaskIntoDB(sender, model::table::TASK_TYPE_TRANSFER);
|
||||
PendingTasksManager::getInstance()->addTask(*it);
|
||||
}
|
||||
@ -280,13 +285,6 @@ namespace model {
|
||||
//transaction_group = receiverGroup;
|
||||
//topic_group = sender_group;
|
||||
|
||||
auto topic_id = controller::HederaId::find(topic_group->getModel()->getID(), network_type);
|
||||
if (topic_id.isNull()) {
|
||||
em->addError(new ParamError(function_name, "could'n find topic for group: ", receiver_model->getGroupId()));
|
||||
em->addError(new ParamError(function_name, "network type: ", network_type));
|
||||
em->sendErrorsAsEmail();
|
||||
return result;
|
||||
}
|
||||
if (transaction_group.isNull()) {
|
||||
em->addError(new Error(function_name, "transaction group is zero, inbound"));
|
||||
em->sendErrorsAsEmail();
|
||||
@ -295,10 +293,17 @@ namespace model {
|
||||
|
||||
auto body = TransactionBody::create(memo, senderPubkey, receiver, amount, pairedTransactionId, transaction_group);
|
||||
result = new Transaction(body);
|
||||
result->getModel()->setHederaId(topic_id->getModel()->getID());
|
||||
|
||||
// }
|
||||
result->setParam("blockchain_type", blockchainType);
|
||||
if (blockchainType == BLOCKCHAIN_HEDERA) {
|
||||
auto topic_id = controller::HederaId::find(topic_group->getModel()->getID(), network_type);
|
||||
if (topic_id.isNull()) {
|
||||
em->addError(new ParamError(function_name, "could'n find topic for group: ", receiver_model->getGroupId()));
|
||||
em->addError(new ParamError(function_name, "network type: ", network_type));
|
||||
em->sendErrorsAsEmail();
|
||||
return result;
|
||||
}
|
||||
result->getModel()->setHederaId(topic_id->getModel()->getID());
|
||||
}
|
||||
result->setParam("blockchain_type", (int)blockchainType);
|
||||
result->insertPendingTaskIntoDB(receiver, model::table::TASK_TYPE_TRANSFER);
|
||||
PendingTasksManager::getInstance()->addTask(result);
|
||||
|
||||
@ -801,11 +806,14 @@ namespace model {
|
||||
param.set("transaction", base_64_message);
|
||||
auto result = json_request.request("putTransaction", param);
|
||||
if (JSON_REQUEST_RETURN_OK == result) {
|
||||
if (!json_request.errorCount()) {
|
||||
finishSuccess();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
getErrors(&json_request);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ namespace model {
|
||||
namespace gradido {
|
||||
|
||||
TransactionBody::TransactionBody()
|
||||
: mTransactionSpecific(nullptr), mType(TRANSACTION_NONE)
|
||||
: mTransactionSpecific(nullptr), mType(TRANSACTION_NONE), mBlockchainType(BLOCKCHAIN_NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@ -207,6 +207,7 @@ namespace model {
|
||||
*pubkey_str = std::string((const char*)receiver_model->getPublicKey(), receiver_model->getPublicKeySize());
|
||||
|
||||
obj->mType = TRANSACTION_CREATION;
|
||||
obj->mBlockchainType = blockchainType;
|
||||
obj->mTransactionSpecific = new TransactionCreation(memo, obj->mTransactionBody.creation());
|
||||
obj->mTransactionSpecific->prepare();
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@ namespace model {
|
||||
|
||||
enum BlockchainType
|
||||
{
|
||||
BLOCKCHAIN_NULL,
|
||||
BLOCKCHAIN_MYSQL,
|
||||
BLOCKCHAIN_HEDERA,
|
||||
BLOCKCHAIN_UNKNOWN
|
||||
|
||||
@ -54,12 +54,9 @@ namespace model {
|
||||
if (loadId) {
|
||||
Poco::Data::Statement select = _loadIdFromDB(session);
|
||||
try {
|
||||
select.executeAsync();
|
||||
auto result_count = select.wait();
|
||||
if (result_count != 1) {
|
||||
int zahl = 0;
|
||||
}
|
||||
return result_count;
|
||||
auto res = select.execute();
|
||||
if (1 == res) { return true; }
|
||||
|
||||
}
|
||||
catch (Poco::Exception& ex) {
|
||||
addError(new ParamError(getTableName(), "mysql error by select id", ex.displayText().data()));
|
||||
@ -68,7 +65,7 @@ namespace model {
|
||||
session = cm->getConnection(CONNECTION_MYSQL_LOGIN_SERVER);
|
||||
select = _loadIdFromDB(session);
|
||||
//Poco::Data::Statement select = _loadIdFromDB(session);
|
||||
select.execute();
|
||||
return 1 == select.execute();
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
|
||||
@ -10,12 +10,12 @@ namespace model
|
||||
namespace table
|
||||
{
|
||||
PendingTask::PendingTask()
|
||||
: mUserId(0), mTaskTypeId(TASK_TYPE_NONE)
|
||||
: mUserId(0), mHederaId(0), mTaskTypeId(TASK_TYPE_NONE)
|
||||
{
|
||||
|
||||
}
|
||||
PendingTask::PendingTask(int userId, std::string serializedProtoRequest, TaskType type)
|
||||
: mUserId(userId), mRequest((const unsigned char*)serializedProtoRequest.data(), serializedProtoRequest.size()),
|
||||
: mUserId(userId), mHederaId(0), mRequest((const unsigned char*)serializedProtoRequest.data(), serializedProtoRequest.size()),
|
||||
mTaskTypeId(TASK_TYPE_NONE)
|
||||
{
|
||||
|
||||
@ -50,8 +50,13 @@ namespace model
|
||||
{
|
||||
UNIQUE_LOCK;
|
||||
std::stringstream ss;
|
||||
param->stringify(ss);
|
||||
mResultJsonString = ss.str();
|
||||
try {
|
||||
param->stringify(ss);
|
||||
}
|
||||
catch (Poco::Exception& ex) {
|
||||
addError(new ParamError("PendingTask::setParamJson", "exception by json -> string", ex.displayText()));
|
||||
}
|
||||
mParamJsonString = ss.str();
|
||||
}
|
||||
|
||||
Poco::JSON::Object::Ptr PendingTask::getResultJson() const
|
||||
@ -91,7 +96,7 @@ namespace model
|
||||
}
|
||||
catch (Poco::JSON::JSONException& jsone)
|
||||
{
|
||||
return nullptr;
|
||||
return new Poco::JSON::Object;
|
||||
}
|
||||
|
||||
return result.extract<Poco::JSON::Object::Ptr>();
|
||||
@ -273,8 +278,8 @@ namespace model
|
||||
Poco::Data::Statement insert(session);
|
||||
|
||||
insert << "INSERT INTO " << getTableName()
|
||||
<< " (user_id, hedera_id, request, created, param_json, task_type_id, child_pending_task_id, parent_pending_task_id) VALUES(?,?,?,?,?,?,?,?)"
|
||||
, use(mUserId), use(mHederaId), use(mRequest), use(mCreated), use(mParamJsonString), use(mTaskTypeId), use(mChildPendingTaskId), use(mParentPendingTaskId);
|
||||
<< " (user_id, hedera_id, request, created, result_json, param_json, task_type_id, child_pending_task_id, parent_pending_task_id) VALUES(?,?,?,?,?,?,?,?,?)"
|
||||
, use(mUserId), use(mHederaId), use(mRequest), use(mCreated), use(mResultJsonString), use(mParamJsonString), use(mTaskTypeId), use(mChildPendingTaskId), use(mParentPendingTaskId);
|
||||
|
||||
return insert;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user