1 #include "clientmodel.h"
3 #include "guiconstants.h"
4 #include "optionsmodel.h"
8 ClientModel::ClientModel(QObject *parent) :
9 QObject(parent), options_model(0)
11 /* Until we build signal notifications into the bitcoin core,
12 simply update everything using a timer.
14 QTimer *timer = new QTimer(this);
15 connect(timer, SIGNAL(timeout()), this, SLOT(update()));
16 timer->start(MODEL_UPDATE_DELAY);
18 options_model = new OptionsModel(this);
21 qint64 ClientModel::getBalance()
26 QString ClientModel::getAddress()
28 std::vector<unsigned char> vchPubKey;
29 if (CWalletDB("r").ReadDefaultKey(vchPubKey))
31 return QString::fromStdString(PubKeyToAddress(vchPubKey));
37 int ClientModel::getNumConnections()
42 int ClientModel::getNumBlocks()
47 int ClientModel::getNumTransactions()
49 int numTransactions = 0;
50 CRITICAL_BLOCK(cs_mapWallet)
52 numTransactions = mapWallet.size();
54 return numTransactions;
57 void ClientModel::update()
59 emit balanceChanged(getBalance());
60 emit addressChanged(getAddress());
61 emit numConnectionsChanged(getNumConnections());
62 emit numBlocksChanged(getNumBlocks());
63 emit numTransactionsChanged(getNumTransactions());
66 ClientModel::StatusCode ClientModel::sendCoins(const QString &payTo, qint64 payAmount)
71 if(!AddressToHash160(payTo.toUtf8().constData(), hash160))
73 return InvalidAddress;
81 if(payAmount > getBalance())
83 return AmountExceedsBalance;
86 if((payAmount + nTransactionFee) > getBalance())
88 return AmountWithFeeExceedsBalance;
91 CRITICAL_BLOCK(cs_main)
93 // Send to bitcoin address
96 scriptPubKey << OP_DUP << OP_HASH160 << hash160 << OP_EQUALVERIFY << OP_CHECKSIG;
98 std::string strError = SendMoney(scriptPubKey, payAmount, wtx, true);
101 else if (strError == "ABORTED")
105 emit error(tr("Sending..."), QString::fromStdString(strError));
113 OptionsModel *ClientModel::getOptionsModel()
115 return options_model;