Skip to content

Commit

Permalink
Merge pull request bitcoin#726 from sickpig/coin_freeze_cltv
Browse files Browse the repository at this point in the history
Basic wallet ui with CLTV coin freeze, watch & spend
  • Loading branch information
gandrewstone authored Aug 5, 2017
2 parents f955157 + e196a72 commit db05363
Show file tree
Hide file tree
Showing 46 changed files with 1,643 additions and 413 deletions.
3 changes: 3 additions & 0 deletions contrib/bitcoin-qt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ FORMS += \
../src/qt/forms/openuridialog.ui \
../src/qt/forms/optionsdialog.ui \
../src/qt/forms/overviewpage.ui \
../src/qt/forms/receivefreezedialog.ui \
../src/qt/forms/receivecoinsdialog.ui \
../src/qt/forms/receiverequestdialog.ui \
../src/qt/forms/debugwindow.ui \
Expand All @@ -17,5 +18,7 @@ FORMS += \
../src/qt/forms/signverifymessagedialog.ui \
../src/qt/forms/transactiondescdialog.ui \



RESOURCES += \
../src/qt/bitcoin.qrc
4 changes: 4 additions & 0 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ QT_FORMS_UI = \
qt/forms/overviewpage.ui \
qt/forms/receivecoinsdialog.ui \
qt/forms/receiverequestdialog.ui \
qt/forms/receivefreezedialog.ui \
qt/forms/debugwindow.ui \
qt/forms/sendcoinsdialog.ui \
qt/forms/sendcoinsentry.ui \
Expand Down Expand Up @@ -137,6 +138,7 @@ QT_MOC_CPP = \
qt/moc_qvaluecombobox.cpp \
qt/moc_receivecoinsdialog.cpp \
qt/moc_receiverequestdialog.cpp \
qt/moc_receivefreezedialog.cpp \
qt/moc_recentrequeststablemodel.cpp \
qt/moc_rpcconsole.cpp \
qt/moc_sendcoinsdialog.cpp \
Expand Down Expand Up @@ -209,6 +211,7 @@ BITCOIN_QT_H = \
qt/qvaluecombobox.h \
qt/receivecoinsdialog.h \
qt/receiverequestdialog.h \
qt/receivefreezedialog.h \
qt/recentrequeststablemodel.h \
qt/rpcconsole.h \
qt/sendcoinsdialog.h \
Expand Down Expand Up @@ -324,6 +327,7 @@ BITCOIN_QT_CPP += \
qt/paymentserver.cpp \
qt/receivecoinsdialog.cpp \
qt/receiverequestdialog.cpp \
qt/receivefreezedialog.cpp \
qt/recentrequeststablemodel.cpp \
qt/sendcoinsdialog.cpp \
qt/sendcoinsentry.cpp \
Expand Down
2 changes: 1 addition & 1 deletion src/bloom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ bool CBloomFilter::IsRelevantAndUpdate(const CTransaction& tx)
txnouttype type;
vector<vector<unsigned char> > vSolutions;
if (Solver(txout.scriptPubKey, type, vSolutions) &&
(type == TX_PUBKEY || type == TX_MULTISIG))
(type == TX_PUBKEY || type == TX_MULTISIG || type == TX_CLTV))
insert(COutPoint(hash, i));
}
break;
Expand Down
2 changes: 2 additions & 0 deletions src/policy/policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType)
return false;
if (m < 1 || m > n)
return false;
} else if (whichType == TX_CLTV) {
return true; // CLTV Freeze are standard enable(disable)
} else if (whichType == TX_NULL_DATA &&
(!fAcceptDatacarrier || scriptPubKey.size() > nMaxDatacarrierBytes))
return false;
Expand Down
41 changes: 37 additions & 4 deletions src/qt/addresstablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <QFont>
#include <QDebug>
#include <QDateTime>

const QString AddressTableModel::Send = "S";
const QString AddressTableModel::Receive = "R";
Expand Down Expand Up @@ -85,7 +86,7 @@ class AddressTablePriv
BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& item, wallet->mapAddressBook)
{
const CBitcoinAddress& address = item.first;
bool fMine = IsMine(*wallet, address.Get());
bool fMine = wallet->IsMine(address.Get());
AddressTableEntry::Type addressType = translateTransactionType(
QString::fromStdString(item.second.purpose), fMine);
const std::string& strName = item.second.name;
Expand Down Expand Up @@ -343,7 +344,7 @@ void AddressTableModel::updateEntry(const QString &address,
priv->updateEntry(address, label, isMine, purpose, status);
}

QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address)
QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address, const CScriptNum nFreezeLockTime)
{
std::string strLabel = label.toStdString();
std::string strAddress = address.toStdString();
Expand Down Expand Up @@ -386,7 +387,14 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
return QString();
}
}
strAddress = CBitcoinAddress(newKey.GetID()).ToString();
// Generate and load freeze script if nFreezeLockTime > 0
if (nFreezeLockTime > 0)
{
if (!wallet->LoadFreezeScript(newKey, nFreezeLockTime, strLabel, strAddress))
return QString();
}
else
strAddress = CBitcoinAddress(newKey.GetID()).ToString();
}
else
{
Expand Down Expand Up @@ -423,14 +431,39 @@ bool AddressTableModel::removeRows(int row, int count, const QModelIndex &parent
*/
QString AddressTableModel::labelForAddress(const QString &address) const
{
QString returnLabel = "";
{
LOCK(wallet->cs_wallet);
CBitcoinAddress address_parsed(address.toStdString());
std::map<CTxDestination, CAddressBookData>::iterator mi = wallet->mapAddressBook.find(address_parsed.Get());
if (mi != wallet->mapAddressBook.end())
{
return QString::fromStdString(mi->second.name);
returnLabel = QString::fromStdString(mi->second.name);
}


}
return returnLabel;

}

/* Look up label for freeze in wallet, if not found return empty string.
*/
QString AddressTableModel::labelForFreeze(const QString &address) const
{
{
LOCK(wallet->cs_wallet);
CBitcoinAddress address_parsed(address.toStdString());
CScript dest = GetScriptForDestination(address_parsed.Get());
CScriptNum nFreezeLockTime(0);
if (isFreezeCLTV(*wallet, dest, nFreezeLockTime))
{
if (nFreezeLockTime.getint64() < LOCKTIME_THRESHOLD)
return (QString)("Block:") + QString::number(nFreezeLockTime.getint());
else
return QDateTime::fromMSecsSinceEpoch(nFreezeLockTime.getint64() * 1000).toString();
}

}
return QString();
}
Expand Down
5 changes: 4 additions & 1 deletion src/qt/addresstablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#ifndef BITCOIN_QT_ADDRESSTABLEMODEL_H
#define BITCOIN_QT_ADDRESSTABLEMODEL_H

#include "script/script.h" // Freeze CScriptNum

#include <QAbstractTableModel>
#include <QStringList>

Expand Down Expand Up @@ -62,11 +64,12 @@ class AddressTableModel : public QAbstractTableModel
/* Add an address to the model.
Returns the added address on success, and an empty string otherwise.
*/
QString addRow(const QString &type, const QString &label, const QString &address);
QString addRow(const QString &type, const QString &label, const QString &address, const CScriptNum nFreezeLockTime);

/* Look up label for address in address book, if not found return empty string.
*/
QString labelForAddress(const QString &address) const;
QString labelForFreeze(const QString &address) const;

/* Look up row index of an address in the model.
Return -1 if not found.
Expand Down
2 changes: 1 addition & 1 deletion src/qt/editaddressdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool EditAddressDialog::saveCurrentRow()
address = model->addRow(
mode == NewSendingAddress ? AddressTableModel::Send : AddressTableModel::Receive,
ui->labelEdit->text(),
ui->addressEdit->text());
ui->addressEdit->text(), CScriptNum(0));
break;
case EditReceivingAddress:
case EditSendingAddress:
Expand Down
Loading

0 comments on commit db05363

Please sign in to comment.