Skip to content
This repository was archived by the owner on Jul 23, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions DigitalNote.pro
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ HEADERS += src/qt/bitcoingui.h \
src/qt/sendmessagesdialog.h \
src/qt/sendmessagesentry.h \
src/qt/blockbrowser.h \
src/qt/airdroppage.h \
src/qt/plugins/mrichtexteditor/mrichtextedit.h \
src/qt/qvalidatedtextedit.h \
src/crypto/common/sph_bmw.h \
Expand Down Expand Up @@ -456,6 +457,7 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
src/qt/sendmessagesdialog.cpp \
src/qt/sendmessagesentry.cpp \
src/qt/blockbrowser.cpp \
src/qt/airdroppage.cpp \
src/qt/qvalidatedtextedit.cpp \
src/qt/plugins/mrichtexteditor/mrichtextedit.cpp \
src/rpcsmessage.cpp \
Expand Down Expand Up @@ -488,6 +490,7 @@ FORMS += \
src/qt/forms/sendmessagesentry.ui \
src/qt/forms/sendmessagesdialog.ui \
src/qt/forms/blockbrowser.ui \
src/qt/forms/airdroppage.ui \
src/qt/plugins/mrichtexteditor/mrichtextedit.ui

contains(USE_QRCODE, 1) {
Expand Down
157 changes: 157 additions & 0 deletions src/qt/airdroppage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#include "airdroppage.h"
#include "ui_airdroppage.h"
#include "main.h"
#include "init.h"
#include "base58.h"
#include "clientmodel.h"
#include "walletmodel.h"
#include "rpcconsole.h"
#include "smessage.h"

#include <sstream>
#include <string>
namespace fs = boost::filesystem;
AirdropPage::AirdropPage(QWidget *parent) :
QWidget(parent),
ui(new Ui::AirdropPage) {
ui->setupUi(this);

setFixedSize(900, 420);

connect(ui->enrollButton, SIGNAL(pressed()), SLOT(enrollButtonClicked()));

enrolledEthAddress = this->IsAlreadyEnrolledEthAddress();
if (enrolledEthAddress != "") {
ui->ethAddressBox->hide();
ui->enrollButton->hide();
std::string message = "You have already signed up for the airdrop with this address: " + enrolledEthAddress;
ui->ethAddressLabel->setText(message.c_str());
}
}

void AirdropPage::setModel(WalletModel *model)
{
this->model = model;
}

AirdropPage::~AirdropPage() {
delete ui;
}

void AirdropPage::enrollButtonClicked()
{
enrollForAirdrop();
}

void AirdropPage::enrollForAirdrop()
{
if (pwalletMain->IsLocked()) {
QMessageBox::warning(this, tr("Wallet locked"), tr("Please unlock your wallet"), QMessageBox::Ok);
return;
}

if (!fSecMsgEnabled) {
QMessageBox::warning(this, tr("Secure messaging disabled"), tr("Please enabled secure messaging"), QMessageBox::Ok);
return;
}

std::string ethAddress = ui->ethAddressBox->text().toUtf8().constData();
if (ethAddress.length() != 42) {
QMessageBox::warning(this, tr("Invalid ETH address"), tr("Please enter 42 length ETH address. Example: 0x00B54E93EE2EBA3086A55F4249873E291D1AB06C"), QMessageBox::Ok);
return;
}
// ui->processing->setText("Enrolling your addresses for airdrop. Please wait...");
ui->enrollButton->setEnabled(false);
ui->enrollButton->hide();
ui->ethAddressBox->hide();

std::string sError;
int addressesCount = SignUpForAirdrop(sError, ethAddress);

if (addressesCount == 0) {
QMessageBox::warning(NULL, tr("Send Secure Message"),
tr("Send failed: %1.").arg(sError.c_str()),
QMessageBox::Ok, QMessageBox::Ok);
}

if (addressesCount != 0) {
AirdropPage::IsAlreadyEnrolledEthAddressWrite(ethAddress);

std::string message = "Enrolled your " + std::to_string(addressesCount)+ " addresses \n for the airdrop with this ETH address: " + ethAddress + ".\n";
ui->ethAddressLabel->setText(message.c_str());
} else {
std::string message = "Something went wrong when enrolling your addresses for the airdrop. Please try again later or check Discord for more info.";
ui->ethAddressLabel->setText(message.c_str());
}
}

std::string AirdropPage::IsAlreadyEnrolledEthAddress()
{
LogPrint("airdrop", "airdrop: IsAlreadyEnrolledEthAddress");

fs::path fullpath = GetDataDir() / "airdrop.ini";
FILE *fp;
errno = 0;
if (!(fp = fopen(fullpath.string().c_str(), "r")))
{
return "";
};

char cLine[512];
char cAddress[64];
char *pName, *pValue;

while (fgets(cLine, 512, fp))
{

cLine[strcspn(cLine, "\n")] = '\0';
cLine[strcspn(cLine, "\r")] = '\0';
cLine[511] = '\0'; // for safety

// -- check that line contains a name value pair and is not a comment, or section header
if (cLine[0] == '#' || cLine[0] == '[' || strcspn(cLine, "=") < 1)
continue;

if (!(pName = strtok(cLine, "="))
|| !(pValue = strtok(NULL, "=")))
continue;

if (strcmp(pName, "enrolledAddress") == 0)
{
int rv = sscanf(pValue, "%s*", cAddress);
return std::string(cAddress);
}
};

fclose(fp);

return "";
}

bool AirdropPage::IsAlreadyEnrolledEthAddressWrite(const std::string& ethAddress)
{
fs::path fullpath = GetDataDir() / "airdrop.ini~";

FILE *fp;
errno = 0;
if (!(fp = fopen(fullpath.string().c_str(), "w")))
{
return false;
};

errno = 0;
if (fprintf(fp, "enrolledAddress=%s\n", ethAddress.c_str()) < 0) {
fclose(fp);
return false;
} else {
fclose(fp);
}

try {
fs::path finalpath = GetDataDir() / "airdrop.ini";
fs::rename(fullpath, finalpath);
} catch (const fs::filesystem_error& ex)
{
};
return true;
}
52 changes: 52 additions & 0 deletions src/qt/airdroppage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef DIGITALNOTE_AIRDROPPAGE_H
#define DIGITALNOTE_AIRDROPPAGE_H

#include "clientmodel.h"
#include "walletmodel.h"
#include "main.h"
#include "wallet.h"
#include "base58.h"
#include <QWidget>
#include "util.h"

#include <QDir>
#include <QFile>
#include <QProcess>
#include <QTime>
#include <QTimer>
#include <QStringList>
#include <QMap>
#include <QSettings>
#include <QSlider>

namespace Ui {
class AirdropPage;
}
class WalletModel;

class AirdropPage : public QWidget {
Q_OBJECT
std::string enrolledEthAddress;
public:
explicit AirdropPage(QWidget *parent = 0);

~AirdropPage();

void setModel(WalletModel *model);

public
slots:
void enrollButtonClicked();
void enrollForAirdrop();

private
slots:

private:
Ui::AirdropPage *ui;
WalletModel *model;
static std::string IsAlreadyEnrolledEthAddress();
static bool IsAlreadyEnrolledEthAddressWrite(const std::string& ethAddress);
};

#endif //DIGITALNOTE_AIRDROPPAGE_H
1 change: 1 addition & 0 deletions src/qt/bitcoin.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<file alias="lock_open">res/icons/lock_open.png</file>
<file alias="key">res/icons/key.png</file>
<file alias="block">res/icons/block.png</file>
<file alias="airdrop">res/icons/airdrop.png</file>
<file alias="filesave">res/icons/filesave.png</file>
<file alias="qrcode">res/icons/qrcode.png</file>
<file alias="debugwindow">res/icons/debugwindow.png</file>
Expand Down
30 changes: 30 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "masternodemanager.h"
#include "messagemodel.h"
#include "messagepage.h"
#include "airdroppage.h"
#include "blockbrowser.h"
#include "importprivatekeydialog.h"

Expand Down Expand Up @@ -148,6 +149,8 @@ DigitalNoteGUI::DigitalNoteGUI(QWidget *parent):

messagePage = new MessagePage(this);

airdropPage = new AirdropPage(this);

centralStackedWidget = new QStackedWidget(this);
centralStackedWidget->setContentsMargins(0, 0, 0, 0);
centralStackedWidget->addWidget(overviewPage);
Expand All @@ -158,6 +161,7 @@ DigitalNoteGUI::DigitalNoteGUI(QWidget *parent):
centralStackedWidget->addWidget(masternodeManagerPage);
centralStackedWidget->addWidget(messagePage);
centralStackedWidget->addWidget(blockBrowser);
centralStackedWidget->addWidget(airdropPage);

QWidget *centralWidget = new QWidget();
QVBoxLayout *centralLayout = new QVBoxLayout(centralWidget);
Expand Down Expand Up @@ -326,6 +330,12 @@ void DigitalNoteGUI::createActions()
blockAction->setCheckable(true);
tabGroup->addAction(blockAction);

airdropAction = new QAction(QIcon(":/icons/airdrop"), tr("&Airdrop"), this);
airdropAction->setToolTip(tr("Enroll for Airdrop"));
airdropAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_8));
airdropAction->setCheckable(true);
tabGroup->addAction(airdropAction);

showBackupsAction = new QAction(QIcon(":/icons/browse"), tr("Show Auto&Backups"), this);
showBackupsAction->setStatusTip(tr("S"));

Expand All @@ -344,6 +354,8 @@ void DigitalNoteGUI::createActions()
connect(masternodeManagerAction, SIGNAL(triggered()), this, SLOT(gotoMasternodeManagerPage()));
connect(messageAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
connect(messageAction, SIGNAL(triggered()), this, SLOT(gotoMessagePage()));
connect(airdropAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized()));
connect(airdropAction, SIGNAL(triggered()), this, SLOT(gotoAirdropPage()));

quitAction = new QAction(QIcon(":icons/quit"), tr("E&xit"), this);
quitAction->setToolTip(tr("Quit application"));
Expand Down Expand Up @@ -487,6 +499,7 @@ void DigitalNoteGUI::createToolBars()
toolbar->addAction(messageAction);
}
toolbar->addAction(blockAction);
toolbar->addAction(airdropAction);
netLabel = new QLabel();

QWidget *spacer = makeToolBarSpacer();
Expand Down Expand Up @@ -574,6 +587,7 @@ void DigitalNoteGUI::setWalletModel(WalletModel *walletModel)
sendCoinsPage->setModel(walletModel);
signVerifyMessageDialog->setModel(walletModel);
blockBrowser->setModel(walletModel);
airdropPage->setModel(walletModel);

setEncryptionStatus(walletModel->getEncryptionStatus());
connect(walletModel, SIGNAL(encryptionStatusChanged(int)), this, SLOT(setEncryptionStatus(int)));
Expand Down Expand Up @@ -1082,6 +1096,22 @@ void DigitalNoteGUI::gotoMessagePage()
connect(exportAction, SIGNAL(triggered()), messagePage, SLOT(exportClicked()));
}

void DigitalNoteGUI::gotoAirdropPage()
{
if(!fGUIunlock) {
QMessageBox::information(this, tr("Wallet is locked"),
tr("Please unlock your wallet to use this feature."));
return;
}

airdropAction->setChecked(true);
centralStackedWidget->setCurrentWidget(airdropPage);

exportAction->setEnabled(true);
disconnect(exportAction, SIGNAL(triggered()), 0, 0);
connect(exportAction, SIGNAL(triggered()), airdropPage, SLOT(exportClicked()));
}

void DigitalNoteGUI::dragEnterEvent(QDragEnterEvent *event)
{
// Accept only URIs
Expand Down
5 changes: 5 additions & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Notificator;
class RPCConsole;
class MasternodeManager;
class MessagePage;
class AirdropPage;
class MessageModel;
class BlockBrowser;

Expand Down Expand Up @@ -82,6 +83,7 @@ class DigitalNoteGUI : public QMainWindow
SignVerifyMessageDialog *signVerifyMessageDialog;
MasternodeManager *masternodeManagerPage;
MessagePage *messagePage;
AirdropPage *airdropPage;
QLabel* netLabel;
BlockBrowser *blockBrowser;
QLabel *labelEncryptionIcon;
Expand Down Expand Up @@ -115,6 +117,7 @@ class DigitalNoteGUI : public QMainWindow
QAction *openRPCConsoleAction;
QAction *masternodeManagerAction;
QAction *messageAction;
QAction *airdropAction;
QAction *blockAction;
QAction *showBackupsAction;
QAction *editConfigAction;
Expand Down Expand Up @@ -196,6 +199,8 @@ private slots:
void gotoVerifyMessageTab(QString addr = "");
/** Switch to message page*/
void gotoMessagePage();
/** Switch to airdrop page*/
void gotoAirdropPage();
/** Show configuration dialog */
void optionsClicked();
/** Show about dialog */
Expand Down
Loading