Skip to content

Commit

Permalink
Adapt GUI to the latest CTransactionRef migration changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Feb 15, 2021
1 parent 362366b commit 7e1aa0d
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/qt/pivx/masternodewizarddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,11 @@ bool MasterNodeWizardDialog::createMN()
}

// look for the tx index of the collateral
CWalletTx* walletTx = currentTransaction.getTransaction();
CTransactionRef walletTx = currentTransaction.getTransaction();
std::string txID = walletTx->GetHash().GetHex();
int indexOut = -1;
for (int i=0; i < (int)walletTx->tx->vout.size(); i++) {
const CTxOut& out = walletTx->tx->vout[i];
for (int i=0; i < (int)walletTx->vout.size(); i++) {
const CTxOut& out = walletTx->vout[i];
if (out.nValue == 10000 * COIN) {
indexOut = i;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ OperationResult SendWidget::prepareTransparent(WalletModelTransaction* currentTr
bool SendWidget::sendFinalStep()
{
showHideOp(true);
const bool fStakeDelegationVoided = ptrModelTx->getTransaction()->fStakeDelegationVoided;
const bool fStakeDelegationVoided = ptrModelTx->fIsStakeDelegationVoided;
QString warningStr = QString();
if (fStakeDelegationVoided)
warningStr = tr("WARNING:\nTransaction spends a cold-stake delegation, voiding it.\n"
Expand Down
24 changes: 12 additions & 12 deletions src/qt/pivx/sendconfirmdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ TxDetailDialog::TxDetailDialog(QWidget *parent, bool _isConfirmDialog, const QSt
connect(ui->pushOutputs, &QPushButton::clicked, this, &TxDetailDialog::onOutputsClicked);
}

void TxDetailDialog::setInputsType(const CWalletTx* _tx)
void TxDetailDialog::setInputsType(CTransactionRef tx)
{
if (_tx->tx->sapData && _tx->tx->sapData->vShieldedSpend.empty()) {
if (tx->sapData && tx->sapData->vShieldedSpend.empty()) {
ui->labelTitlePrevTx->setText(tr("Previous Transaction"));
ui->labelOutputIndex->setText(tr("Output Index"));
} else {
Expand Down Expand Up @@ -126,7 +126,7 @@ void TxDetailDialog::setData(WalletModel *_model, const QModelIndex &index)
shieldedInputsExtraMsg = " shielded";
}

setInputsType(_tx);
setInputsType(_tx->tx);
int inputsSize = (_tx->tx->sapData && !_tx->tx->sapData->vShieldedSpend.empty()) ? _tx->tx->sapData->vShieldedSpend.size() : _tx->tx->vin.size();
ui->textInputs->setText(QString::number(inputsSize) + shieldedInputsExtraMsg);
ui->textConfirmations->setText(QString::number(rec->status.depth));
Expand Down Expand Up @@ -186,7 +186,7 @@ void TxDetailDialog::setData(WalletModel *_model, WalletModelTransaction* _tx)
CAmount totalAmount = tx->getTotalTransactionAmount() + txFee;

// inputs label
CWalletTx* walletTx = tx->getTransaction();
CTransactionRef walletTx = tx->getTransaction();
setInputsType(walletTx);

ui->textAmount->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, totalAmount, false, BitcoinUnits::separatorAlways) + " (Fee included)");
Expand Down Expand Up @@ -226,7 +226,7 @@ void TxDetailDialog::setData(WalletModel *_model, WalletModelTransaction* _tx)
ui->labelDividerMemo->setVisible(false);
}

int inputsSize = (walletTx->tx->sapData && !walletTx->tx->sapData->vShieldedSpend.empty()) ? walletTx->tx->sapData->vShieldedSpend.size() : walletTx->tx->vin.size();
int inputsSize = (walletTx->sapData && !walletTx->sapData->vShieldedSpend.empty()) ? walletTx->sapData->vShieldedSpend.size() : walletTx->vin.size();
ui->textInputs->setText(QString::number(inputsSize));
ui->textFee->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, txFee, false, BitcoinUnits::separatorAlways));
}
Expand Down Expand Up @@ -260,24 +260,24 @@ void TxDetailDialog::onInputsClicked()
if (!inputsLoaded) {
inputsLoaded = true;
if (showGrid) {
const CWalletTx* walletTx = (this->tx) ? this->tx->getTransaction() : model->getTx(this->txHash);
CTransactionRef walletTx = (this->tx) ? this->tx->getTransaction() : model->getTx(this->txHash)->tx;
if (walletTx) {
if (walletTx->tx->sapData && walletTx->tx->sapData->vShieldedSpend.empty()) {
if (walletTx->sapData && walletTx->sapData->vShieldedSpend.empty()) {
// transparent inputs
ui->gridInputs->setMinimumHeight(50 + (50 * walletTx->tx->vin.size()));
ui->gridInputs->setMinimumHeight(50 + (50 * walletTx->vin.size()));
int i = 1;
for (const CTxIn& in : walletTx->tx->vin) {
for (const CTxIn& in : walletTx->vin) {
QString hash = QString::fromStdString(in.prevout.hash.GetHex());
loadInputs(hash.left(18) + "..." + hash.right(18),
QString::number(in.prevout.n),
ui->gridLayoutInput, i);
i++;
}
} else {
ui->gridInputs->setMinimumHeight(50 + (50 * walletTx->tx->sapData->vShieldedSpend.size()));
ui->gridInputs->setMinimumHeight(50 + (50 * walletTx->sapData->vShieldedSpend.size()));
bool fInfoAvailable = false;
for (int i = 0; i < (int) walletTx->tx->sapData->vShieldedSpend.size(); ++i) {
Optional<QString> opAddr = model->getShieldedAddressFromSpendDesc(walletTx, i);
for (int i = 0; i < (int) walletTx->sapData->vShieldedSpend.size(); ++i) {
Optional<QString> opAddr = model->getShieldedAddressFromSpendDesc(walletTx->GetHash(), i);
if (opAddr) {
QString addr = *opAddr;
loadInputs(addr.left(18) + "..." + addr.right(18),
Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/sendconfirmdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Q_SLOTS:
bool inputsLoaded = false;
bool outputsLoaded = false;

void setInputsType(const CWalletTx* _tx);
void setInputsType(CTransactionRef _tx);
};

#endif // SENDCONFIRMDIALOG_H
4 changes: 2 additions & 2 deletions src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ void TransactionRecord::loadHotOrColdStakeOrContract(
}

bool isSpendable = (wallet->IsMine(p2csUtxo) & ISMINE_SPENDABLE_DELEGATED);
bool isFromMe = wallet->IsFromMe(wtx);
bool isFromMe = wallet->IsFromMe(wtx.tx);

if (isContract) {
if (isSpendable && isFromMe) {
Expand Down Expand Up @@ -611,7 +611,7 @@ void TransactionRecord::updateStatus(const CWalletTx& wtx)
status.cur_num_blocks = chainHeight;
status.depth = depth;

if (!IsFinalTx(wtx, chainHeight + 1)) {
if (!IsFinalTx(wtx.tx, chainHeight + 1)) {
if (wtx.tx->nLockTime < LOCKTIME_THRESHOLD) {
status.status = TransactionStatus::OpenUntilBlock;
status.open_for = wtx.tx->nLockTime - chainHeight;
Expand Down
7 changes: 4 additions & 3 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
ALL_COINS,
true,
0,
fIncludeDelegations);
fIncludeDelegations,
&transaction->fIsStakeDelegationVoided);
transaction->setTransactionFee(nFeeRequired);

if (!fCreated) {
Expand Down Expand Up @@ -1081,8 +1082,8 @@ bool WalletModel::isUsed(CTxDestination address)
return wallet->IsUsed(address);
}

Optional<QString> WalletModel::getShieldedAddressFromSpendDesc(const CWalletTx* wtx, int index)
Optional<QString> WalletModel::getShieldedAddressFromSpendDesc(const uint256& txHash, int index)
{
Optional<libzcash::SaplingPaymentAddress> opAddr = wallet->GetSaplingScriptPubKeyMan()->GetAddressFromInputIfPossible(wtx, index);
Optional<libzcash::SaplingPaymentAddress> opAddr = wallet->GetSaplingScriptPubKeyMan()->GetAddressFromInputIfPossible(txHash, index);
return opAddr ? Optional<QString>(QString::fromStdString(KeyIO::EncodePaymentAddress(*opAddr))) : nullopt;
}
2 changes: 1 addition & 1 deletion src/qt/walletmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class WalletModel : public QObject
bool validateAddress(const QString& address, bool fStaking, bool& isShielded);

// Return the address from where the shielded spend is taking the funds from (if possible)
Optional<QString> getShieldedAddressFromSpendDesc(const CWalletTx* wtx, int index);
Optional<QString> getShieldedAddressFromSpendDesc(const uint256& txHash, int index);

// Return status record for SendCoins, contains error id + information
struct SendCoinsReturn {
Expand Down
1 change: 1 addition & 0 deletions src/qt/walletmodeltransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class WalletModelTransaction

// Whether should create a +v2 tx or go simple and create a v1.
bool useV2{false};
bool fIsStakeDelegationVoided{false};

private:
const QList<SendCoinsRecipient> recipients;
Expand Down
8 changes: 8 additions & 0 deletions src/sapling/saplingscriptpubkeyman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,14 @@ void SaplingScriptPubKeyMan::GetFilteredNotes(
}
}

Optional<libzcash::SaplingPaymentAddress>
SaplingScriptPubKeyMan::GetAddressFromInputIfPossible(const uint256& txHash, int index) const
{
const CWalletTx* wtx = wallet->GetWalletTx(txHash);
if (!wtx) return nullopt;
return GetAddressFromInputIfPossible(wtx, index);
}

Optional<libzcash::SaplingPaymentAddress>
SaplingScriptPubKeyMan::GetAddressFromInputIfPossible(const CWalletTx* wtx, int index) const
{
Expand Down
1 change: 1 addition & 0 deletions src/sapling/saplingscriptpubkeyman.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ class SaplingScriptPubKeyMan {

//! Return the address from where the shielded spend is taking the funds from (if possible)
Optional<libzcash::SaplingPaymentAddress> GetAddressFromInputIfPossible(const CWalletTx* wtx, int index) const;
Optional<libzcash::SaplingPaymentAddress> GetAddressFromInputIfPossible(const uint256& txHash, int index) const;

//! Whether the nullifier is from this wallet
bool IsSaplingNullifierFromMe(const uint256& nullifier) const;
Expand Down
6 changes: 5 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2725,7 +2725,8 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend,
AvailableCoinsType coin_type,
bool sign,
CAmount nFeePay,
bool fIncludeDelegated)
bool fIncludeDelegated,
bool* fStakeDelegationVoided)
{
CAmount nValue = 0;
int nChangePosRequest = nChangePosInOut;
Expand Down Expand Up @@ -2856,6 +2857,9 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend,

// Fill vin
for (const std::pair<const CWalletTx*, unsigned int>& coin : setCoins) {
if(coin.first->tx->vout[coin.second].scriptPubKey.IsPayToColdStaking()) {
*fStakeDelegationVoided = true;
}
txNew.vin.emplace_back(coin.first->GetHash(), coin.second);
}

Expand Down
3 changes: 2 additions & 1 deletion src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,8 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
AvailableCoinsType coin_type = ALL_COINS,
bool sign = true,
CAmount nFeePay = 0,
bool fIncludeDelegated = false);
bool fIncludeDelegated = false,
bool* fStakeDelegationVoided = nullptr);
bool CreateTransaction(CScript scriptPubKey, const CAmount& nValue, CTransactionRef& tx, CReserveKey& reservekey, CAmount& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl = NULL, AvailableCoinsType coin_type = ALL_COINS, CAmount nFeePay = 0, bool fIncludeDelegated = false);

// enumeration for CommitResult (return status of CommitTransaction)
Expand Down

0 comments on commit 7e1aa0d

Please sign in to comment.