Browse Source

logging and error handling

pull/24/head
Duke Leto 3 years ago
parent
commit
a135753cef
  1. 35
      src/Chat/Chat.cpp
  2. 9
      src/DataStore/ChatDataStore.cpp
  3. 2
      src/connection.cpp
  4. 13
      src/controller.cpp
  5. 27
      src/mainwindow.cpp

35
src/Chat/Chat.cpp

@ -93,21 +93,17 @@ void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view, QLabel *label)
DataStore::getChatDataStore()->dump(); // test to see if the chat items in datastore are correctly dumped to json
qDebug() << __func__ << ": looking at memos...";
for (auto &p : AddressBook::getInstance()->getAllAddressLabels())
for (auto &contact : AddressBook::getInstance()->getAllAddressLabels())
{
for (auto &c : DataStore::getChatDataStore()->getAllMemos())
{
for (auto &memo : DataStore::getChatDataStore()->getAllMemos()) {
if ( (contact.getName() == ui->contactNameMemo->text().trimmed()) &&
(contact.getPartnerAddress() == memo.second.getAddress()) &&
(memo.second.isOutgoing() == true)) {
if (
(p.getName() == ui->contactNameMemo->text().trimmed()) &&
(p.getPartnerAddress() == c.second.getAddress()) &&
(c.second.isOutgoing() == true))
{
QStandardItem *Items = new QStandardItem(c.second.toChatLine());
QStandardItem *Items = new QStandardItem(memo.second.toChatLine());
Items->setData(OUTGOING, Qt::UserRole + 1);
qDebug() << __func__ << ": appending row to OUTGOING chatitems to contact " << p.getName() << " with item " << Items;
qDebug() << __func__ << ": appending row to OUTGOING chatitems to contact " << contact.getName() << " with item " << Items;
chat->appendRow(Items);
ui->listChat->setModel(chat);
@ -115,16 +111,15 @@ void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view, QLabel *label)
ui->listChat->setModel(chat);
}
if (
(p.getName() == ui->contactNameMemo->text().trimmed()) &&
(p.getMyAddress() == c.second.getAddress()) &&
(c.second.isOutgoing() == false) &&
(c.second.getCid() == p.getCid())
)
{
QStandardItem *Items1 = new QStandardItem(c.second.toChatLine());
qDebug() << __func__ << ": memo.first=" << memo.first;
if ( (contact.getName() == ui->contactNameMemo->text().trimmed()) &&
(contact.getMyAddress() == memo.second.getAddress()) &&
(memo.second.isOutgoing() == false) &&
(memo.second.getCid() == contact.getCid())
) {
QStandardItem *Items1 = new QStandardItem(memo.second.toChatLine());
Items1->setData(INCOMING, Qt::UserRole + 1);
qDebug() << __func__ << ": appending row to INCOMING chatitems to contact " << p.getName() << "with cid=" << p.getCid() << " and item " << Items1;
qDebug() << __func__ << ": appending row to INCOMING chatitems to contact " << contact.getName() << "with txid=" << memo.second.getTxid() << " cid=" << contact.getCid() << " item " << Items1 << " memo=" << memo.second.getMemo();
chat->appendRow(Items1);
ui->listChat->setModel(chat);
ui->memoTxtChat->setEnabled(true);

9
src/DataStore/ChatDataStore.cpp

@ -160,14 +160,7 @@ std::map<QString, ChatItem> ChatDataStore::getAllMemos()
std::map<QString, ChatItem> filteredItems;
for(auto &c: this->data)
{
if (
(c.second.getMemo().startsWith("{") == false) &&
(c.second.getMemo().isEmpty() == false)
)
{
if ((c.second.getMemo().startsWith("{") == false) && (c.second.getMemo().isEmpty() == false) ) {
filteredItems[c.first] = c.second;
}
}

2
src/connection.cpp

@ -267,6 +267,7 @@ void ConnectionLoader::doRPCSetConnection(Connection* conn)
try {
QFile plaintextWallet(dirwalletconnection);
main->logger->write("Path to Wallet.dat : " );
qDebug() << __func__ << ": wallet path =" << plaintextWallet;
plaintextWallet.remove();
} catch (...) {
@ -286,6 +287,7 @@ void ConnectionLoader::doRPCSetConnectionShield(Connection* conn)
try {
QFile plaintextWallet(dirwalletconnection);
main->logger->write("Path to Wallet.dat : " );
qDebug() << __func__ << ": wallet path =" << plaintextWallet;
plaintextWallet.remove();
} catch (...) {
main->logger->write("no Plaintext wallet.dat");

13
src/controller.cpp

@ -1236,13 +1236,13 @@ void Controller::refreshTransactions() {
}
int position = it["position"].get<json::number_integer_t>();
int ciphercheck = memo.length() - crypto_secretstream_xchacha20poly1305_ABYTES;
qDebug() << __func__ << ": position=" << position << " headerbytes=" << headerbytes
<< " ciphercheck=" << ciphercheck << " for memo=" << memo;
if ((memo.startsWith("{") == false) && (headerbytes > 0) && (ciphercheck > 0))
{
if (chatModel->getMemoByTx(txid) == QString("0xdeadbeef"))
{
if (chatModel->getMemoByTx(txid) == QString("0xdeadbeef")) {
if (position == 1)
{
chatModel->addMemo(txid, headerbytes);
@ -1352,10 +1352,13 @@ void Controller::refreshTransactions() {
DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item);
} else {
//
qDebug() << __func__ << ": ignoring txid="<< txid;
}
//} else if (memo.startsWith("{")) {
//qDebug() << __func__ << ": ignoring a header memo";
} else {
// Add a chatitem for the initial CR
ChatItem item = ChatItem(
datetime,
address,
@ -1371,7 +1374,7 @@ void Controller::refreshTransactions() {
isContact
);
qDebug() << "refreshTransactions: adding chatItem with memo=" << memo;
qDebug() << "refreshTransactions: adding chatItem for initial CR with memo=" << memo;
DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item);
}
}

27
src/mainwindow.cpp

@ -86,15 +86,17 @@ MainWindow::MainWindow(QWidget *parent) :
}else{}
logger = new Logger(this, QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("silentdragonlite-wallet.log"));
// Check for encryption
if(fileExists(dirwalletenc))
{
qDebug() << __func__ << ": decrypting wallet=" << dirwalletenc;
this->removeWalletEncryptionStartUp();
}
ui->memoTxtChat->setAutoFillBackground(false);
ui->memoTxtChat->setPlaceholderText("Send Message (you can only write messages after the initial message from your contact)");
// TODO: make this HTML with some emoji
ui->memoTxtChat->setPlaceholderText("Send Memo (you can only write memo after the initial message from your contact)");
ui->memoTxtChat->setTextColor(Qt::white);
// Status Bar
@ -543,10 +545,8 @@ void MainWindow::removeWalletEncryption() {
QObject::connect(ed.txtConfirmPassword, &QLineEdit::textChanged, fnPasswordEdited);
QObject::connect(ed.txtPassword, &QLineEdit::textChanged, fnPasswordEdited);
if (d.exec() == QDialog::Accepted)
{
if (d.exec() == QDialog::Accepted) {
QString passphraseBlank = ed.txtPassword->text(); // data comes from user inputs
QString passphrase = QString("HUSH3") + passphraseBlank + QString("SDL");
int length = passphrase.length();
@ -563,18 +563,17 @@ void MainWindow::removeWalletEncryption() {
#define hash ((const unsigned char *) sequence1)
#define PASSWORD sequence
#define KEY_LEN crypto_box_SEEDBYTES
unsigned char key[KEY_LEN];
if (crypto_pwhash
(key, sizeof key, PASSWORD, strlen(PASSWORD), hash,
crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE,
crypto_pwhash_ALG_DEFAULT) != 0) {
if (crypto_pwhash(key, sizeof key, PASSWORD, strlen(PASSWORD), hash,
crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE, crypto_pwhash_ALG_DEFAULT) != 0) {
/* out of memory */
}
qDebug() << "crypto_pwhash failed!";
return;
}
auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
auto dirHome = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
@ -587,9 +586,7 @@ void MainWindow::removeWalletEncryption() {
QFile filencrypted(dirwalletenc);
QFile wallet(dirwallet);
if (wallet.size() > 0)
{
if (wallet.size() > 0) {
QMessageBox::information(this, tr("Wallet decryption Success"),
QString("Successfully delete the encryption"),
QMessageBox::Ok
@ -597,7 +594,7 @@ void MainWindow::removeWalletEncryption() {
filencrypted.remove();
}else{
} else {
QMessageBox::critical(this, tr("Wallet Encryption Failed"),
QString("False password, please try again"),

Loading…
Cancel
Save