From 0466e9ab558df464e22dbf30f1666caa747251a3 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 12 Feb 2020 04:59:26 -0500 Subject: [PATCH] Method to create header memos and updates to sendMemo() --- src/mainwindow.cpp | 27 +++++++++++++++++++++++++++ src/mainwindow.h | 1 + 2 files changed, 28 insertions(+) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 012d0cb..9693d2e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -133,6 +133,8 @@ MainWindow::MainWindow(QWidget *parent) : createWebsocket(wormholecode); } + //QObject::connect(chatView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(onTableClicked(const QModelIndex &))); + setupSendTab(); setupTransactionsTab(); setupReceiveTab(); @@ -148,6 +150,25 @@ MainWindow::MainWindow(QWidget *parent) : } +QString MainWindow::createHeaderMemo(QString cid, QString zaddr, int version=0, int headerNumber=1) +{ + QString header=""; + QJsonDocument j; + QJsonObject h; + // We use short keynames to use less space for metadata and so allow + // the user to send more actual data in memos + h["h"] = headerNumber; // header number + h["v"] = version; // HushChat version + h["z"] = zaddr; // zaddr to respond to + h["cid"] = cid; // conversation id + + j.setObject(h); + header = j.toJson(); + qDebug() << "made header=" << header; + + return header; +} + // Send button clicked void MainWindow::sendMemo() { Tx tx; @@ -158,9 +179,15 @@ void MainWindow::sendMemo() { //TODO: verify we currently own the private key to this zaddr via z_validateaddress tx.fromAddr = chat.getMyZaddr(); double amount = 0; + //TODO: cid=random int64 or sha256 + QString cid = QString::number( time(NULL) % std::rand() ); // low entropy for testing! + QString hmemo= createHeaderMemo(cid,chat.getMyZaddr()); // TODO: look up input text to add to memo QString memo = ""; QString addr = contact.getZaddr(); + + // we send a header memo plus actual memo + tx.toAddrs.push_back( ToFields{addr, amount, hmemo, hmemo.toUtf8().toHex()} ); tx.toAddrs.push_back( ToFields{addr, amount, memo, memo.toUtf8().toHex()} ); QString error = doSendTxValidations(tx); diff --git a/src/mainwindow.h b/src/mainwindow.h index f8bb5f2..39ed431 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -109,6 +109,7 @@ public: void doClose(); HushChat getHushChat() { return hushChat; } void setHushChat(HushChat chat) { hushChat = chat; } + QString createHeaderMemo(QString cid, QString zaddr, int version, int headerNumnber); private: void closeEvent(QCloseEvent* event);