Skip to content
Permalink
Browse files

refactor timelock/send closer to original suqa/hodl code

  • Loading branch information...
barrystyle committed Feb 23, 2019
1 parent c46d3ae commit d8b7aafe4cb48c6d1b2e664fdd091045816f73d0
@@ -125,9 +125,6 @@ DepositCoinsDialog::DepositCoinsDialog(const PlatformStyle *_platformStyle, QWid
ui->customFee->setValue(settings.value("nTransactionFee").toLongLong());
ui->checkBoxMinimumFee->setChecked(settings.value("fPayOnlyMinFee").toBool());
minimizeFeeSection(settings.value("fFeeSectionMinimized").toBool());

ui->addButton->hide();
ui->clearButton->hide();
}

void DepositCoinsDialog::setClientModel(ClientModel *_clientModel)
@@ -164,7 +161,7 @@ void DepositCoinsDialog::setModel(WalletModel *_model)
// Coin Control
connect(_model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(coinControlUpdateLabels()));
connect(_model->getOptionsModel(), SIGNAL(coinControlFeaturesChanged(bool)), this, SLOT(coinControlFeatureChanged(bool)));
// ui->frameCoinControl->setVisible(_model->getOptionsModel()->getCoinControlFeatures());
ui->frameCoinControl->setVisible(_model->getOptionsModel()->getCoinControlFeatures());
coinControlUpdateLabels();

// fee section
@@ -234,9 +231,8 @@ void DepositCoinsDialog::on_sendButton_clicked()
if(entry->validate(model->node()))
{
recipients.append(entry->getValue());
termDepositBlocks = entry->getTermDepositLength();
if (termDepositBlocks >= 720 && termDepositBlocks < 730)
termDepositBlocks = 730;
termDepositBlocks=entry->getTermDepositLength();
if (termDepositBlocks >= 720 && termDepositBlocks < 730) termDepositBlocks = 730;
}
else
{
@@ -259,18 +255,17 @@ void DepositCoinsDialog::on_sendButton_clicked()
return;
}

// prepare transaction for getting txFee earlier
WalletModelTransaction currentTransaction(recipients);
WalletModel::SendCoinsReturn prepareStatus;

// Always use a CCoinControl instance, use the CoinControlDialog instance if CoinControl has been enabled
CCoinControl ctrl;
if (model->getOptionsModel()->getCoinControlFeatures())
ctrl = *CoinControlDialog::coinControl();

updateCoinControlState(ctrl);

// prepare transaction for getting txFee earlier
WalletModelTransaction currentTransaction(recipients);
WalletModel::SendCoinsReturn prepareStatus;
std::string termDepositConfirmQuestion = "";

prepareStatus = model->prepareTransaction(currentTransaction, termDepositConfirmQuestion, termDepositBlocks);

// process prepareStatus and on error generate message shown to user
@@ -295,10 +290,6 @@ void DepositCoinsDialog::on_sendButton_clicked()
}
}else{
QString questionString = QString::fromStdString("Something went wrong! No term deposit instruction was detected. Instruction will be cancelled.");
QMessageBox::StandardButton retval = QMessageBox::question(this, tr("No Term Deposit Detected"),
questionString,
QMessageBox::Yes | QMessageBox::Cancel,
QMessageBox::Cancel);
fNewRecipientAllowed = true;
return;
}
@@ -347,33 +338,18 @@ void DepositCoinsDialog::on_sendButton_clicked()
}

QString questionString = tr("Are you sure you want to send?");
questionString.append("<br /><span style='font-size:10pt;'>");
questionString.append(tr("Please, review your transaction."));
questionString.append("</span><br />%1");
questionString.append("<br /><br />%1");

if(txFee > 0)
{
// append fee string if a fee is required
questionString.append("<hr /><b>");
questionString.append(tr("Transaction fee"));
questionString.append("</b>");
questionString.append("<hr /><span style='color:#aa0000;'>");
questionString.append(BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), txFee));
questionString.append("</span> ");
questionString.append(tr("added as transaction fee"));

// append transaction size
questionString.append(" (" + QString::number((double)currentTransaction.getTransactionSize() / 1000) + " kB): ");

// append transaction fee value
questionString.append("<span style='color:#aa0000; font-weight:bold;'>");
questionString.append(BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), txFee));
questionString.append("</span><br />");

// append RBF message according to transaction's signalling
questionString.append("<span style='font-size:10pt; font-weight:normal;'>");
if (ui->optInRBF->isChecked()) {
questionString.append(tr("You can increase the fee later (signals Replace-By-Fee, BIP-125)."));
} else {
questionString.append(tr("Not signalling Replace-By-Fee, BIP-125."));
}
questionString.append("</span>");
questionString.append(" (" + QString::number((double)currentTransaction.getTransactionSize() / 1000) + " kB)");
}

// add total amount in all subdivision units
@@ -385,15 +361,14 @@ void DepositCoinsDialog::on_sendButton_clicked()
if(u != model->getOptionsModel()->getDisplayUnit())
alternativeUnits.append(BitcoinUnits::formatHtmlWithUnit(u, totalAmount));
}
questionString.append(QString("<b>%1</b>: <b>%2</b>").arg(tr("Total Amount"))
.arg(BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), totalAmount)));
questionString.append(QString("<br /><span style='font-size:10pt; font-weight:normal;'>(=%1)</span>")
.arg(alternativeUnits.join(" " + tr("or") + " ")));
questionString.append(tr("Total Amount %1<span style='font-size:10pt;font-weight:normal;'><br />(=%2)</span>")
.arg(BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), totalAmount))
.arg(alternativeUnits.join(" " + tr("or") + "<br />")));

DepositConfirmationDialog confirmationDialog(tr("Confirm send coins"),
questionString.arg(formatted.join("<br />")), SEND_CONFIRM_DELAY, this);
confirmationDialog.exec();
QMessageBox::StandardButton retval = static_cast<QMessageBox::StandardButton>(confirmationDialog.result());
QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm send coins"),
questionString.arg(formatted.join("<br />")),
QMessageBox::Yes | QMessageBox::Cancel,
QMessageBox::Cancel);

if(retval != QMessageBox::Yes)
{
BIN -1.35 MB (2.3%) src/qt/res/icons/suqa.ico
Binary file not shown.
@@ -179,39 +179,48 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
++nAddresses;

CScript scriptPubKey;
CTxDestination address = DecodeDestination(rcp.address.toStdString());
if(termDepositLength>0) {
std::ostringstream ss;
if(termDepositLength < 720*1) {
ss << "!!!!!WARNING: There is no interest rate advantage of using a Term Deposit for a period of less than 1 day. It is recommended that you cancel this transaction. ";
ss <<"!!!!!WARNING: There is no interest rate advantage of using a Term Deposit for a period of less than 1 day. It is recommended that you cancel this transaction. ";
}
if(termDepositLength > 720*30){
ss << "!!!!!WARNING: There is no interest rate advantage of using a Term Deposit for a period of more than 1 month. It is recommended that you cancel this transaction. ";
ss <<"!!!!!WARNING: There is no interest rate advantage of using a Term Deposit for a period of more than 1 month. It is recommended that you cancel this transaction. ";
}
ss << "Term Deposit Instruction Detected: " << std::fixed;
ss <<"Term Deposit Instruction Detected: " << std::fixed;
ss.precision(8);
ss << "This will send the amount of " << (0.0+rcp.amount)/COIN <<" SUQA ";
ss << "to be locked for " << termDepositLength << " blocks. ";
ss <<"This will send the amount of " << (0.0+rcp.amount)/COIN <<" SUQA ";
ss <<"to be locked for " << termDepositLength << " blocks. ";
ss.precision(2);
ss << "This is approximately " << (0.0+termDepositLength)/(720) << " days. ";
ss <<"This is approximately " << (0.0+termDepositLength)/(720) << " days. ";
CAmount withInterest=GetInterest(rcp.amount, chainActive.Height()+1, chainActive.Height()+1+termDepositLength, chainActive.Height()+1+termDepositLength);
ss.precision(8);
ss << "Upon maturation, it will be worth " << (0.0+withInterest)/COIN << " SUQA. ";
ss <<"Upon maturation, it will be worth " << (0.0+withInterest)/COIN << " SUQA. ";
termdepositquestion = ss.str();
CTxDestination address = DecodeDestination(rcp.address.toStdString());
scriptPubKey = GetTimeLockScriptForDestination(address,chainActive.Height()+1+termDepositLength);
}else{
CTxDestination address = DecodeDestination(rcp.address.toStdString());
scriptPubKey = GetScriptForDestination(address);
}

CRecipient recipient = {scriptPubKey, rcp.amount, rcp.fSubtractFeeFromAmount};
vecSend.push_back(recipient);

total += rcp.amount;
}
}
if(setAddress.size() != nAddresses)
{
return DuplicateAddress;
}

CAmount nBalance = m_wallet->getBalance();

if(total > nBalance)
{
return AmountExceedsBalance;
}

{
CAmount nFeeRequired = 0;
int nChangePosRet = -1;
@@ -220,11 +229,15 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
auto& newTx = transaction.getWtx();
newTx = m_wallet->createTransaction(vecSend, coinControl, true, nChangePosRet, nFeeRequired, strFailReason);
transaction.setTransactionFee(nFeeRequired);
if (fSubtractFeeFromAmount)
if (fSubtractFeeFromAmount && newTx)
transaction.reassignAmounts(nChangePosRet);

if(!newTx)
{
if(!fSubtractFeeFromAmount && (total + nFeeRequired) > nBalance)
{
return SendCoinsReturn(AmountWithFeeExceedsBalance);
}
Q_EMIT message(tr("Send Coins"), QString::fromStdString(strFailReason),
CClientUIInterface::MSG_ERROR);
return TransactionCreationFailed;
@@ -8,6 +8,18 @@
#include <tinyformat.h>
#include <utilstrencodings.h>

namespace {
inline std::string ValueString(const std::vector<unsigned char>& vch)
{
if (vch.size() <= 4)
return strprintf("%d", CScriptNum(vch, false).getint());
else
return HexStr(vch);
}
} // anon namespace

using namespace std;

const char* GetOpName(opcodetype opcode)
{
switch (opcode)
@@ -130,7 +142,7 @@ const char* GetOpName(opcodetype opcode)
// expansion
case OP_NOP1 : return "OP_NOP1";
case OP_NOP2 : return "OP_CHECKLOCKTIMEVERIFY";
case OP_CHECKSEQUENCEVERIFY : return "OP_CHECKSEQUENCEVERIFY";
case OP_NOP3 : return "OP_NOP3";
case OP_NOP4 : return "OP_NOP4";
case OP_NOP5 : return "OP_NOP5";
case OP_NOP6 : return "OP_NOP6";
@@ -203,12 +215,8 @@ bool CScript::IsPayToScriptHash() const
(*this)[22] == OP_EQUAL);
}

bool CScript::IsCheckLockTimeVerify() const
{
// Extra-fast test for pay-to-script-hash CScripts:
return (this->size() == 31 &&
(*this)[7] == OP_HASH160 &&
(*this)[8] == 0x14);
bool CScript::IsTermDeposit() const{
return GetTermDepositReleaseBlock()>-1;
}

bool CScript::IsPayToWitnessScriptHash() const
@@ -254,14 +262,11 @@ bool CScript::IsPushOnly(const_iterator pc) const
return true;
}

bool CScript::IsTermDeposit() const{
return GetTermDepositReleaseBlock() > -1;
}

int CScript::GetTermDepositReleaseBlock() const
{
if(this->size()<29 || this->size()>32 || (*this)[0] > 4 || (*this)[0] == 0)
if(this->size()<29 || this->size()>32 || (*this)[0] > 4 || (*this)[0] == 0){
return -1;
}
int skipsize=(*this)[0];

if((*this)[skipsize+1] != OP_CHECKLOCKTIMEVERIFY ||
@@ -273,7 +278,7 @@ int CScript::GetTermDepositReleaseBlock() const
return -1;
}

std::vector<unsigned char> vch1;
vector<unsigned char> vch1;
CScript::const_iterator pc1 = this->begin();
opcodetype opcode1;
this->GetOp(pc1, opcode1, vch1);
@@ -169,18 +169,26 @@ enum opcodetype

// expansion
OP_NOP1 = 0xb0,
OP_CHECKLOCKTIMEVERIFY = 0xb1,
OP_NOP2 = OP_CHECKLOCKTIMEVERIFY,
OP_CHECKSEQUENCEVERIFY = 0xb2,
OP_NOP3 = OP_CHECKSEQUENCEVERIFY,
OP_NOP2 = 0xb1,
OP_CHECKLOCKTIMEVERIFY = OP_NOP2,
OP_NOP3 = 0xb2,
OP_CHECKSEQUENCEVERIFY = OP_NOP3,
OP_NOP4 = 0xb3,
OP_NOP5 = 0xb4,
OP_NOP6 = 0xb5,
OP_NOP7 = 0xb6,
OP_NOP8 = 0xb7,
OP_NOP9 = 0xb8,
OP_NOP10 = 0xb9,


// template matching params
OP_SMALLDATA = 0xf9,
OP_SMALLINTEGER = 0xfa,
OP_PUBKEYS = 0xfb,
OP_LOCKTIMEINTEGER = 0xfc,
OP_PUBKEYHASH = 0xfd,
OP_PUBKEY = 0xfe,

OP_INVALIDOPCODE = 0xff,
};

0 comments on commit d8b7aaf

Please sign in to comment.
You can’t perform that action at this time.