From 77e4b0657298c715c835d8d2eb11e173852e6815 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Tue, 5 Dec 2017 15:57:12 -0500 Subject: refactor: Get rid of Wallet::IsWalletFlagSet method Replace by privateKeysDisabled method to avoid need for GUI to reference internal wallet flags. Also remove adjacent WalletModel canGetAddresses wrapper that serves no purpose and make Wallet::canGetAddresses non-const so it can be implemented by IPC classes in #10102. --- src/interfaces/wallet.cpp | 4 ++-- src/interfaces/wallet.h | 6 +++--- src/qt/bitcoingui.cpp | 2 +- src/qt/overviewpage.cpp | 8 ++++---- src/qt/receivecoinsdialog.cpp | 4 ++-- src/qt/sendcoinsdialog.cpp | 18 +++++++++--------- src/qt/walletmodel.cpp | 16 +++------------- src/qt/walletmodel.h | 2 -- 8 files changed, 24 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp index 01ade56b2a..c2d42d78d3 100644 --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -463,8 +463,8 @@ public: } unsigned int getConfirmTarget() override { return m_wallet->m_confirm_target; } bool hdEnabled() override { return m_wallet->IsHDEnabled(); } - bool canGetAddresses() const override { return m_wallet->CanGetAddresses(); } - bool IsWalletFlagSet(uint64_t flag) override { return m_wallet->IsWalletFlagSet(flag); } + bool canGetAddresses() override { return m_wallet->CanGetAddresses(); } + bool privateKeysDisabled() override { return m_wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS); } OutputType getDefaultAddressType() override { return m_wallet->m_default_address_type; } OutputType getDefaultChangeType() override { return m_wallet->m_default_change_type; } CAmount getDefaultMaxTxFee() override { return m_wallet->m_default_max_tx_fee; } diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h index 9476c9f77f..56829289b2 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -247,10 +247,10 @@ public: virtual bool hdEnabled() = 0; // Return whether the wallet is blank. - virtual bool canGetAddresses() const = 0; + virtual bool canGetAddresses() = 0; - // check if a certain wallet flag is set. - virtual bool IsWalletFlagSet(uint64_t flag) = 0; + // Return whether private keys enabled. + virtual bool privateKeysDisabled() = 0; // Get default address type. virtual OutputType getDefaultAddressType() = 0; diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 5fab267610..2918676c22 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -1258,7 +1258,7 @@ void BitcoinGUI::updateWalletStatus() } WalletModel * const walletModel = walletView->getWalletModel(); setEncryptionStatus(walletModel->getEncryptionStatus()); - setHDStatus(walletModel->privateKeysDisabled(), walletModel->wallet().hdEnabled()); + setHDStatus(walletModel->wallet().privateKeysDisabled(), walletModel->wallet().hdEnabled()); } #endif // ENABLE_WALLET diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 342c7cce31..c376921b72 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -161,7 +161,7 @@ void OverviewPage::setBalance(const interfaces::WalletBalances& balances) { int unit = walletModel->getOptionsModel()->getDisplayUnit(); m_balances = balances; - if (walletModel->privateKeysDisabled()) { + if (walletModel->wallet().privateKeysDisabled()) { ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balances.watch_only_balance, false, BitcoinUnits::separatorAlways)); ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, balances.unconfirmed_watch_only_balance, false, BitcoinUnits::separatorAlways)); ui->labelImmature->setText(BitcoinUnits::formatWithUnit(unit, balances.immature_watch_only_balance, false, BitcoinUnits::separatorAlways)); @@ -184,7 +184,7 @@ void OverviewPage::setBalance(const interfaces::WalletBalances& balances) // for symmetry reasons also show immature label when the watch-only one is shown ui->labelImmature->setVisible(showImmature || showWatchOnlyImmature); ui->labelImmatureText->setVisible(showImmature || showWatchOnlyImmature); - ui->labelWatchImmature->setVisible(!walletModel->privateKeysDisabled() && showWatchOnlyImmature); // show watch-only immature balance + ui->labelWatchImmature->setVisible(!walletModel->wallet().privateKeysDisabled() && showWatchOnlyImmature); // show watch-only immature balance } // show/hide watch-only labels @@ -236,9 +236,9 @@ void OverviewPage::setWalletModel(WalletModel *model) connect(model->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &OverviewPage::updateDisplayUnit); - updateWatchOnlyLabels(wallet.haveWatchOnly() && !model->privateKeysDisabled()); + updateWatchOnlyLabels(wallet.haveWatchOnly() && !model->wallet().privateKeysDisabled()); connect(model, &WalletModel::notifyWatchonlyChanged, [this](bool showWatchOnly) { - updateWatchOnlyLabels(showWatchOnly && !walletModel->privateKeysDisabled()); + updateWatchOnlyLabels(showWatchOnly && !walletModel->wallet().privateKeysDisabled()); }); } diff --git a/src/qt/receivecoinsdialog.cpp b/src/qt/receivecoinsdialog.cpp index 16597e4758..180550c5ae 100644 --- a/src/qt/receivecoinsdialog.cpp +++ b/src/qt/receivecoinsdialog.cpp @@ -99,11 +99,11 @@ void ReceiveCoinsDialog::setModel(WalletModel *_model) } // Set the button to be enabled or disabled based on whether the wallet can give out new addresses. - ui->receiveButton->setEnabled(model->canGetAddresses()); + ui->receiveButton->setEnabled(model->wallet().canGetAddresses()); // Enable/disable the receive button if the wallet is now able/unable to give out new addresses. connect(model, &WalletModel::canGetAddressesChanged, [this] { - ui->receiveButton->setEnabled(model->canGetAddresses()); + ui->receiveButton->setEnabled(model->wallet().canGetAddresses()); }); } } diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 4ddee513a1..7dc3e996d4 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -187,7 +187,7 @@ void SendCoinsDialog::setModel(WalletModel *_model) // set default rbf checkbox state ui->optInRBF->setCheckState(Qt::Checked); - if (model->privateKeysDisabled()) { + if (model->wallet().privateKeysDisabled()) { ui->sendButton->setText(tr("Cr&eate Unsigned")); ui->sendButton->setToolTip(tr("Creates a Partially Signed Bitcoin Transaction (PSBT) for use with e.g. an offline %1 wallet, or a PSBT-compatible hardware wallet.").arg(PACKAGE_NAME)); } @@ -312,14 +312,14 @@ void SendCoinsDialog::on_sendButton_clicked() } QString questionString; - if (model->privateKeysDisabled()) { + if (model->wallet().privateKeysDisabled()) { questionString.append(tr("Do you want to draft this transaction?")); } else { questionString.append(tr("Are you sure you want to send?")); } questionString.append("
"); - if (model->privateKeysDisabled()) { + if (model->wallet().privateKeysDisabled()) { questionString.append(tr("Please, review your transaction proposal. This will produce a Partially Signed Bitcoin Transaction (PSBT) which you can copy and then sign with e.g. an offline %1 wallet, or a PSBT-compatible hardware wallet.").arg(PACKAGE_NAME)); } else { questionString.append(tr("Please, review your transaction.")); @@ -374,8 +374,8 @@ void SendCoinsDialog::on_sendButton_clicked() } else { questionString = questionString.arg("

" + formatted.at(0)); } - const QString confirmation = model->privateKeysDisabled() ? tr("Confirm transaction proposal") : tr("Confirm send coins"); - const QString confirmButtonText = model->privateKeysDisabled() ? tr("Copy PSBT to clipboard") : tr("Send"); + const QString confirmation = model->wallet().privateKeysDisabled() ? tr("Confirm transaction proposal") : tr("Confirm send coins"); + const QString confirmButtonText = model->wallet().privateKeysDisabled() ? tr("Copy PSBT to clipboard") : tr("Send"); SendConfirmationDialog confirmationDialog(confirmation, questionString, informative_text, detailed_text, SEND_CONFIRM_DELAY, confirmButtonText, this); confirmationDialog.exec(); QMessageBox::StandardButton retval = static_cast(confirmationDialog.result()); @@ -387,7 +387,7 @@ void SendCoinsDialog::on_sendButton_clicked() } bool send_failure = false; - if (model->privateKeysDisabled()) { + if (model->wallet().privateKeysDisabled()) { CMutableTransaction mtx = CMutableTransaction{*(currentTransaction.getWtx())}; PartiallySignedTransaction psbtx(mtx); bool complete = false; @@ -562,7 +562,7 @@ void SendCoinsDialog::setBalance(const interfaces::WalletBalances& balances) if(model && model->getOptionsModel()) { CAmount balance = balances.balance; - if (model->privateKeysDisabled()) { + if (model->wallet().privateKeysDisabled()) { balance = balances.watch_only_balance; ui->labelBalanceName->setText(tr("Watch-only balance:")); } @@ -652,7 +652,7 @@ void SendCoinsDialog::useAvailableBalance(SendCoinsEntry* entry) } // Include watch-only for wallets without private key - coin_control.fAllowWatchOnly = model->privateKeysDisabled(); + coin_control.fAllowWatchOnly = model->wallet().privateKeysDisabled(); // Calculate available amount to send. CAmount amount = model->wallet().getAvailableBalance(coin_control); @@ -707,7 +707,7 @@ void SendCoinsDialog::updateCoinControlState(CCoinControl& ctrl) ctrl.m_confirm_target = getConfTargetForIndex(ui->confTargetSelector->currentIndex()); ctrl.m_signal_bip125_rbf = ui->optInRBF->isChecked(); // Include watch-only for wallets without private key - ctrl.fAllowWatchOnly = model->privateKeysDisabled(); + ctrl.fAllowWatchOnly = model->wallet().privateKeysDisabled(); } void SendCoinsDialog::updateSmartFeeLabel() diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 8a84a8c168..642dce4ba9 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -23,7 +23,7 @@ #include #include // for GetBoolArg #include -#include +#include // for CRecipient #include @@ -184,7 +184,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact std::string strFailReason; auto& newTx = transaction.getWtx(); - newTx = m_wallet->createTransaction(vecSend, coinControl, !privateKeysDisabled() /* sign */, nChangePosRet, nFeeRequired, strFailReason); + newTx = m_wallet->createTransaction(vecSend, coinControl, !wallet().privateKeysDisabled() /* sign */, nChangePosRet, nFeeRequired, strFailReason); transaction.setTransactionFee(nFeeRequired); if (fSubtractFeeFromAmount && newTx) transaction.reassignAmounts(nChangePosRet); @@ -488,7 +488,7 @@ bool WalletModel::bumpFee(uint256 hash, uint256& new_hash) return false; } - const bool create_psbt = privateKeysDisabled(); + const bool create_psbt = m_wallet->privateKeysDisabled(); // allow a user based fee verification QString questionString = create_psbt ? tr("Do you want to draft a transaction with fee increase?") : tr("Do you want to increase the fee?"); @@ -558,16 +558,6 @@ bool WalletModel::isWalletEnabled() return !gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET); } -bool WalletModel::privateKeysDisabled() const -{ - return m_wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS); -} - -bool WalletModel::canGetAddresses() const -{ - return m_wallet->canGetAddresses(); -} - QString WalletModel::getWalletName() const { return QString::fromStdString(m_wallet->getWalletName()); diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 8087356f5e..7936014af9 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -140,8 +140,6 @@ public: bool bumpFee(uint256 hash, uint256& new_hash); static bool isWalletEnabled(); - bool privateKeysDisabled() const; - bool canGetAddresses() const; interfaces::Node& node() const { return m_node; } interfaces::Wallet& wallet() const { return *m_wallet; } -- cgit v1.2.3 From 1c2ab1a6d29f2c6c065dae4f4a4e2ad1286311b3 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Tue, 5 Dec 2017 15:57:12 -0500 Subject: refactor: Rename Node::disconnect methods Avoid overloading method name to work more easily with IPC framework --- src/interfaces/node.cpp | 4 ++-- src/interfaces/node.h | 4 ++-- src/qt/rpcconsole.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp index b720a63017..25e5b0f7e4 100644 --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -152,14 +152,14 @@ public: } return false; } - bool disconnect(const CNetAddr& net_addr) override + bool disconnectByAddress(const CNetAddr& net_addr) override { if (m_context.connman) { return m_context.connman->DisconnectNode(net_addr); } return false; } - bool disconnect(NodeId id) override + bool disconnectById(NodeId id) override { if (m_context.connman) { return m_context.connman->DisconnectNode(id); diff --git a/src/interfaces/node.h b/src/interfaces/node.h index 38aeb06324..a0466bd297 100644 --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -124,10 +124,10 @@ public: virtual bool unban(const CSubNet& ip) = 0; //! Disconnect node by address. - virtual bool disconnect(const CNetAddr& net_addr) = 0; + virtual bool disconnectByAddress(const CNetAddr& net_addr) = 0; //! Disconnect node by id. - virtual bool disconnect(NodeId id) = 0; + virtual bool disconnectById(NodeId id) = 0; //! Get total bytes recv. virtual int64_t getTotalBytesRecv() = 0; diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index b82ab9ffe8..0ff0bb323e 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -1191,7 +1191,7 @@ void RPCConsole::disconnectSelectedNode() // Get currently selected peer address NodeId id = nodes.at(i).data().toLongLong(); // Find the node, disconnect it and clear the selected node - if(m_node.disconnect(id)) + if(m_node.disconnectById(id)) clearSelectedNode(); } } @@ -1216,7 +1216,7 @@ void RPCConsole::banSelectedNode(int bantime) const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow); if (stats) { m_node.ban(stats->nodeStats.addr, BanReasonManuallyAdded, bantime); - m_node.disconnect(stats->nodeStats.addr); + m_node.disconnectByAddress(stats->nodeStats.addr); } } clearSelectedNode(); -- cgit v1.2.3 From 6ceb21909ce66b7b4762a855889acd46bb6b77f3 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Wed, 26 Feb 2020 16:05:49 -0500 Subject: refactor: Rename Chain::Notifications methods to be consistent with other interfaces methods This also simplifies #10102 removing overrides needed to deal with inconsistent case convention --- src/interfaces/chain.cpp | 14 +++++++------- src/interfaces/chain.h | 14 +++++++------- src/wallet/wallet.cpp | 18 +++++++++--------- src/wallet/wallet.h | 12 ++++++------ 4 files changed, 29 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp index d16f4e7ccc..da11c63883 100644 --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -166,25 +166,25 @@ public: } void TransactionAddedToMempool(const CTransactionRef& tx) override { - m_notifications->TransactionAddedToMempool(tx); + m_notifications->transactionAddedToMempool(tx); } void TransactionRemovedFromMempool(const CTransactionRef& tx) override { - m_notifications->TransactionRemovedFromMempool(tx); + m_notifications->transactionRemovedFromMempool(tx); } void BlockConnected(const std::shared_ptr& block, const CBlockIndex* index) override { - m_notifications->BlockConnected(*block, index->nHeight); + m_notifications->blockConnected(*block, index->nHeight); } void BlockDisconnected(const std::shared_ptr& block, const CBlockIndex* index) override { - m_notifications->BlockDisconnected(*block, index->nHeight); + m_notifications->blockDisconnected(*block, index->nHeight); } void UpdatedBlockTip(const CBlockIndex* index, const CBlockIndex* fork_index, bool is_ibd) override { - m_notifications->UpdatedBlockTip(); + m_notifications->updatedBlockTip(); } - void ChainStateFlushed(const CBlockLocator& locator) override { m_notifications->ChainStateFlushed(locator); } + void ChainStateFlushed(const CBlockLocator& locator) override { m_notifications->chainStateFlushed(locator); } Chain& m_chain; Chain::Notifications* m_notifications; }; @@ -366,7 +366,7 @@ public: { LOCK2(::cs_main, ::mempool.cs); for (const CTxMemPoolEntry& entry : ::mempool.mapTx) { - notifications.TransactionAddedToMempool(entry.GetSharedTx()); + notifications.transactionAddedToMempool(entry.GetSharedTx()); } } NodeContext& m_node; diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index 03a600d5a3..dc0dcfb0d4 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -217,12 +217,12 @@ public: { public: virtual ~Notifications() {} - virtual void TransactionAddedToMempool(const CTransactionRef& tx) {} - virtual void TransactionRemovedFromMempool(const CTransactionRef& ptx) {} - virtual void BlockConnected(const CBlock& block, int height) {} - virtual void BlockDisconnected(const CBlock& block, int height) {} - virtual void UpdatedBlockTip() {} - virtual void ChainStateFlushed(const CBlockLocator& locator) {} + virtual void transactionAddedToMempool(const CTransactionRef& tx) {} + virtual void transactionRemovedFromMempool(const CTransactionRef& ptx) {} + virtual void blockConnected(const CBlock& block, int height) {} + virtual void blockDisconnected(const CBlock& block, int height) {} + virtual void updatedBlockTip() {} + virtual void chainStateFlushed(const CBlockLocator& locator) {} }; //! Register handler for notifications. @@ -245,7 +245,7 @@ public: //! Current RPC serialization flags. virtual int rpcSerializationFlags() = 0; - //! Synchronously send TransactionAddedToMempool notifications about all + //! Synchronously send transactionAddedToMempool notifications about all //! current mempool transactions to the specified handler and return after //! the last one is sent. These notifications aren't coordinated with async //! notifications sent by handleNotifications, so out of date async diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 01aadcdd6d..922b50f5e2 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -344,7 +344,7 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, return false; } -void CWallet::ChainStateFlushed(const CBlockLocator& loc) +void CWallet::chainStateFlushed(const CBlockLocator& loc) { WalletBatch batch(*database); batch.WriteBestBlock(loc); @@ -1089,7 +1089,7 @@ void CWallet::SyncTransaction(const CTransactionRef& ptx, CWalletTx::Confirmatio MarkInputsDirty(ptx); } -void CWallet::TransactionAddedToMempool(const CTransactionRef& ptx) { +void CWallet::transactionAddedToMempool(const CTransactionRef& ptx) { auto locked_chain = chain().lock(); LOCK(cs_wallet); CWalletTx::Confirmation confirm(CWalletTx::Status::UNCONFIRMED, /* block_height */ 0, {}, /* nIndex */ 0); @@ -1101,7 +1101,7 @@ void CWallet::TransactionAddedToMempool(const CTransactionRef& ptx) { } } -void CWallet::TransactionRemovedFromMempool(const CTransactionRef &ptx) { +void CWallet::transactionRemovedFromMempool(const CTransactionRef &ptx) { LOCK(cs_wallet); auto it = mapWallet.find(ptx->GetHash()); if (it != mapWallet.end()) { @@ -1109,7 +1109,7 @@ void CWallet::TransactionRemovedFromMempool(const CTransactionRef &ptx) { } } -void CWallet::BlockConnected(const CBlock& block, int height) +void CWallet::blockConnected(const CBlock& block, int height) { const uint256& block_hash = block.GetHash(); auto locked_chain = chain().lock(); @@ -1120,11 +1120,11 @@ void CWallet::BlockConnected(const CBlock& block, int height) for (size_t index = 0; index < block.vtx.size(); index++) { CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, height, block_hash, index); SyncTransaction(block.vtx[index], confirm); - TransactionRemovedFromMempool(block.vtx[index]); + transactionRemovedFromMempool(block.vtx[index]); } } -void CWallet::BlockDisconnected(const CBlock& block, int height) +void CWallet::blockDisconnected(const CBlock& block, int height) { auto locked_chain = chain().lock(); LOCK(cs_wallet); @@ -1141,7 +1141,7 @@ void CWallet::BlockDisconnected(const CBlock& block, int height) } } -void CWallet::UpdatedBlockTip() +void CWallet::updatedBlockTip() { m_best_block_time = GetTime(); } @@ -3875,7 +3875,7 @@ std::shared_ptr CWallet::CreateWalletFromFile(interfaces::Chain& chain, } auto locked_chain = chain.lock(); - walletInstance->ChainStateFlushed(locked_chain->getTipLocator()); + walletInstance->chainStateFlushed(locked_chain->getTipLocator()); } else if (wallet_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS) { // Make it impossible to disable private keys after creation error = strprintf(_("Error loading %s: Private keys can only be disabled during creation").translated, walletFile); @@ -4056,7 +4056,7 @@ std::shared_ptr CWallet::CreateWalletFromFile(interfaces::Chain& chain, return nullptr; } } - walletInstance->ChainStateFlushed(locked_chain->getTipLocator()); + walletInstance->chainStateFlushed(locked_chain->getTipLocator()); walletInstance->database->IncrementUpdateCounter(); // Restore wallet transaction metadata after -zapwallettxes=1 diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 1fb72c83cd..75fd14a80e 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -875,10 +875,10 @@ public: void MarkDirty(); bool AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose=true); void LoadToWallet(CWalletTx& wtxIn) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); - void TransactionAddedToMempool(const CTransactionRef& tx) override; - void BlockConnected(const CBlock& block, int height) override; - void BlockDisconnected(const CBlock& block, int height) override; - void UpdatedBlockTip() override; + void transactionAddedToMempool(const CTransactionRef& tx) override; + void blockConnected(const CBlock& block, int height) override; + void blockDisconnected(const CBlock& block, int height) override; + void updatedBlockTip() override; int64_t RescanFromTime(int64_t startTime, const WalletRescanReserver& reserver, bool update); struct ScanResult { @@ -897,7 +897,7 @@ public: uint256 last_failed_block; }; ScanResult ScanForWalletTransactions(const uint256& first_block, const uint256& last_block, const WalletRescanReserver& reserver, bool fUpdate); - void TransactionRemovedFromMempool(const CTransactionRef &ptx) override; + void transactionRemovedFromMempool(const CTransactionRef &ptx) override; void ReacceptWalletTransactions() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); void ResendWalletTransactions(); struct Balance { @@ -1033,7 +1033,7 @@ public: bool IsAllFromMe(const CTransaction& tx, const isminefilter& filter) const; CAmount GetCredit(const CTransaction& tx, const isminefilter& filter) const; CAmount GetChange(const CTransaction& tx) const; - void ChainStateFlushed(const CBlockLocator& loc) override; + void chainStateFlushed(const CBlockLocator& loc) override; DBErrors LoadWallet(bool& fFirstRunRet); DBErrors ZapWalletTx(std::vector& vWtx); -- cgit v1.2.3 From 96dfe5ced64979e51649d20555aa182defc80119 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Tue, 5 Dec 2017 15:57:12 -0500 Subject: refactor: Change Chain::broadcastTransaction param order Make output argument last argument so it works more easily with IPC framework in #10102, and for consistency with other methods --- src/interfaces/chain.cpp | 5 ++++- src/interfaces/chain.h | 5 ++++- src/wallet/wallet.cpp | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp index da11c63883..9dc0d37cd9 100644 --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -278,7 +278,10 @@ public: auto it = ::mempool.GetIter(txid); return it && (*it)->GetCountWithDescendants() > 1; } - bool broadcastTransaction(const CTransactionRef& tx, std::string& err_string, const CAmount& max_tx_fee, bool relay) override + bool broadcastTransaction(const CTransactionRef& tx, + const CAmount& max_tx_fee, + bool relay, + std::string& err_string) override { const TransactionError err = BroadcastTransaction(m_node, tx, err_string, max_tx_fee, relay, /*wait_callback*/ false); // Chain clients only care about failures to accept the tx to the mempool. Disregard non-mempool related failures. diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index dc0dcfb0d4..caefa87e11 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -154,7 +154,10 @@ public: //! Transaction is added to memory pool, if the transaction fee is below the //! amount specified by max_tx_fee, and broadcast to all peers if relay is set to true. //! Return false if the transaction could not be added due to the fee or for another reason. - virtual bool broadcastTransaction(const CTransactionRef& tx, std::string& err_string, const CAmount& max_tx_fee, bool relay) = 0; + virtual bool broadcastTransaction(const CTransactionRef& tx, + const CAmount& max_tx_fee, + bool relay, + std::string& err_string) = 0; //! Calculate mempool ancestor and descendant counts for the given transaction. virtual void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) = 0; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 922b50f5e2..9a972febab 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1785,7 +1785,7 @@ bool CWalletTx::SubmitMemoryPoolAndRelay(std::string& err_string, bool relay) // Irrespective of the failure reason, un-marking fInMempool // out-of-order is incorrect - it should be unmarked when // TransactionRemovedFromMempool fires. - bool ret = pwallet->chain().broadcastTransaction(tx, err_string, pwallet->m_default_max_tx_fee, relay); + bool ret = pwallet->chain().broadcastTransaction(tx, pwallet->m_default_max_tx_fee, relay, err_string); fInMempool |= ret; return ret; } -- cgit v1.2.3 From 1dca9dc4c772fa0a4ec52c4d88b7cd3d243aea7b Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Tue, 5 Dec 2017 15:57:12 -0500 Subject: refactor: Change createWallet, fillPSBT argument order Move output arguments after input arguments for consistency with other methods, and to work more easily with IPC framework in #10102 --- src/interfaces/node.cpp | 7 +++---- src/interfaces/node.h | 2 +- src/interfaces/wallet.cpp | 10 +++++----- src/interfaces/wallet.h | 10 +++++----- src/qt/sendcoinsdialog.cpp | 2 +- src/qt/walletcontroller.cpp | 4 ++-- src/qt/walletmodel.cpp | 2 +- 7 files changed, 18 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp index 25e5b0f7e4..905173d20b 100644 --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -262,12 +262,11 @@ public: { return MakeWallet(LoadWallet(*m_context.chain, name, error, warnings)); } - WalletCreationStatus createWallet(const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, std::string& error, std::vector& warnings, std::unique_ptr& result) override + std::unique_ptr createWallet(const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, std::string& error, std::vector& warnings, WalletCreationStatus& status) override { std::shared_ptr wallet; - WalletCreationStatus status = CreateWallet(*m_context.chain, passphrase, wallet_creation_flags, name, error, warnings, wallet); - result = MakeWallet(wallet); - return status; + status = CreateWallet(*m_context.chain, passphrase, wallet_creation_flags, name, error, warnings, wallet); + return MakeWallet(wallet); } std::unique_ptr handleInitMessage(InitMessageFn fn) override { diff --git a/src/interfaces/node.h b/src/interfaces/node.h index a0466bd297..53a20886cd 100644 --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -204,7 +204,7 @@ public: virtual std::unique_ptr loadWallet(const std::string& name, std::string& error, std::vector& warnings) = 0; //! Create a wallet from file - virtual WalletCreationStatus createWallet(const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, std::string& error, std::vector& warnings, std::unique_ptr& result) = 0; + virtual std::unique_ptr createWallet(const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, std::string& error, std::vector& warnings, WalletCreationStatus& status) = 0; //! Register handler for init messages. using InitMessageFn = std::function; diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp index c2d42d78d3..c3a62cf73d 100644 --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -352,11 +352,11 @@ public: } return {}; } - TransactionError fillPSBT(PartiallySignedTransaction& psbtx, - bool& complete, - int sighash_type = 1 /* SIGHASH_ALL */, - bool sign = true, - bool bip32derivs = false) const override + TransactionError fillPSBT(int sighash_type, + bool sign, + bool bip32derivs, + PartiallySignedTransaction& psbtx, + bool& complete) override { return m_wallet->FillPSBT(psbtx, complete, sighash_type, sign, bip32derivs); } diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h index 56829289b2..487a7c3a5a 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -193,11 +193,11 @@ public: int& num_blocks) = 0; //! Fill PSBT. - virtual TransactionError fillPSBT(PartiallySignedTransaction& psbtx, - bool& complete, - int sighash_type = 1 /* SIGHASH_ALL */, - bool sign = true, - bool bip32derivs = false) const = 0; + virtual TransactionError fillPSBT(int sighash_type, + bool sign, + bool bip32derivs, + PartiallySignedTransaction& psbtx, + bool& complete) = 0; //! Get balances. virtual WalletBalances getBalances() = 0; diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 7dc3e996d4..a8c82aaf6c 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -391,7 +391,7 @@ void SendCoinsDialog::on_sendButton_clicked() CMutableTransaction mtx = CMutableTransaction{*(currentTransaction.getWtx())}; PartiallySignedTransaction psbtx(mtx); bool complete = false; - const TransactionError err = model->wallet().fillPSBT(psbtx, complete, SIGHASH_ALL, false /* sign */, true /* bip32derivs */); + const TransactionError err = model->wallet().fillPSBT(SIGHASH_ALL, false /* sign */, true /* bip32derivs */, psbtx, complete); assert(!complete); assert(err == TransactionError::OK); // Serialize the PSBT diff --git a/src/qt/walletcontroller.cpp b/src/qt/walletcontroller.cpp index 7413a1f09e..233c0ab6be 100644 --- a/src/qt/walletcontroller.cpp +++ b/src/qt/walletcontroller.cpp @@ -218,8 +218,8 @@ void CreateWalletActivity::createWallet() } QTimer::singleShot(500, worker(), [this, name, flags] { - std::unique_ptr wallet; - WalletCreationStatus status = node().createWallet(m_passphrase, flags, name, m_error_message, m_warning_message, wallet); + WalletCreationStatus status; + std::unique_ptr wallet = node().createWallet(m_passphrase, flags, name, m_error_message, m_warning_message, status); if (status == WalletCreationStatus::SUCCESS) m_wallet_model = m_wallet_controller->getOrCreateWallet(std::move(wallet)); diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 642dce4ba9..94e7a05e40 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -526,7 +526,7 @@ bool WalletModel::bumpFee(uint256 hash, uint256& new_hash) if (create_psbt) { PartiallySignedTransaction psbtx(mtx); bool complete = false; - const TransactionError err = wallet().fillPSBT(psbtx, complete, SIGHASH_ALL, false /* sign */, true /* bip32derivs */); + const TransactionError err = wallet().fillPSBT(SIGHASH_ALL, false /* sign */, true /* bip32derivs */, psbtx, complete); if (err != TransactionError::OK || complete) { QMessageBox::critical(nullptr, tr("Fee bump error"), tr("Can't draft transaction.")); return false; -- cgit v1.2.3