mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
update model::gradido::Transaction::createTransfer for using with blockchain mysql, update return type
update functions calling model::gradido::Transaction::createTransfer to handle on transaction as return instead of vector
This commit is contained in:
parent
f1ae457155
commit
31ac055c65
@ -657,8 +657,8 @@ void AdminNodeServerTestPage::handleRequest(Poco::Net::HTTPServerRequest& reques
|
||||
auto transaction4 = model::gradido::Transaction::createTransfer(user_2, user_1_pubkey, user_group, 5000000, "Test Transfer", model::gradido::BLOCKCHAIN_HEDERA);
|
||||
// wait before sending fourth transaction, gn seems to crash by more than 3 transaction at nearly the same time
|
||||
Poco::Thread::sleep(sleep_ms_between_transactions);
|
||||
transaction4[0]->sign(user_2);
|
||||
auto transaction4_json = transaction4[0]->getTransactionAsJson(true);
|
||||
transaction4->sign(user_2);
|
||||
auto transaction4_json = transaction4->getTransactionAsJson(true);
|
||||
responseStream << "\n";
|
||||
responseStream << "\t\t\t<p>";
|
||||
#line 321 "F:\\Gradido\\gradido_stage2_local\\login_server\\src\\cpsp\\adminNodeServerTest.cpsp"
|
||||
@ -714,7 +714,7 @@ void AdminNodeServerTestPage::handleRequest(Poco::Net::HTTPServerRequest& reques
|
||||
} else {
|
||||
auto user_3_pubkey = user_3->getModel()->getPublicKeyCopy();
|
||||
auto transaction6 = model::gradido::Transaction::createTransfer(user_2, user_3_pubkey, user_group2, 4000000, "Test Group Transfer", model::gradido::BLOCKCHAIN_HEDERA, false);
|
||||
if(!transaction6.size()) {
|
||||
if(transaction6.isNull()) {
|
||||
responseStream << "\n";
|
||||
responseStream << "\t\t\t\t<div class=\"alert alert-error\" role=\"alert\">\n";
|
||||
responseStream << "\t\t\t\t\t<i class=\"material-icons-outlined\">report_problem</i>\n";
|
||||
@ -725,9 +725,9 @@ void AdminNodeServerTestPage::handleRequest(Poco::Net::HTTPServerRequest& reques
|
||||
|
||||
} else {
|
||||
Poco::Thread::sleep(sleep_ms_between_transactions);
|
||||
transaction6[0]->sign(user_2);
|
||||
auto transaction6_json = transaction6[0]->getTransactionAsJson(true);
|
||||
auto paired_transaction = transaction6[0]->getPairedTransaction();
|
||||
transaction6->sign(user_2);
|
||||
auto transaction6_json = transaction6->getTransactionAsJson(true);
|
||||
auto paired_transaction = transaction6->getPairedTransaction();
|
||||
responseStream << "\n";
|
||||
responseStream << "\t\t\t\t\t<p>";
|
||||
#line 364 "F:\\Gradido\\gradido_stage2_local\\login_server\\src\\cpsp\\adminNodeServerTest.cpsp"
|
||||
|
||||
@ -122,15 +122,13 @@ Poco::JSON::Object* JsonCreateTransaction::transfer(Poco::Dynamic::Var params)
|
||||
}
|
||||
}
|
||||
if (!result) {
|
||||
auto transactions = model::gradido::Transaction::createTransfer(mSession->getNewUser(), target_pubkey, mTargetGroup, amount, mMemo, mBlockchainType);
|
||||
auto transaction = model::gradido::Transaction::createTransfer(mSession->getNewUser(), target_pubkey, mTargetGroup, amount, mMemo, mBlockchainType);
|
||||
|
||||
if (mAutoSign) {
|
||||
Poco::JSON::Array errors;
|
||||
for (auto it = transactions.begin(); it != transactions.end(); it++) {
|
||||
(*it)->sign(user);
|
||||
if ((*it)->errorCount() > 0) {
|
||||
errors.add((*it)->getErrorsArray());
|
||||
}
|
||||
transaction->sign(user);
|
||||
if (transaction->errorCount() > 0) {
|
||||
errors.add(transaction->getErrorsArray());
|
||||
}
|
||||
|
||||
if (errors.size() > 0) {
|
||||
|
||||
@ -124,7 +124,7 @@ namespace model {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<Poco::AutoPtr<Transaction>> Transaction::createTransfer(
|
||||
Poco::AutoPtr<Transaction> Transaction::createTransfer(
|
||||
Poco::AutoPtr<controller::User> sender,
|
||||
const MemoryBin* receiverPubkey,
|
||||
Poco::AutoPtr<controller::Group> receiverGroup,
|
||||
@ -134,31 +134,42 @@ namespace model {
|
||||
bool inbound/* = true*/
|
||||
)
|
||||
{
|
||||
std::vector<Poco::AutoPtr<Transaction>> results;
|
||||
Poco::AutoPtr<Transaction> transaction;
|
||||
Poco::AutoPtr<TransactionBody> transaction_body;
|
||||
Poco::AutoPtr<controller::HederaId> topic_id;
|
||||
auto em = ErrorManager::getInstance();
|
||||
static const char* function_name = "Transaction::create transfer";
|
||||
|
||||
if (sender.isNull() || !sender->getModel() || !receiverPubkey || !amount) {
|
||||
return results;
|
||||
return transaction;
|
||||
}
|
||||
|
||||
//std::vector<Poco::AutoPtr<TransactionBody>> bodys;
|
||||
auto sender_model = sender->getModel();
|
||||
|
||||
|
||||
if (blockchainType == BLOCKCHAIN_MYSQL) {
|
||||
transaction_body = TransactionBody::create(memo, sender, receiverPubkey, amount, blockchainType);
|
||||
transaction = new Transaction(transaction_body);
|
||||
}
|
||||
else if (blockchainType == BLOCKCHAIN_HEDERA)
|
||||
{
|
||||
auto network_type = ServerConfig::g_HederaNetworkType;
|
||||
|
||||
|
||||
// LOCAL Transfer
|
||||
if (receiverGroup.isNull() || sender_model->getGroupId() == receiverGroup->getModel()->getID())
|
||||
{
|
||||
auto body = TransactionBody::create(memo, sender, receiverPubkey, amount, blockchainType);
|
||||
Poco::AutoPtr<Transaction> transaction = new Transaction(body);
|
||||
auto topic_id = controller::HederaId::find(sender_model->getGroupId(), network_type);
|
||||
if (topic_id.isNull()) {
|
||||
topic_id = controller::HederaId::find(sender_model->getGroupId(), network_type);
|
||||
|
||||
if (topic_id.isNull())
|
||||
{
|
||||
em->addError(new ParamError(function_name, "could'n find topic for group: ", sender_model->getGroupId()));
|
||||
em->addError(new ParamError(function_name, "network type: ", network_type));
|
||||
em->sendErrorsAsEmail();
|
||||
return results;
|
||||
return transaction;
|
||||
}
|
||||
transaction->getModel()->setHederaId(topic_id->getModel()->getID());
|
||||
results.push_back(transaction);
|
||||
transaction_body = TransactionBody::create(memo, sender, receiverPubkey, amount, blockchainType);
|
||||
transaction = new Transaction(transaction_body);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -167,7 +178,7 @@ namespace model {
|
||||
{
|
||||
em->addError(new ParamError(function_name, "couldn't find group with id: ", sender_model->getGroupId()));
|
||||
em->sendErrorsAsEmail();
|
||||
return results;
|
||||
return transaction;
|
||||
}
|
||||
Poco::AutoPtr<controller::Group> transaction_group;
|
||||
Poco::AutoPtr<controller::Group> topic_group;
|
||||
@ -189,38 +200,32 @@ namespace model {
|
||||
em->addError(new ParamError(function_name, "could'n find topic for group: ", sender_model->getGroupId()));
|
||||
em->addError(new ParamError(function_name, "network type: ", network_type));
|
||||
em->sendErrorsAsEmail();
|
||||
return results;
|
||||
return transaction;
|
||||
}
|
||||
if (transaction_group.isNull()) {
|
||||
em->addError(new ParamError(function_name, "transaction group is zero, inbound", inbound));
|
||||
em->sendErrorsAsEmail();
|
||||
return results;
|
||||
return transaction;
|
||||
}
|
||||
|
||||
auto body = TransactionBody::create(memo, sender, receiverPubkey, amount, blockchainType, pairedTransactionId, transaction_group);
|
||||
Poco::AutoPtr<Transaction> transaction = new Transaction(body);
|
||||
transaction->getModel()->setHederaId(topic_id->getModel()->getID());
|
||||
|
||||
auto transfer_transaction = transaction->getTransactionBody()->getTransferTransaction();
|
||||
transfer_transaction->setOwnGroupAlias(sender_group->getModel()->getAlias());
|
||||
transfer_transaction->setTargetGroupAlias(receiverGroup->getModel()->getAlias());
|
||||
|
||||
results.push_back(transaction);
|
||||
// }
|
||||
}
|
||||
auto transaction_model = transaction->getModel();
|
||||
transaction_model->setHederaId(topic_id->getModel()->getID());
|
||||
|
||||
}
|
||||
|
||||
transaction->setParam("blockchain_type", (int)blockchainType);
|
||||
transaction->insertPendingTaskIntoDB(sender, model::table::TASK_TYPE_TRANSFER);
|
||||
PendingTasksManager::getInstance()->addTask(transaction);
|
||||
|
||||
for (auto it = results.begin(); it != results.end(); it++) {
|
||||
if (!(*it)->getTransactionBody()->getTransferTransaction()->isInbound()) {
|
||||
(*it)->setParam("blockchain_type", (int)blockchainType);
|
||||
(*it)->insertPendingTaskIntoDB(sender, model::table::TASK_TYPE_TRANSFER);
|
||||
PendingTasksManager::getInstance()->addTask(*it);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return results;
|
||||
|
||||
return transaction;
|
||||
}
|
||||
|
||||
bool Transaction::setTopicIdByGroup(const std::string& alias)
|
||||
@ -326,7 +331,7 @@ namespace model {
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
// try not finished but sign transactions again
|
||||
// try not finished but signed transactions again
|
||||
if (!finished) {
|
||||
transaction->ifEnoughSignsProceed(nullptr);
|
||||
}
|
||||
|
||||
@ -32,8 +32,8 @@ namespace model {
|
||||
// groupMemberUpdate
|
||||
static Poco::AutoPtr<Transaction> createGroupMemberUpdate(Poco::AutoPtr<controller::User> user, Poco::AutoPtr<controller::Group> group);
|
||||
//! \brief transfer
|
||||
//! \return for cross group transaction return two transactions
|
||||
static std::vector<Poco::AutoPtr<Transaction>> createTransfer(
|
||||
//! \return
|
||||
static Poco::AutoPtr<Transaction> createTransfer(
|
||||
Poco::AutoPtr<controller::User> sender,
|
||||
const MemoryBin* receiverPubkey,
|
||||
Poco::AutoPtr<controller::Group> receiverGroup,
|
||||
|
||||
@ -315,8 +315,8 @@ enum PageType
|
||||
auto transaction4 = model::gradido::Transaction::createTransfer(user_2, user_1_pubkey, user_group, 5000000, "Test Transfer", model::gradido::BLOCKCHAIN_HEDERA);
|
||||
// wait before sending fourth transaction, gn seems to crash by more than 3 transaction at nearly the same time
|
||||
Poco::Thread::sleep(sleep_ms_between_transactions);
|
||||
transaction4[0]->sign(user_2);
|
||||
auto transaction4_json = transaction4[0]->getTransactionAsJson(true);
|
||||
transaction4->sign(user_2);
|
||||
auto transaction4_json = transaction4->getTransactionAsJson(true);
|
||||
%>
|
||||
<p><%= DataTypeConverter::replaceNewLineWithBr(transaction4_json) %></p>
|
||||
<% } %>
|
||||
@ -348,7 +348,7 @@ enum PageType
|
||||
<% } else {
|
||||
auto user_3_pubkey = user_3->getModel()->getPublicKeyCopy();
|
||||
auto transaction6 = model::gradido::Transaction::createTransfer(user_2, user_3_pubkey, user_group2, 4000000, "Test Group Transfer", model::gradido::BLOCKCHAIN_HEDERA, false);
|
||||
if(!transaction6.size()) {
|
||||
if(transaction6.isNull()) {
|
||||
%>
|
||||
<div class="alert alert-error" role="alert">
|
||||
<i class="material-icons-outlined">report_problem</i>
|
||||
@ -357,9 +357,9 @@ enum PageType
|
||||
<%
|
||||
} else {
|
||||
Poco::Thread::sleep(sleep_ms_between_transactions);
|
||||
transaction6[0]->sign(user_2);
|
||||
auto transaction6_json = transaction6[0]->getTransactionAsJson(true);
|
||||
auto paired_transaction = transaction6[0]->getPairedTransaction();
|
||||
transaction6->sign(user_2);
|
||||
auto transaction6_json = transaction6->getTransactionAsJson(true);
|
||||
auto paired_transaction = transaction6->getPairedTransaction();
|
||||
%>
|
||||
<p><%= DataTypeConverter::replaceNewLineWithBr(transaction6_json) %></p>
|
||||
<% if(!paired_transaction.isNull()) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user