From 9b386365b094036f2fe86daecd8125380b3143b9 Mon Sep 17 00:00:00 2001 From: Block Mechanic Date: Sat, 4 Jun 2022 09:40:35 +0200 Subject: [PATCH 1/3] t --- src/chainparams.cpp | 4 +- src/interfaces/wallet.cpp | 12 +++--- src/qt/forms/sendcoinsentry.ui | 69 ++++++++++++++++++++++++++++++-- src/qt/overviewpage.cpp | 7 +++- src/qt/sendcoinsentry.cpp | 21 ++++++++++ src/qt/sendcoinsentry.h | 5 +++ src/qt/transactionrecord.cpp | 12 +++++- src/wallet/wallet.cpp | 73 ++++++++++++++++++++-------------- 8 files changed, 158 insertions(+), 45 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index a7ffbee..265a0bc 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -292,10 +292,10 @@ class CTestNetParams : public CChainParams { m_assumed_blockchain_size = 1; m_assumed_chain_state_size = 1; - genesis = CreateGenesisBlock(1652728167, 313229, 0x1e0ffff0, 1, 10 * COIN, consensus); + genesis = CreateGenesisBlock(1654102950, 194002, 0x1e0ffff0, 1, 10 * COIN, consensus); consensus.hashGenesisBlock = genesis.GetHash(); //MineNewGenesisBlock(consensus,genesis); - assert(consensus.hashGenesisBlock == uint256S("0x000002e98cb578ba29508547f36cf87f8aee2e94d8fcdd873ac41aa7e8f95e9c")); + assert(consensus.hashGenesisBlock == uint256S("0x00000a25d3a25466f7fae5b6803a68d7a158631111202ec194b37ee17de2401b")); assert(genesis.hashMerkleRoot == uint256S("0x80ad356118a9ab8db192db66ef77146cc36d958f959251feace550e4ca3d1446")); vFixedSeeds.clear(); diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp index ceca526..ae81c23 100644 --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -44,10 +44,12 @@ WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx) for (const auto& txin : wtx.tx->vin) { result.txin_is_mine.emplace_back(wallet.IsMine(txin)); } - result.txout_is_mine.reserve(wtx.tx->vout.size()); - result.txout_address.reserve(wtx.tx->vout.size()); - result.txout_address_is_mine.reserve(wtx.tx->vout.size()); - for (const auto& txout : wtx.tx->vout) { + result.txout_is_mine.reserve(wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout.size() : wtx.tx->vout.size()); + result.txout_address.reserve(wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout.size() : wtx.tx->vout.size()); + result.txout_address_is_mine.reserve(wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout.size() : wtx.tx->vout.size()); + for(unsigned int i = 0; i < (wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout.size() : wtx.tx->vout.size()) ; i++){ + CTxOutAsset txout = (wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout[i] : wtx.tx->vout[i]); + result.txout_is_mine.emplace_back(wallet.IsMine(txout)); result.txout_address.emplace_back(); result.txout_address_is_mine.emplace_back(ExtractDestination(txout.scriptPubKey, result.txout_address.back()) ? @@ -95,7 +97,7 @@ WalletTxOut MakeWalletTxOut(CWallet& wallet, int depth) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet) { WalletTxOut result; - result.txout = wtx.tx->vout[n]; + result.txout = (wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout[n] : wtx.tx->vout[n]); result.time = wtx.GetTxTime(); result.depth_in_main_chain = depth; result.is_spent = wallet.IsSpent(wtx.GetHash(), n); diff --git a/src/qt/forms/sendcoinsentry.ui b/src/qt/forms/sendcoinsentry.ui index 58b0e2d..e911153 100644 --- a/src/qt/forms/sendcoinsentry.ui +++ b/src/qt/forms/sendcoinsentry.ui @@ -163,12 +163,19 @@ - + - - The amount to send in the selected unit - + + The amount to send in the selected unit + + + + + + + Select Asset + @@ -358,6 +365,15 @@ + + + + 0 + 0 + 0 + + + @@ -495,6 +511,15 @@ + + + + 0 + 0 + 0 + + + @@ -632,6 +657,15 @@ + + + + 0 + 0 + 0 + + + @@ -869,6 +903,15 @@ + + + + 0 + 0 + 0 + + + @@ -1015,6 +1058,15 @@ + + + + 0 + 0 + 0 + + + @@ -1161,6 +1213,15 @@ + + + + 0 + 0 + 0 + + + diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index a3f4687..d9780c1 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -213,7 +213,9 @@ void OverviewPage::setBalance(const interfaces::WalletBalances& balances) ui->labelBalance->setText(formatMultiAssetAmount(balances.balance, unit, CrownUnits::SeparatorStyle::ALWAYS, "")); ui->labelUnconfirmed->setText(formatMultiAssetAmount(balances.unconfirmed_balance, unit, CrownUnits::SeparatorStyle::ALWAYS, "")); ui->labelImmature->setText(formatMultiAssetAmount(balances.immature_balance, unit, CrownUnits::SeparatorStyle::ALWAYS, "")); - ui->labelTotal->setText(formatMultiAssetAmount(balances.balance + balances.unconfirmed_balance + balances.immature_balance, unit, CrownUnits::SeparatorStyle::ALWAYS, "")); + CAmountMap nm = balances.balance + balances.unconfirmed_balance + balances.immature_balance; + + ui->labelTotal->setText(formatMultiAssetAmount(nm, unit, CrownUnits::SeparatorStyle::ALWAYS, "")); ui->labelWatchAvailable->setText(formatMultiAssetAmount(balances.watch_only_balance, unit, CrownUnits::SeparatorStyle::ALWAYS, "")); ui->labelWatchPending->setText(formatMultiAssetAmount(balances.unconfirmed_watch_only_balance, unit, CrownUnits::SeparatorStyle::ALWAYS, "")); ui->labelWatchImmature->setText(formatMultiAssetAmount(balances.immature_watch_only_balance, unit, CrownUnits::SeparatorStyle::ALWAYS, "")); @@ -224,7 +226,8 @@ void OverviewPage::setBalance(const interfaces::WalletBalances& balances) ui->labelBalance->setText(formatMultiAssetAmount(balances.balance, unit, CrownUnits::SeparatorStyle::ALWAYS, "")); ui->labelUnconfirmed->setText(formatMultiAssetAmount(balances.unconfirmed_balance, unit, CrownUnits::SeparatorStyle::ALWAYS, "")); ui->labelImmature->setText(formatMultiAssetAmount(balances.immature_balance, unit, CrownUnits::SeparatorStyle::ALWAYS, "")); - ui->labelTotal->setText(formatMultiAssetAmount(balances.balance + balances.unconfirmed_balance + balances.immature_balance, unit, CrownUnits::SeparatorStyle::ALWAYS, "")); + CAmountMap nm = balances.balance + balances.unconfirmed_balance + balances.immature_balance; + ui->labelTotal->setText(formatMultiAssetAmount(nm, unit, CrownUnits::SeparatorStyle::ALWAYS, "")); } // only show immature (newly mined) balance if it's non-zero, so as not to complicate things // for the non-mining users diff --git a/src/qt/sendcoinsentry.cpp b/src/qt/sendcoinsentry.cpp index ef4927b..8abbfca 100644 --- a/src/qt/sendcoinsentry.cpp +++ b/src/qt/sendcoinsentry.cpp @@ -18,6 +18,7 @@ #include #include +#include SendCoinsEntry::SendCoinsEntry(const PlatformStyle *_platformStyle, QWidget *parent) : QStackedWidget(parent), @@ -57,6 +58,26 @@ SendCoinsEntry::~SendCoinsEntry() delete ui; } + +void SendCoinsEntry::assetList(){ + // Keep up to date with wallet + interfaces::Wallet& wallet = model->wallet(); + m_balances = wallet.getBalances(); + QStringList list; + list << "CRW"; + + for(auto const& x : m_balances.balance){ + //assetListModel.append(); + list << QString::fromStdString(x.first.getName()); + } + + std::sort(list.begin(), list.end()); + + QStringListModel *a_model = new QStringListModel(); + a_model->setStringList(list); + ui->assetBox->setModel(a_model); +} + void SendCoinsEntry::on_pasteButton_clicked() { // Paste text from clipboard into recipient field diff --git a/src/qt/sendcoinsentry.h b/src/qt/sendcoinsentry.h index 01e4d4a..c8c6c99 100644 --- a/src/qt/sendcoinsentry.h +++ b/src/qt/sendcoinsentry.h @@ -6,6 +6,7 @@ #define CROWN_QT_SENDCOINSENTRY_H #include +#include #include @@ -50,6 +51,7 @@ class SendCoinsEntry : public QStackedWidget QWidget *setupTabChain(QWidget *prev); void setFocus(); + QList assetListModel; public Q_SLOTS: void clear(); @@ -74,8 +76,11 @@ private Q_SLOTS: Ui::SendCoinsEntry *ui; WalletModel *model; const PlatformStyle *platformStyle; + interfaces::WalletBalances m_balances; bool updateLabel(const QString &address); + void assetList(); + }; #endif // CROWN_QT_SENDCOINSENTRY_H diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index 0e9e486..4cdc302 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -44,7 +44,7 @@ QList TransactionRecord::decomposeTransaction(const interface CTxOutAsset txout = (wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout[i] : wtx.tx->vout[i]); //const CTxOut& txout = wtx.tx->vout[i]; - const CAsset& asset = wtx.txout_assets[i]; + //const CAsset& asset = wtx.txout_assets[i]; if (txout.IsFee()) { // explicit fee; ignore continue; @@ -106,8 +106,16 @@ QList TransactionRecord::decomposeTransaction(const interface } CAmountMap nChange = wtx.change; + TransactionRecord sub(hash, nTime); + sub.idx = 0; + sub.involvesWatchAddress = involvesWatchAddress; + sub.type = TransactionRecord::SendToSelf; + sub.address = address; + //sub.debit = -nValue; + //sub.credit = -nValue; + parts.append(sub); + //parts.append(TransactionRecord(hash, nTime, TransactionRecord::SendToSelf, address, (nDebit - nChange) * -1, nCredit - nChange)); - parts.last().involvesWatchAddress = involvesWatchAddress; // maybe pass to TransactionRecord as constructor argument } else if (fAllFromMe) { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 4a8b421..4b8ac5d 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1307,7 +1307,7 @@ CAmountMap CWallet::GetDebit(const CTxIn &txin, const isminefilter& filter) cons CAmountMap amounts; CTxOutAsset mout = (prev.tx->nVersion >= TX_ELE_VERSION ? prev.tx->vpout[txin.prevout.n] : prev.tx->vout[txin.prevout.n]); if (IsMine(mout) & filter) { - if(prev.tx->nVersion >= TX_ELE_VERSION) + if(prev.tx->nVersion >= TX_ELE_VERSION) amounts[prev.tx->vpout[txin.prevout.n].nAsset] = prev.tx->vpout[txin.prevout.n].nValue; else amounts[Params().GetConsensus().subsidy_asset] = prev.tx->vout[txin.prevout.n].nValue; @@ -2006,11 +2006,24 @@ CAmountMap CWalletTx::GetCredit(const isminefilter& filter) const CAmountMap CWalletTx::GetImmatureCredit(bool fUseCache) const { + CAmountMap nCredit; + uint256 hashTx = GetHash(); if (IsImmatureCoinBase() && IsInMainChain()) { - return GetCachableAmount(IMMATURE_CREDIT, ISMINE_SPENDABLE, !fUseCache); + + for(unsigned int i = 0; i < (tx->nVersion >= TX_ELE_VERSION ? tx->vpout.size() : tx->vout.size()) ; i++){ + //nCredit += pwallet->GetCredit(txout, filter); + CAmount credit = (tx->nVersion >= TX_ELE_VERSION ? tx->vpout[i].nValue : tx->vout[i].nValue); + if (!MoneyRange(credit)) + throw std::runtime_error(std::string(__func__) + " : value out of range"); + + if(tx->nVersion >= TX_ELE_VERSION) + nCredit[tx->vpout[i].nAsset] += credit; + else + nCredit[Params().GetConsensus().subsidy_asset] += credit; + } } - return CAmountMap(); + return nCredit; } CAmountMap CWalletTx::GetAvailableCredit(bool fUseCache, const isminefilter& filter) const @@ -2039,7 +2052,7 @@ CAmountMap CWalletTx::GetAvailableCredit(bool fUseCache, const isminefilter& fil CAmount credit = (tx->nVersion >= TX_ELE_VERSION ? tx->vpout[i].nValue : tx->vout[i].nValue); if (!MoneyRange(credit)) throw std::runtime_error(std::string(__func__) + " : value out of range"); - + if(tx->nVersion >= TX_ELE_VERSION) nCredit[tx->vpout[i].nAsset] += credit; else @@ -2734,7 +2747,7 @@ bool CWallet::GetMasternodeVinAndKeys(CTxIn& vinRet, CPubKey& pubKeyRet, CKey& k if(out.tx->GetHash() == txHash && out.i == nOutputIndex) // found it! return GetVinAndKeysFromOutput(out, vinRet, pubKeyRet, keyRet); - } + } LogPrintf("CWallet::GetMasternodeVinAndKeys - Could not locate specified masternode vin %s\n", strTxHash); return false; @@ -2766,8 +2779,8 @@ bool CWallet::GetSystemnodeVinAndKeys(CTxIn& vinRet, CPubKey& pubKeyRet, CKey& k if(out.tx->GetHash() == txHash && out.i == nOutputIndex) // found it! return GetVinAndKeysFromOutput(out, vinRet, pubKeyRet, keyRet); - - } + + } LogPrintf("CWallet::GetSystemnodeVinAndKeys - Could not locate specified servicenode vin\n"); return false; @@ -3060,7 +3073,7 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC } if (nChangePosInOut != -1) { - if(tx.nVersion >= TX_ELE_VERSION) + if(tx.nVersion >= TX_ELE_VERSION) tx.vpout.insert(tx.vpout.begin() + nChangePosInOut, tx_new->vpout[nChangePosInOut]); else tx.vout.insert(tx.vout.begin() + nChangePosInOut, tx_new->vout[nChangePosInOut]); @@ -3069,9 +3082,9 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC // Copy output sizes from new transaction; they may have had the fee // subtracted from them. for (unsigned int idx = 0; idx < (tx.nVersion >= TX_ELE_VERSION ? tx.vpout.size() : tx.vout.size()); idx++) { - if (tx.nVersion >= TX_ELE_VERSION) - tx.vpout[idx].nValue = tx_new->vpout[idx].nValue; - else + if (tx.nVersion >= TX_ELE_VERSION) + tx.vpout[idx].nValue = tx_new->vpout[idx].nValue; + else tx.vout[idx].nValue = tx_new->vout[idx].nValue; } @@ -3771,21 +3784,21 @@ bool CWallet::CreateTransactionInternal( std::vector::iterator change_positionr = txNew.vpout.begin()+nChangePosInOut; if(txNew.nVersion >= TX_ELE_VERSION){ - // Only reduce change if remaining amount is still a large enough output. - if (change_positionr->nValue >= MIN_FINAL_CHANGE + additionalFeeNeeded) { - change_positionr->nValue -= additionalFeeNeeded; - nFeeRet += additionalFeeNeeded; - break; // Done, able to increase fee from change - } - } - else { - // Only reduce change if remaining amount is still a large enough output. - if (change_position->nValue >= MIN_FINAL_CHANGE + additionalFeeNeeded) { - change_position->nValue -= additionalFeeNeeded; - nFeeRet += additionalFeeNeeded; - break; // Done, able to increase fee from change - } - } + // Only reduce change if remaining amount is still a large enough output. + if (change_positionr->nValue >= MIN_FINAL_CHANGE + additionalFeeNeeded) { + change_positionr->nValue -= additionalFeeNeeded; + nFeeRet += additionalFeeNeeded; + break; // Done, able to increase fee from change + } + } + else { + // Only reduce change if remaining amount is still a large enough output. + if (change_position->nValue >= MIN_FINAL_CHANGE + additionalFeeNeeded) { + change_position->nValue -= additionalFeeNeeded; + nFeeRet += additionalFeeNeeded; + break; // Done, able to increase fee from change + } + } } // If subtracting fee from recipients, we now know what fee we @@ -4236,7 +4249,7 @@ std::set< std::set > CWallet::GetAddressGroupings() const continue; grouping.insert(txoutAddr); } - } + } } if (grouping.size() > 0) { @@ -4246,8 +4259,8 @@ std::set< std::set > CWallet::GetAddressGroupings() const } // group lone addrs by themselves - for(unsigned int i = 0; i < (wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout.size() : wtx.tx->vout.size()) ; i++){ - CTxOutAsset txout = (wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout[i] : wtx.tx->vout[i]); + for(unsigned int i = 0; i < (wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout.size() : wtx.tx->vout.size()) ; i++){ + CTxOutAsset txout = (wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout[i] : wtx.tx->vout[i]); if (IsMine(txout)) { CTxDestination address; @@ -4257,7 +4270,7 @@ std::set< std::set > CWallet::GetAddressGroupings() const groupings.insert(grouping); grouping.clear(); } - } + } } From 06b9e6ab31427ab41a9cd523966f1e7f7154b851 Mon Sep 17 00:00:00 2001 From: Block Mechanic Date: Tue, 7 Jun 2022 08:34:58 +0200 Subject: [PATCH 2/3] Update sendcoinsentry.cpp --- src/qt/sendcoinsentry.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/qt/sendcoinsentry.cpp b/src/qt/sendcoinsentry.cpp index 8abbfca..ca542e7 100644 --- a/src/qt/sendcoinsentry.cpp +++ b/src/qt/sendcoinsentry.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -64,10 +65,8 @@ void SendCoinsEntry::assetList(){ interfaces::Wallet& wallet = model->wallet(); m_balances = wallet.getBalances(); QStringList list; - list << "CRW"; for(auto const& x : m_balances.balance){ - //assetListModel.append(); list << QString::fromStdString(x.first.getName()); } @@ -78,6 +77,11 @@ void SendCoinsEntry::assetList(){ ui->assetBox->setModel(a_model); } +void SendCoinsEntry::setBalance(const interfaces::WalletBalances& balances) +{ + assetList(); +} + void SendCoinsEntry::on_pasteButton_clicked() { // Paste text from clipboard into recipient field @@ -109,6 +113,8 @@ void SendCoinsEntry::setModel(WalletModel *_model) if (_model && _model->getOptionsModel()) connect(_model->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &SendCoinsEntry::updateDisplayUnit); + connect(model, &WalletModel::balanceChanged, this, &SendCoinsEntry::setBalance); + clear(); } @@ -193,6 +199,11 @@ SendAssetsRecipient SendCoinsEntry::getValue() recipient.message = ui->messageTextLabel->text(); recipient.fSubtractFeeFromAmount = (ui->checkboxSubtractFeeFromAmount->checkState() == Qt::Checked); + for(auto const& x : passetsCache->GetItemsMap()){ + if(QString::fromStdString(x.second->second.asset.getName()) == ui->assetBox->currentText()) + recipient.asset = x.second->second.asset; + } + return recipient; } From 7f6fa6d80f6ef53f51ffe5cbfc4942268261d4d5 Mon Sep 17 00:00:00 2001 From: Block Mechanic Date: Tue, 7 Jun 2022 08:35:03 +0200 Subject: [PATCH 3/3] Update sendcoinsentry.h --- src/qt/sendcoinsentry.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/sendcoinsentry.h b/src/qt/sendcoinsentry.h index c8c6c99..b7a0579 100644 --- a/src/qt/sendcoinsentry.h +++ b/src/qt/sendcoinsentry.h @@ -80,6 +80,7 @@ private Q_SLOTS: bool updateLabel(const QString &address); void assetList(); + void setBalance(const interfaces::WalletBalances &balances); };