Обновить transactions2/transactions2.cpp
This commit is contained in:
parent
c7b5312b79
commit
56ca258454
@ -34,7 +34,7 @@ vector<Block> blocks;
|
||||
bool loadBlocksFromFile(const string& filename) {
|
||||
ifstream input_file(filename);
|
||||
if (!input_file.is_open()) {
|
||||
cerr << "Error: Cannot open file " << filename << endl; //Ошибка: не удалось открыть файл
|
||||
cerr << "Error: Cannot open file " << filename << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -64,12 +64,12 @@ bool loadBlocksFromFile(const string& filename) {
|
||||
blocks.push_back(block);
|
||||
}
|
||||
|
||||
//Успешно загружено //блоков из файла
|
||||
|
||||
cout << "Successfully loaded " << blocks.size() << " blocks from " << filename << endl;
|
||||
return true;
|
||||
}
|
||||
catch (const exception& e) {
|
||||
cerr << "JSON parsing error: " << e.what() << endl; //Ошибка при чтении JSON:
|
||||
cerr << "JSON parsing error: " << e.what() << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -100,12 +100,12 @@ bool saveBlocksToFile(const string& filename) {
|
||||
|
||||
ofstream output_file(filename);
|
||||
if (!output_file.is_open()) {
|
||||
cerr << "Error: Cannot create file " << filename << endl; //Ошибка: не удалось создать файл
|
||||
cerr << "Error: Cannot create file " << filename << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
output_file << setw(4) << j << endl;
|
||||
cout << "Successfully saved " << blocks.size() << " blocks to " << filename << endl; //Успешно сохранено //блоков в файл
|
||||
cout << "Successfully saved " << blocks.size() << " blocks to " << filename << endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ void printBlock(const Block& block) {
|
||||
|
||||
void printAllBlocks() {
|
||||
if (blocks.empty()) {
|
||||
cout << "There is no data about the blocks.Download them first." << endl; //Нет данных о блоках. Загрузите их сначала.
|
||||
cout << "There is no data about the blocks.Download them first." << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -138,12 +138,12 @@ void printAllBlocks() {
|
||||
|
||||
void filterByMiner() {
|
||||
if (blocks.empty()) {
|
||||
cout << "There is no data about the blocks. Download them first." << endl; //Нет данных о блоках. Загрузите их сначала.
|
||||
cout << "There is no data about the blocks. Download them first." << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
string minerName;
|
||||
cout << "Enter the miner's name: "; //Введите имя майнера:
|
||||
cout << "Enter the miner's name: ";
|
||||
cin >> minerName;
|
||||
|
||||
bool found = false;
|
||||
@ -155,17 +155,17 @@ void filterByMiner() {
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
cout << "Blocks with a miner " << minerName << " not found." << endl; //Блоки с майнером ... не найдены
|
||||
cout << "Blocks with a miner " << minerName << " not found." << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void printTransactionsCount() {
|
||||
if (blocks.empty()) {
|
||||
cout << "There is no data about the blocks. Download them first." << endl; //Нет данных о блоках. Загрузите их сначала.
|
||||
cout << "There is no data about the blocks. Download them first." << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
cout << "Number of transactions in blocks: " << endl; //Количество транзакций в блоках:
|
||||
cout << "Number of transactions in blocks: " << endl;
|
||||
for (const auto& block : blocks) {
|
||||
cout << "block " << block.index << ": "
|
||||
<< block.transactions.size() << " transactions" << endl;
|
||||
@ -174,7 +174,7 @@ void printTransactionsCount() {
|
||||
|
||||
void calculateBalances() {
|
||||
if (blocks.empty()) {
|
||||
cout << "There is no data about the blocks. Download them first." << endl; //Нет данных о блоках. Загрузите их сначала.
|
||||
cout << "There is no data about the blocks. Download them first." << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -189,7 +189,7 @@ void calculateBalances() {
|
||||
}
|
||||
}
|
||||
|
||||
cout << "User balances:" << endl; //Балансы пользователей:
|
||||
cout << "User balances:" << endl;
|
||||
for (const auto& entry : balances) {
|
||||
cout << entry.first << ": " << fixed << setprecision(2) << entry.second << endl;
|
||||
}
|
||||
@ -208,7 +208,7 @@ void sortBlocksByIndex() {
|
||||
}
|
||||
}
|
||||
}
|
||||
cout << "The blocks are sorted by index." << endl; //Блоки отсортированы по индексу.
|
||||
cout << "The blocks are sorted by index." << endl;
|
||||
}
|
||||
|
||||
void printEvenIndexBlocks() {
|
||||
@ -217,7 +217,7 @@ void printEvenIndexBlocks() {
|
||||
return;
|
||||
}
|
||||
|
||||
cout << "Blocks with an even index:" << endl; //Блоки с четным индексом:
|
||||
cout << "Blocks with an even index:" << endl;
|
||||
for (const auto& block : blocks) {
|
||||
if (block.index % 2 == 0) {
|
||||
printBlock(block);
|
||||
@ -232,7 +232,7 @@ void printVowelMinerBlocks() {
|
||||
}
|
||||
|
||||
const string vowels = "AEIOUaeiou";
|
||||
cout << "Blocks where the miner starts with a vowel:" << endl; //Блоки, где майнер начинается с гласной:
|
||||
cout << "Blocks where the miner starts with a vowel:" << endl;
|
||||
|
||||
for (const auto& block : blocks) {
|
||||
if (!block.miner.empty() && vowels.find(block.miner[0]) != string::npos) {
|
||||
@ -247,7 +247,7 @@ void printFourDigitNonceBlocks() {
|
||||
return;
|
||||
}
|
||||
|
||||
cout << "Blocks with a 4-digit nonce (1000-9999):" << endl; //Блоки с 4-значным nonce (1000-9999):
|
||||
cout << "Blocks with a 4-digit nonce (1000-9999):" << endl;
|
||||
for (const auto& block : blocks) {
|
||||
if (block.nonce >= 1000 && block.nonce <= 9999) {
|
||||
printBlock(block);
|
||||
@ -256,19 +256,19 @@ void printFourDigitNonceBlocks() {
|
||||
}
|
||||
|
||||
void showMenu() {
|
||||
cout << "\n=== Menu ===" << endl //Загрузить блоки из файла
|
||||
<< "1. Load blocks from file" << endl //Загрузить блоки из файла
|
||||
<< "2. Save blocks to file" << endl //Сохранить блоки в файл
|
||||
<< "3. Print all blocks" << endl //Вывести все блоки
|
||||
<< "4. Filter by miner" << endl //Фильтр по майнеру
|
||||
<< "5. Transaction count" << endl //Количество транзакций
|
||||
<< "6. User balances" << endl //Балансы пользователей
|
||||
<< "7. Sort by index" << endl //Сортировать по индексу
|
||||
<< "8. Blocks with even index" << endl //Блоки с четным индексом
|
||||
<< "9. Blocks where miner starts with a vowel" << endl //Блоки, где майнер начинается с гласной
|
||||
<< "10. Blocks with 4-digit nonce" << endl //Блоки с 4-значным nonce
|
||||
<< "0. Exit" << endl //Выход
|
||||
<< "Enter choice: "; //Введите номер
|
||||
cout << "\n=== Menu ===" << endl
|
||||
<< "1. Load blocks from file" << endl
|
||||
<< "2. Save blocks to file" << endl
|
||||
<< "3. Print all blocks" << endl
|
||||
<< "4. Filter by miner" << endl
|
||||
<< "5. Transaction count" << endl
|
||||
<< "6. User balances" << endl
|
||||
<< "7. Sort by index" << endl
|
||||
<< "8. Blocks with even index" << endl
|
||||
<< "9. Blocks where miner starts with a vowel" << endl
|
||||
<< "10. Blocks with 4-digit nonce" << endl
|
||||
<< "0. Exit" << endl
|
||||
<< "Enter choice: ";
|
||||
}
|
||||
|
||||
int main() {
|
||||
@ -280,16 +280,16 @@ int main() {
|
||||
switch (choice) {
|
||||
case 1: {
|
||||
string filename;
|
||||
cout << "Enter the file name to download: "; //Введите имя файла для загрузки:
|
||||
cout << "Enter the file name to download: ";
|
||||
cin >> filename;
|
||||
if (!loadBlocksFromFile(filename)) {
|
||||
cout << "File upload error!" << endl; //Ошибка загрузки файла!
|
||||
cout << "File upload error!" << endl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
string filename;
|
||||
cout << "Enter the file name to save: "; //Введите имя файла для сохранения:
|
||||
cout << "Enter the file name to save: ";
|
||||
cin >> filename;
|
||||
if (!saveBlocksToFile(filename)) {
|
||||
cout << "File upload error!" << endl;
|
||||
@ -324,7 +324,7 @@ int main() {
|
||||
cout << "Exit the program..." << endl;
|
||||
break;
|
||||
default:
|
||||
cout << "Wrong choice! Try again." << endl; //Неверный выбор! Попробуйте снова.
|
||||
cout << "Wrong choice! Try again." << endl;
|
||||
}
|
||||
} while (choice != 0);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user