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);
|
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
|
// 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);
|
Poco::Thread::sleep(sleep_ms_between_transactions);
|
||||||
transaction4[0]->sign(user_2);
|
transaction4->sign(user_2);
|
||||||
auto transaction4_json = transaction4[0]->getTransactionAsJson(true);
|
auto transaction4_json = transaction4->getTransactionAsJson(true);
|
||||||
responseStream << "\n";
|
responseStream << "\n";
|
||||||
responseStream << "\t\t\t<p>";
|
responseStream << "\t\t\t<p>";
|
||||||
#line 321 "F:\\Gradido\\gradido_stage2_local\\login_server\\src\\cpsp\\adminNodeServerTest.cpsp"
|
#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 {
|
} else {
|
||||||
auto user_3_pubkey = user_3->getModel()->getPublicKeyCopy();
|
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);
|
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 << "\n";
|
||||||
responseStream << "\t\t\t\t<div class=\"alert alert-error\" role=\"alert\">\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";
|
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 {
|
} else {
|
||||||
Poco::Thread::sleep(sleep_ms_between_transactions);
|
Poco::Thread::sleep(sleep_ms_between_transactions);
|
||||||
transaction6[0]->sign(user_2);
|
transaction6->sign(user_2);
|
||||||
auto transaction6_json = transaction6[0]->getTransactionAsJson(true);
|
auto transaction6_json = transaction6->getTransactionAsJson(true);
|
||||||
auto paired_transaction = transaction6[0]->getPairedTransaction();
|
auto paired_transaction = transaction6->getPairedTransaction();
|
||||||
responseStream << "\n";
|
responseStream << "\n";
|
||||||
responseStream << "\t\t\t\t\t<p>";
|
responseStream << "\t\t\t\t\t<p>";
|
||||||
#line 364 "F:\\Gradido\\gradido_stage2_local\\login_server\\src\\cpsp\\adminNodeServerTest.cpsp"
|
#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) {
|
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) {
|
if (mAutoSign) {
|
||||||
Poco::JSON::Array errors;
|
Poco::JSON::Array errors;
|
||||||
for (auto it = transactions.begin(); it != transactions.end(); it++) {
|
transaction->sign(user);
|
||||||
(*it)->sign(user);
|
if (transaction->errorCount() > 0) {
|
||||||
if ((*it)->errorCount() > 0) {
|
errors.add(transaction->getErrorsArray());
|
||||||
errors.add((*it)->getErrorsArray());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errors.size() > 0) {
|
if (errors.size() > 0) {
|
||||||
|
|||||||
@ -124,7 +124,7 @@ namespace model {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Poco::AutoPtr<Transaction>> Transaction::createTransfer(
|
Poco::AutoPtr<Transaction> Transaction::createTransfer(
|
||||||
Poco::AutoPtr<controller::User> sender,
|
Poco::AutoPtr<controller::User> sender,
|
||||||
const MemoryBin* receiverPubkey,
|
const MemoryBin* receiverPubkey,
|
||||||
Poco::AutoPtr<controller::Group> receiverGroup,
|
Poco::AutoPtr<controller::Group> receiverGroup,
|
||||||
@ -134,53 +134,64 @@ namespace model {
|
|||||||
bool inbound/* = true*/
|
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();
|
auto em = ErrorManager::getInstance();
|
||||||
static const char* function_name = "Transaction::create transfer";
|
static const char* function_name = "Transaction::create transfer";
|
||||||
|
|
||||||
if (sender.isNull() || !sender->getModel() || !receiverPubkey || !amount) {
|
if (sender.isNull() || !sender->getModel() || !receiverPubkey || !amount) {
|
||||||
return results;
|
return transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
//std::vector<Poco::AutoPtr<TransactionBody>> bodys;
|
|
||||||
auto sender_model = sender->getModel();
|
auto sender_model = sender->getModel();
|
||||||
auto network_type = ServerConfig::g_HederaNetworkType;
|
|
||||||
// LOCAL Transfer
|
|
||||||
if (receiverGroup.isNull() || sender_model->getGroupId() == receiverGroup->getModel()->getID())
|
if (blockchainType == BLOCKCHAIN_MYSQL) {
|
||||||
{
|
transaction_body = TransactionBody::create(memo, sender, receiverPubkey, amount, blockchainType);
|
||||||
auto body = TransactionBody::create(memo, sender, receiverPubkey, amount, blockchainType);
|
transaction = new Transaction(transaction_body);
|
||||||
Poco::AutoPtr<Transaction> transaction = new Transaction(body);
|
|
||||||
auto 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;
|
|
||||||
}
|
|
||||||
transaction->getModel()->setHederaId(topic_id->getModel()->getID());
|
|
||||||
results.push_back(transaction);
|
|
||||||
}
|
}
|
||||||
else
|
else if (blockchainType == BLOCKCHAIN_HEDERA)
|
||||||
{
|
{
|
||||||
auto sender_group = controller::Group::load(sender_model->getGroupId());
|
auto network_type = ServerConfig::g_HederaNetworkType;
|
||||||
if (sender_group.isNull())
|
|
||||||
|
|
||||||
|
// LOCAL Transfer
|
||||||
|
if (receiverGroup.isNull() || sender_model->getGroupId() == receiverGroup->getModel()->getID())
|
||||||
{
|
{
|
||||||
em->addError(new ParamError(function_name, "couldn't find group with id: ", sender_model->getGroupId()));
|
topic_id = controller::HederaId::find(sender_model->getGroupId(), network_type);
|
||||||
em->sendErrorsAsEmail();
|
|
||||||
return results;
|
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 transaction;
|
||||||
|
}
|
||||||
|
transaction_body = TransactionBody::create(memo, sender, receiverPubkey, amount, blockchainType);
|
||||||
|
transaction = new Transaction(transaction_body);
|
||||||
}
|
}
|
||||||
Poco::AutoPtr<controller::Group> transaction_group;
|
else
|
||||||
Poco::AutoPtr<controller::Group> topic_group;
|
{
|
||||||
// default constructor set it to now
|
auto sender_group = controller::Group::load(sender_model->getGroupId());
|
||||||
Poco::Timestamp pairedTransactionId;
|
if (sender_group.isNull())
|
||||||
// create only inbound transaction, and outbound before sending to hedera
|
{
|
||||||
//for (int i = 0; i < 1; i++) {
|
em->addError(new ParamError(function_name, "couldn't find group with id: ", sender_model->getGroupId()));
|
||||||
|
em->sendErrorsAsEmail();
|
||||||
|
return transaction;
|
||||||
|
}
|
||||||
|
Poco::AutoPtr<controller::Group> transaction_group;
|
||||||
|
Poco::AutoPtr<controller::Group> topic_group;
|
||||||
|
// default constructor set it to now
|
||||||
|
Poco::Timestamp pairedTransactionId;
|
||||||
|
// create only inbound transaction, and outbound before sending to hedera
|
||||||
|
//for (int i = 0; i < 1; i++) {
|
||||||
if (!inbound) {
|
if (!inbound) {
|
||||||
transaction_group = receiverGroup;
|
transaction_group = receiverGroup;
|
||||||
topic_group = sender_group;
|
topic_group = sender_group;
|
||||||
}
|
}
|
||||||
// transaction send to receiver blockchain
|
// transaction send to receiver blockchain
|
||||||
else if(inbound) {
|
else if (inbound) {
|
||||||
transaction_group = sender_group;
|
transaction_group = sender_group;
|
||||||
topic_group = receiverGroup;
|
topic_group = receiverGroup;
|
||||||
}
|
}
|
||||||
@ -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, "could'n find topic for group: ", sender_model->getGroupId()));
|
||||||
em->addError(new ParamError(function_name, "network type: ", network_type));
|
em->addError(new ParamError(function_name, "network type: ", network_type));
|
||||||
em->sendErrorsAsEmail();
|
em->sendErrorsAsEmail();
|
||||||
return results;
|
return transaction;
|
||||||
}
|
}
|
||||||
if (transaction_group.isNull()) {
|
if (transaction_group.isNull()) {
|
||||||
em->addError(new ParamError(function_name, "transaction group is zero, inbound", inbound));
|
em->addError(new ParamError(function_name, "transaction group is zero, inbound", inbound));
|
||||||
em->sendErrorsAsEmail();
|
em->sendErrorsAsEmail();
|
||||||
return results;
|
return transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto body = TransactionBody::create(memo, sender, receiverPubkey, amount, blockchainType, pairedTransactionId, transaction_group);
|
auto body = TransactionBody::create(memo, sender, receiverPubkey, amount, blockchainType, pairedTransactionId, transaction_group);
|
||||||
Poco::AutoPtr<Transaction> transaction = new Transaction(body);
|
Poco::AutoPtr<Transaction> transaction = new Transaction(body);
|
||||||
transaction->getModel()->setHederaId(topic_id->getModel()->getID());
|
|
||||||
|
|
||||||
auto transfer_transaction = transaction->getTransactionBody()->getTransferTransaction();
|
auto transfer_transaction = transaction->getTransactionBody()->getTransferTransaction();
|
||||||
transfer_transaction->setOwnGroupAlias(sender_group->getModel()->getAlias());
|
transfer_transaction->setOwnGroupAlias(sender_group->getModel()->getAlias());
|
||||||
transfer_transaction->setTargetGroupAlias(receiverGroup->getModel()->getAlias());
|
transfer_transaction->setTargetGroupAlias(receiverGroup->getModel()->getAlias());
|
||||||
|
|
||||||
results.push_back(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);
|
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
|
|
||||||
return results;
|
return transaction;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Transaction::setTopicIdByGroup(const std::string& alias)
|
bool Transaction::setTopicIdByGroup(const std::string& alias)
|
||||||
@ -326,7 +331,7 @@ namespace model {
|
|||||||
finished = true;
|
finished = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// try not finished but sign transactions again
|
// try not finished but signed transactions again
|
||||||
if (!finished) {
|
if (!finished) {
|
||||||
transaction->ifEnoughSignsProceed(nullptr);
|
transaction->ifEnoughSignsProceed(nullptr);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,8 +32,8 @@ namespace model {
|
|||||||
// groupMemberUpdate
|
// groupMemberUpdate
|
||||||
static Poco::AutoPtr<Transaction> createGroupMemberUpdate(Poco::AutoPtr<controller::User> user, Poco::AutoPtr<controller::Group> group);
|
static Poco::AutoPtr<Transaction> createGroupMemberUpdate(Poco::AutoPtr<controller::User> user, Poco::AutoPtr<controller::Group> group);
|
||||||
//! \brief transfer
|
//! \brief transfer
|
||||||
//! \return for cross group transaction return two transactions
|
//! \return
|
||||||
static std::vector<Poco::AutoPtr<Transaction>> createTransfer(
|
static Poco::AutoPtr<Transaction> createTransfer(
|
||||||
Poco::AutoPtr<controller::User> sender,
|
Poco::AutoPtr<controller::User> sender,
|
||||||
const MemoryBin* receiverPubkey,
|
const MemoryBin* receiverPubkey,
|
||||||
Poco::AutoPtr<controller::Group> receiverGroup,
|
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);
|
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
|
// 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);
|
Poco::Thread::sleep(sleep_ms_between_transactions);
|
||||||
transaction4[0]->sign(user_2);
|
transaction4->sign(user_2);
|
||||||
auto transaction4_json = transaction4[0]->getTransactionAsJson(true);
|
auto transaction4_json = transaction4->getTransactionAsJson(true);
|
||||||
%>
|
%>
|
||||||
<p><%= DataTypeConverter::replaceNewLineWithBr(transaction4_json) %></p>
|
<p><%= DataTypeConverter::replaceNewLineWithBr(transaction4_json) %></p>
|
||||||
<% } %>
|
<% } %>
|
||||||
@ -348,7 +348,7 @@ enum PageType
|
|||||||
<% } else {
|
<% } else {
|
||||||
auto user_3_pubkey = user_3->getModel()->getPublicKeyCopy();
|
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);
|
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">
|
<div class="alert alert-error" role="alert">
|
||||||
<i class="material-icons-outlined">report_problem</i>
|
<i class="material-icons-outlined">report_problem</i>
|
||||||
@ -357,9 +357,9 @@ enum PageType
|
|||||||
<%
|
<%
|
||||||
} else {
|
} else {
|
||||||
Poco::Thread::sleep(sleep_ms_between_transactions);
|
Poco::Thread::sleep(sleep_ms_between_transactions);
|
||||||
transaction6[0]->sign(user_2);
|
transaction6->sign(user_2);
|
||||||
auto transaction6_json = transaction6[0]->getTransactionAsJson(true);
|
auto transaction6_json = transaction6->getTransactionAsJson(true);
|
||||||
auto paired_transaction = transaction6[0]->getPairedTransaction();
|
auto paired_transaction = transaction6->getPairedTransaction();
|
||||||
%>
|
%>
|
||||||
<p><%= DataTypeConverter::replaceNewLineWithBr(transaction6_json) %></p>
|
<p><%= DataTypeConverter::replaceNewLineWithBr(transaction6_json) %></p>
|
||||||
<% if(!paired_transaction.isNull()) {
|
<% if(!paired_transaction.isNull()) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user