From c802a55bac46e18ee07f56e08e3e22c96d0f363b Mon Sep 17 00:00:00 2001 From: Deniod Date: Fri, 12 Jan 2024 11:11:00 +0100 Subject: [PATCH] replace sietch transactions with the new note automatic if spendable notes < 30 --- src/controller.cpp | 105 ++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 77 deletions(-) diff --git a/src/controller.cpp b/src/controller.cpp index 724cc1d..ee22b80 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -188,40 +188,27 @@ void Controller::fillTxJsonParams(json& allRecepients, Tx tx) } - // Create more Notes if spendableNotesCount < 7 - bool extraTransactionAdded = false; - - if (spendableNotesCount < 7) { - // Create a random memo for that - QString randomMemo; - for (int i = 0; i < randomStringLength; ++i) { - int index = QRandomGenerator::system()->bounded(0, possibleCharacters.length()); - randomMemo.append(possibleCharacters.at(index)); - } - - // create the transaction - json extraTransaction = json::object(); - extraTransaction["address"] = addressWithMaxValue.toStdString(); - extraTransaction["amount"] = 12000; - extraTransaction["memo"] = randomMemo.toStdString(); + // Create more Notes if spendableNotesCount < 30 + if (spendableNotesCount < 30) { + // Create extra transaction + for (size_t i = 0; i < dust.size(); ++i) { + // Generate random memo + QString randomMemo; + for (int j = 0; j < randomStringLength; ++j) { + int index = QRandomGenerator::system()->bounded(0, possibleCharacters.length()); + randomMemo.append(possibleCharacters.at(index)); + } - // Replace one sietch transaction - if (!dust.empty()) { - dust.front() = extraTransaction; - extraTransactionAdded = true; - } else { - dust.push_back(extraTransaction); - extraTransactionAdded = true; + dust.at(i)["address"] = addressWithMaxValue.toStdString(); + dust.at(i)["amount"] = 10000; + dust.at(i)["memo"] = randomMemo.toStdString(); } - } - - // Set amount = 0 to all sietch transactions - for(auto &it: dust) { - if (!extraTransactionAdded || it["address"] != addressWithMaxValue.toStdString()) { - it["amount"] = 0; - } - -} + } else { + // Set amount for real Sietch transaction to 0 + for (auto &it : dust) { + it["amount"] = 0; + } + } // For each addr/amt/memo, construct the JSON and also build the confirm dialog box for (int i=0; i < tx.toAddrs.size(); i++) @@ -230,57 +217,21 @@ void Controller::fillTxJsonParams(json& allRecepients, Tx tx) rec["address"] = toAddr.addr.toStdString(); rec["amount"] = toAddr.amount.toqint64(); if (Settings::isZAddress(toAddr.addr) && !toAddr.memo.trimmed().isEmpty()) - rec["memo"] = toAddr.memo.toStdString(); + rec["memo"] = toAddr.memo.toStdString(); + } allRecepients.push_back(rec); - } - int decider = rand() % 100 + 1 ; ; // random int between 1 and 100 + int decider = rand() % 100 + 1; + + int dustCount = (decider % 4 == 3) ? 5 : 6; if (tx.toAddrs.size() < 2) { - - if(decider % 4 == 3) { - allRecepients.insert(std::begin(allRecepients), { - dust.at(0), - dust.at(1), - dust.at(2), - dust.at(3), - dust.at(4), - dust.at(5) - }) ; - - } else { - allRecepients.insert(std::begin(allRecepients), { - dust.at(0), - dust.at(1), - dust.at(2), - dust.at(3), - dust.at(4), - dust.at(5), - dust.at(6) - }) ; - } - } else { - - if(decider % 4 == 3) { - allRecepients.insert(std::begin(allRecepients), { - dust.at(0), - dust.at(1), - dust.at(2), - dust.at(3), - dust.at(4) - }) ; - } else { - allRecepients.insert(std::begin(allRecepients), { - dust.at(0), - dust.at(1), - dust.at(2), - dust.at(3), - dust.at(4), - dust.at(5) - }) ; - } + dustCount++; } + for (int i = 0; i < dustCount; ++i) { + allRecepients.insert(allRecepients.begin(), dust.at(i)); + } } void Controller::noConnection()