void saveCSV(CryptoNote::WalletGreen &wallet, CryptoNote::INode &node) { const size_t numTransactions = wallet.getTransactionCount(); std::ofstream csv; csv.open(WalletConfig::csvFilename); if (!csv) { std::cout << WarningMsg("Couldn't open transactions.csv file for " "saving!") << std::endl << WarningMsg("Ensure it is not open in any other " "application.") << std::endl; return; } std::cout << InformationMsg("Saving CSV file...") << std::endl; /* Create CSV header */ csv << "Timestamp,Block Height,Hash,Amount,In/Out" << std::endl; /* Loop through transactions */ for (size_t i = 0; i < numTransactions; i++) { const CryptoNote::WalletTransaction t = wallet.getTransaction(i); /* Ignore fusion transactions */ if (t.totalAmount == 0) { continue; } const std::string amount = formatAmountBasic(std::abs(t.totalAmount)); const std::string direction = t.totalAmount > 0 ? "IN" : "OUT"; csv << unixTimeToDate(t.timestamp) << "," /* Timestamp */ << t.blockHeight << "," /* Block Height */ << Common::podToHex(t.hash) << "," /* Hash */ << amount << "," /* Amount */ << direction /* In/Out */ << std::endl; } csv.close(); std::cout << SuccessMsg("CSV successfully written to ") << SuccessMsg(WalletConfig::csvFilename) << SuccessMsg("!") << std::endl; }
void listTransfers(bool incoming, bool outgoing, CryptoNote::WalletGreen &wallet, CryptoNote::INode &node) { const size_t numTransactions = wallet.getTransactionCount(); int64_t totalSpent = 0; int64_t totalReceived = 0; for (size_t i = 0; i < numTransactions; i++) { const CryptoNote::WalletTransaction t = wallet.getTransaction(i); if (t.totalAmount < 0 && outgoing) { printOutgoingTransfer(t, node); totalSpent += -t.totalAmount; } else if (t.totalAmount > 0 && incoming) { printIncomingTransfer(t, node); totalReceived += t.totalAmount; } } if (incoming) { std::cout << SuccessMsg("Total received: " + formatAmount(totalReceived)) << std::endl; } if (outgoing) { std::cout << WarningMsg("Total spent: " + formatAmount(totalSpent)) << std::endl; } }