mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-03-09 12:11:16 +00:00
sending support
This commit is contained in:
parent
1d7e321c10
commit
6630c1cbf5
@ -67,6 +67,7 @@ private slots:
|
|||||||
|
|
||||||
void newAddressClicked();
|
void newAddressClicked();
|
||||||
void copyClipboardClicked();
|
void copyClipboardClicked();
|
||||||
|
void error(const QString &title, const QString &message);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -9,18 +9,35 @@ class ClientModel : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit ClientModel(QObject *parent = 0);
|
explicit ClientModel(QObject *parent = 0);
|
||||||
|
|
||||||
|
enum StatusCode
|
||||||
|
{
|
||||||
|
OK,
|
||||||
|
InvalidAmount,
|
||||||
|
InvalidAddress,
|
||||||
|
AmountExceedsBalance,
|
||||||
|
AmountWithFeeExceedsBalance,
|
||||||
|
Aborted,
|
||||||
|
MiscError
|
||||||
|
};
|
||||||
|
|
||||||
qint64 getBalance();
|
qint64 getBalance();
|
||||||
QString getAddress();
|
QString getAddress();
|
||||||
int getNumConnections();
|
int getNumConnections();
|
||||||
int getNumBlocks();
|
int getNumBlocks();
|
||||||
int getNumTransactions();
|
int getNumTransactions();
|
||||||
|
|
||||||
|
qint64 getTransactionFee();
|
||||||
|
|
||||||
|
StatusCode sendCoins(const QString &payTo, qint64 payAmount);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void balanceChanged(qint64 balance);
|
void balanceChanged(qint64 balance);
|
||||||
void addressChanged(const QString &address);
|
void addressChanged(const QString &address);
|
||||||
void numConnectionsChanged(int count);
|
void numConnectionsChanged(int count);
|
||||||
void numBlocksChanged(int count);
|
void numBlocksChanged(int count);
|
||||||
void numTransactionsChanged(int count);
|
void numTransactionsChanged(int count);
|
||||||
|
/* Asynchronous error notification */
|
||||||
|
void error(const QString &title, const QString &message);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
namespace Ui {
|
namespace Ui {
|
||||||
class SendCoinsDialog;
|
class SendCoinsDialog;
|
||||||
}
|
}
|
||||||
|
class ClientModel;
|
||||||
|
|
||||||
class SendCoinsDialog : public QDialog
|
class SendCoinsDialog : public QDialog
|
||||||
{
|
{
|
||||||
@ -15,8 +16,11 @@ public:
|
|||||||
explicit SendCoinsDialog(QWidget *parent = 0, const QString &address = "");
|
explicit SendCoinsDialog(QWidget *parent = 0, const QString &address = "");
|
||||||
~SendCoinsDialog();
|
~SendCoinsDialog();
|
||||||
|
|
||||||
|
void setModel(ClientModel *model);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::SendCoinsDialog *ui;
|
Ui::SendCoinsDialog *ui;
|
||||||
|
ClientModel *model;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_buttonBox_rejected();
|
void on_buttonBox_rejected();
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
@ -160,6 +161,9 @@ void BitcoinGUI::setModel(ClientModel *model)
|
|||||||
|
|
||||||
setAddress(model->getAddress());
|
setAddress(model->getAddress());
|
||||||
connect(model, SIGNAL(addressChanged(QString)), this, SLOT(setAddress(QString)));
|
connect(model, SIGNAL(addressChanged(QString)), this, SLOT(setAddress(QString)));
|
||||||
|
|
||||||
|
/* Report errors from network/worker thread */
|
||||||
|
connect(model, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitcoinGUI::createTrayIcon()
|
void BitcoinGUI::createTrayIcon()
|
||||||
@ -226,6 +230,7 @@ QWidget *BitcoinGUI::createTabs()
|
|||||||
void BitcoinGUI::sendcoinsClicked()
|
void BitcoinGUI::sendcoinsClicked()
|
||||||
{
|
{
|
||||||
SendCoinsDialog dlg;
|
SendCoinsDialog dlg;
|
||||||
|
dlg.setModel(model);
|
||||||
dlg.exec();
|
dlg.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,3 +301,11 @@ void BitcoinGUI::setNumTransactions(int count)
|
|||||||
{
|
{
|
||||||
labelTransactions->setText(QLocale::system().toString(count)+" "+tr("transaction(s)", "", count));
|
labelTransactions->setText(QLocale::system().toString(count)+" "+tr("transaction(s)", "", count));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BitcoinGUI::error(const QString &title, const QString &message)
|
||||||
|
{
|
||||||
|
/* Report errors from network/worker thread */
|
||||||
|
QMessageBox::critical(this, title,
|
||||||
|
message,
|
||||||
|
QMessageBox::Ok, QMessageBox::Ok);
|
||||||
|
}
|
||||||
|
@ -51,6 +51,11 @@ int ClientModel::getNumTransactions()
|
|||||||
return numTransactions;
|
return numTransactions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qint64 ClientModel::getTransactionFee()
|
||||||
|
{
|
||||||
|
return nTransactionFee;
|
||||||
|
}
|
||||||
|
|
||||||
void ClientModel::update()
|
void ClientModel::update()
|
||||||
{
|
{
|
||||||
emit balanceChanged(getBalance());
|
emit balanceChanged(getBalance());
|
||||||
@ -59,3 +64,51 @@ void ClientModel::update()
|
|||||||
emit numBlocksChanged(getNumBlocks());
|
emit numBlocksChanged(getNumBlocks());
|
||||||
emit numTransactionsChanged(getNumTransactions());
|
emit numTransactionsChanged(getNumTransactions());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClientModel::StatusCode ClientModel::sendCoins(const QString &payTo, qint64 payAmount)
|
||||||
|
{
|
||||||
|
uint160 hash160 = 0;
|
||||||
|
bool valid = false;
|
||||||
|
|
||||||
|
if(!AddressToHash160(payTo.toUtf8().constData(), hash160))
|
||||||
|
{
|
||||||
|
return InvalidAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(payAmount <= 0)
|
||||||
|
{
|
||||||
|
return InvalidAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(payAmount > getBalance())
|
||||||
|
{
|
||||||
|
return AmountExceedsBalance;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((payAmount + nTransactionFee) > getBalance())
|
||||||
|
{
|
||||||
|
return AmountWithFeeExceedsBalance;
|
||||||
|
}
|
||||||
|
|
||||||
|
CRITICAL_BLOCK(cs_main)
|
||||||
|
{
|
||||||
|
// Send to bitcoin address
|
||||||
|
CWalletTx wtx;
|
||||||
|
CScript scriptPubKey;
|
||||||
|
scriptPubKey << OP_DUP << OP_HASH160 << hash160 << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||||
|
|
||||||
|
std::string strError = SendMoney(scriptPubKey, payAmount, wtx, true);
|
||||||
|
if (strError == "")
|
||||||
|
return OK;
|
||||||
|
else if (strError == "ABORTED")
|
||||||
|
return Aborted;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
emit error(tr("Sending..."), QString::fromStdString(strError));
|
||||||
|
return MiscError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "sendcoinsdialog.h"
|
#include "sendcoinsdialog.h"
|
||||||
#include "ui_sendcoinsdialog.h"
|
#include "ui_sendcoinsdialog.h"
|
||||||
|
#include "clientmodel.h"
|
||||||
|
|
||||||
#include "addressbookdialog.h"
|
#include "addressbookdialog.h"
|
||||||
#include "bitcoinaddressvalidator.h"
|
#include "bitcoinaddressvalidator.h"
|
||||||
@ -15,7 +16,8 @@
|
|||||||
|
|
||||||
SendCoinsDialog::SendCoinsDialog(QWidget *parent, const QString &address) :
|
SendCoinsDialog::SendCoinsDialog(QWidget *parent, const QString &address) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::SendCoinsDialog)
|
ui(new Ui::SendCoinsDialog),
|
||||||
|
model(0)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
@ -35,6 +37,11 @@ SendCoinsDialog::SendCoinsDialog(QWidget *parent, const QString &address) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SendCoinsDialog::setModel(ClientModel *model)
|
||||||
|
{
|
||||||
|
this->model = model;
|
||||||
|
}
|
||||||
|
|
||||||
SendCoinsDialog::~SendCoinsDialog()
|
SendCoinsDialog::~SendCoinsDialog()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
@ -42,35 +49,50 @@ SendCoinsDialog::~SendCoinsDialog()
|
|||||||
|
|
||||||
void SendCoinsDialog::on_sendButton_clicked()
|
void SendCoinsDialog::on_sendButton_clicked()
|
||||||
{
|
{
|
||||||
QByteArray payTo = ui->payTo->text().toUtf8();
|
bool valid;
|
||||||
uint160 payToHash = 0;
|
QString payAmount = ui->payAmount->text();
|
||||||
int64 payAmount = 0.0;
|
qint64 payAmountParsed;
|
||||||
bool valid = false;
|
|
||||||
|
|
||||||
if(!AddressToHash160(payTo.constData(), payToHash))
|
valid = ParseMoney(payAmount.toStdString(), payAmountParsed);
|
||||||
|
|
||||||
|
if(!valid)
|
||||||
{
|
{
|
||||||
QMessageBox::warning(this, tr("Warning"),
|
QMessageBox::warning(this, tr("Send Coins"),
|
||||||
tr("The recepient address is not valid, please recheck."),
|
tr("The amount to pay must be a valid number."),
|
||||||
QMessageBox::Ok,
|
QMessageBox::Ok, QMessageBox::Ok);
|
||||||
QMessageBox::Ok);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(model->sendCoins(ui->payTo->text(), payAmountParsed))
|
||||||
|
{
|
||||||
|
case ClientModel::InvalidAddress:
|
||||||
|
QMessageBox::warning(this, tr("Send Coins"),
|
||||||
|
tr("The recepient address is not valid, please recheck."),
|
||||||
|
QMessageBox::Ok, QMessageBox::Ok);
|
||||||
ui->payTo->setFocus();
|
ui->payTo->setFocus();
|
||||||
return;
|
break;
|
||||||
}
|
case ClientModel::InvalidAmount:
|
||||||
valid = ParseMoney(ui->payAmount->text().toStdString(), payAmount);
|
QMessageBox::warning(this, tr("Send Coins"),
|
||||||
|
tr("The amount to pay must be larger than 0."),
|
||||||
if(!valid || payAmount <= 0)
|
QMessageBox::Ok, QMessageBox::Ok);
|
||||||
{
|
|
||||||
QMessageBox::warning(this, tr("Warning"),
|
|
||||||
tr("The amount to pay must be a valid number larger than 0."),
|
|
||||||
QMessageBox::Ok,
|
|
||||||
QMessageBox::Ok);
|
|
||||||
ui->payAmount->setFocus();
|
ui->payAmount->setFocus();
|
||||||
return;
|
break;
|
||||||
|
case ClientModel::AmountExceedsBalance:
|
||||||
|
QMessageBox::warning(this, tr("Send Coins"),
|
||||||
|
tr("Amount exceeds your balance"),
|
||||||
|
QMessageBox::Ok, QMessageBox::Ok);
|
||||||
|
ui->payAmount->setFocus();
|
||||||
|
break;
|
||||||
|
case ClientModel::AmountWithFeeExceedsBalance:
|
||||||
|
QMessageBox::warning(this, tr("Send Coins"),
|
||||||
|
tr("Total exceeds your balance when the %1 transaction fee is included").
|
||||||
|
arg(QString::fromStdString(FormatMoney(model->getTransactionFee()))),
|
||||||
|
QMessageBox::Ok, QMessageBox::Ok);
|
||||||
|
ui->payAmount->setFocus();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
qDebug() << "Pay " << payAmount;
|
|
||||||
|
|
||||||
/* TODO: send command to core, once this succeeds do accept() */
|
/* TODO: send command to core, once this succeeds do accept() */
|
||||||
accept();
|
//accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendCoinsDialog::on_pasteButton_clicked()
|
void SendCoinsDialog::on_pasteButton_clicked()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user