update notifications to also have copy errors to email, instead of move, update protocol, run transactions with enough signatures and without result on startup from pending_tasks table

This commit is contained in:
einhornimmond 2021-04-09 20:11:24 +02:00
parent c5e849c79d
commit 9e049d8477
9 changed files with 51 additions and 13 deletions

View File

@ -332,6 +332,7 @@ namespace DataTypeConverter
return microseconds;
}
Poco::Timespan convertFromProtoDuration(const proto::Duration& duration)
{
return Poco::Timespan(duration.seconds(), 0);

View File

@ -63,6 +63,9 @@ namespace DataTypeConverter {
void convertToProtoTimestamp(const Poco::Timestamp pocoTimestamp, proto::Timestamp* protoTimestamp);
void convertToProtoTimestamp(const Poco::Timestamp pocoTimestamp, proto::gradido::Timestamp* protoTimestamp);
Poco::Timestamp convertFromProtoTimestampSeconds(const proto::gradido::TimestampSeconds& timestampSeconds);
inline void convertToProtoTimestampSeconds(const Poco::Timestamp pocoTimestamp, proto::gradido::TimestampSeconds* protoTimestampSeconds) {
protoTimestampSeconds->set_seconds(pocoTimestamp.epochTime());
}
Poco::Timespan convertFromProtoDuration(const proto::Duration& duration);
//! \brief go through json object and replace every string entry in base64 format into hex format

View File

@ -236,7 +236,8 @@ JsonRequestReturn JsonRequest::requestGRPCRelay(const Poco::Net::NameValueCollec
if (!object.isNull("details")) {
addError(new ParamError(functionName, "details:", object.get("details").convert<std::string>().data()));
}
sendErrorsAsEmail();
// send copy of errors as email, to have result also in db
sendErrorsAsEmail("", true);
return JSON_REQUEST_RETURN_ERROR;
}
ss.clear();

View File

@ -184,7 +184,7 @@ std::string NotificationList::getErrorsHtmlNewFormat()
*/
void NotificationList::sendErrorsAsEmail(std::string rawHtml/* = ""*/)
void NotificationList::sendErrorsAsEmail(std::string rawHtml/* = ""*/, bool copy/* = false*/)
{
auto em = EmailManager::getInstance();
/*auto message = new Poco::Net::MailMessage();
@ -193,12 +193,22 @@ void NotificationList::sendErrorsAsEmail(std::string rawHtml/* = ""*/)
message->setSubject("Error from Gradido Login Server");
*/
std::string content;
std::stack<Notification*> stack_copy;
if (copy) {
stack_copy = mErrorStack;
}
while (mErrorStack.size() > 0) {
auto error = mErrorStack.top();
mErrorStack.pop();
content += error->getString();
delete error;
if (!copy) {
delete error;
}
}
if (copy) {
mErrorStack = std::move(stack_copy);
}
auto email = new model::Email(content, model::EMAIL_ERROR);
//message->addContent(new Poco::Net::StringPartSource(content));

View File

@ -47,7 +47,7 @@ public:
std::string getErrorsHtmlNewFormat();
std::vector<std::string> getErrorsArray();
void sendErrorsAsEmail(std::string rawHtml = "");
void sendErrorsAsEmail(std::string rawHtml = "", bool copy = false);
protected:
std::stack<Notification*> mErrorStack;

View File

@ -317,6 +317,20 @@ namespace model {
Poco::AutoPtr<Transaction> transaction = new Transaction(dbModel->getRequestCopy(), dbModel);
PendingTasksManager::getInstance()->addTask(transaction);
// check if transaction was already finished
auto json = transaction->getModel()->getResultJson();
bool finished = false;
if (!json.isNull()) {
if (!json->get("state").isEmpty()) {
finished = true;
}
}
// try not finished but sign transactions again
if (!finished) {
transaction->ifEnoughSignsProceed(nullptr);
}
return transaction;
}
@ -438,10 +452,16 @@ namespace model {
mm->releaseMemory(sign);
updateRequestInDB();
return ifEnoughSignsProceed(user);
}
bool Transaction::ifEnoughSignsProceed(Poco::AutoPtr<controller::User> user)
{
// check if enough signatures exist for next step
if (getSignCount() >= mTransactionBody->getTransactionBase()->getMinSignatureCount())
{
if (getTransactionBody()->isTransfer()) {
if (getTransactionBody()->isTransfer() && !user.isNull()) {
auto transfer = getTransactionBody()->getTransferTransaction();
if (transfer->isOutbound()) {
auto transaction = transfer->createInbound(getTransactionBody()->getMemo());
@ -453,19 +473,17 @@ namespace model {
//Poco::Thread::sleep(1000);
}
else {
addError(new Error(function_name, "Error creating outbound transaction"));
addError(new Error("Transaction::ifEnoughSignsProceed", "Error creating outbound transaction"));
return false;
}
}
}
UniLib::controller::TaskPtr transaction_send_task(new SendTransactionTask(Poco::AutoPtr<Transaction>(this, true)));
transaction_send_task->scheduleTask(transaction_send_task);
return true;
}
//getModel()->updateIntoDB("request", )
//printf("[Transaction::sign] reference-count: %d\n", mReferenceCount);
return true;
return false;
}
bool Transaction::updateRequestInDB()
@ -814,7 +832,7 @@ namespace model {
getErrors(&json_request);
return 0;
return -1;
}
std::string Transaction::getTransactionAsJson(bool replaceBase64WithHex/* = false*/)
@ -910,6 +928,7 @@ namespace model {
if (1 == result) {
//mTransaction->deleteFromDB();
}
return 0;
}

View File

@ -91,6 +91,8 @@ namespace model {
protected:
bool ifEnoughSignsProceed(Poco::AutoPtr<controller::User> user);
int runSendTransactionHedera();
int runSendTransactionMysql();

View File

@ -7,6 +7,8 @@ namespace model {
TransactionBody::TransactionBody()
: mTransactionSpecific(nullptr), mType(TRANSACTION_NONE), mBlockchainType(BLOCKCHAIN_NULL)
{
auto created = mTransactionBody.mutable_created();
DataTypeConverter::convertToProtoTimestampSeconds(Poco::Timestamp(), created);
}
TransactionBody::~TransactionBody()

@ -1 +1 @@
Subproject commit ff412f735667b30233c0ce00d461f209ac7dde7c
Subproject commit 77dee5685ebba543ea1cd2321580ad56c92f5775