Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
252DataStream ssTx;253ssTx << TX_WITH_WITNESS(*newTx);254transaction_array.append((const char*)ssTx.data(), ssTx.size());255}257// Add addresses / update labels that we've sent to the address book,258// and emit coinsSent signal for each recipient259for (const SendCoinsRecipient &rcp : transaction.getRecipients())260{261{262std::string strAddress = rcp.address.toStdString();263CTxDestination dest = DecodeDestination(strAddress);264std::string strLabel = rcp.label.toStdString();265{266// Check if we have a new address or an updated label267std::string name;268if (!m_wallet->getAddress(269dest, &name, /*purpose=*/nullptr))270{271m_wallet->setAddressBook(dest, strLabel, wallet::AddressPurpose::SEND);272}273else if (name != strLabel)274{275m_wallet->setAddressBook(dest, strLabel, {}); // {} means don't change purpose276}277}278}279Q_EMIT coinsSent(this, rcp, transaction_array);280}282checkBalanceChanged(m_wallet->getBalances()); // update balance immediately, otherwise there could be a short noticeable delay until pollBalanceChanged hits283}285OptionsModel* WalletModel::getOptionsModel() const286{287return optionsModel;288}290AddressTableModel* WalletModel::getAddressTableModel() const291{292return addressTableModel;293}295TransactionTableModel* WalletModel::getTransactionTableModel() const296{297return transactionTableModel;298}300RecentRequestsTableModel* WalletModel::getRecentRequestsTableModel() const301{302return recentRequestsTableModel;303}305WalletModel::EncryptionStatus WalletModel::getEncryptionStatus() const306{307if(!m_wallet->isCrypted())308{309// A previous bug allowed for watchonly wallets to be encrypted (encryption keys set, but nothing is actually encrypted).310// To avoid misrepresenting the encryption status of such wallets, we only return NoKeys for watchonly wallets that are unencrypted.311if (m_wallet->privateKeysDisabled()) {312return NoKeys;313}314return Unencrypted;315}316else if(m_wallet->isLocked())317{318return Locked;319}320else321{322return Unlocked;323}324}326bool WalletModel::setWalletEncrypted(const SecureString& passphrase)327{328return m_wallet->encryptWallet(passphrase);329}331bool WalletModel::setWalletLocked(bool locked, const SecureString &passPhrase)332{333if(locked)334{335// Lock336return m_wallet->lock();337}338else339{340// Unlock341return m_wallet->unlock(passPhrase);342}343}345bool WalletModel::changePassphrase(const SecureString &oldPass, const SecureString &newPass)346{347m_wallet->lock(); // Make sure wallet is locked before attempting pass change348return m_wallet->changeWalletPassphrase(oldPass, newPass);349}351// Handlers for core signals352static void NotifyUnload(WalletModel* walletModel)353{354qDebug() << "NotifyUnload";355bool invoked = QMetaObject::invokeMethod(walletModel, "unload");356assert(invoked);357}359static void NotifyKeyStoreStatusChanged(WalletModel *walletmodel)360{361qDebug() << "NotifyKeyStoreStatusChanged";362bool invoked = QMetaObject::invokeMethod(walletmodel, "updateStatus", Qt::QueuedConnection);363assert(invoked);364}366static void NotifyAddressBookChanged(WalletModel *walletmodel,367const CTxDestination &address, const std::string &label, bool isMine,368wallet::AddressPurpose purpose, ChangeType status)369{370QString strAddress = QString::fromStdString(EncodeDestination(address));371QString strLabel = QString::fromStdString(label);373qDebug() << "NotifyAddressBookChanged: " + strAddress + " " + strLabel + " isMine=" + QString::number(isMine) + " purpose=" + QString::number(static_cast<uint8_t>(purpose)) + " status=" + QString::number(status);374bool invoked = QMetaObject::invokeMethod(walletmodel, "updateAddressBook",375Q_ARG(QString, strAddress),376Q_ARG(QString, strLabel),377Q_ARG(bool, isMine),378Q_ARG(wallet::AddressPurpose, purpose),379Q_ARG(int, status));380assert(invoked);381}383static void NotifyTransactionChanged(WalletModel *walletmodel, const Txid& hash, ChangeType status)384{385Q_UNUSED(hash);386Q_UNUSED(status);387bool invoked = QMetaObject::invokeMethod(walletmodel, "updateTransaction", Qt::QueuedConnection);388assert(invoked);389}391static void ShowProgress(WalletModel *walletmodel, const std::string &title, int nProgress)392{393// emits signal "showProgress"394bool invoked = QMetaObject::invokeMethod(walletmodel, "showProgress", Qt::QueuedConnection,395Q_ARG(QString, QString::fromStdString(title)),396Q_ARG(int, nProgress));397assert(invoked);398}400static void NotifyCanGetAddressesChanged(WalletModel* walletmodel)401{402bool invoked = QMetaObject::invokeMethod(walletmodel, "canGetAddressesChanged");403assert(invoked);404}406void WalletModel::subscribeToCoreSignals()407{408// Connect signals to wallet409m_handler_unload = m_wallet->handleUnload(std::bind_front(&NotifyUnload, this));410m_handler_status_changed = m_wallet->handleStatusChanged(std::bind_front(&NotifyKeyStoreStatusChanged, this));411m_handler_address_book_changed = m_wallet->handleAddressBookChanged(std::bind_front(NotifyAddressBookChanged, this));412m_handler_transaction_changed = m_wallet->handleTransactionChanged(std::bind_front(NotifyTransactionChanged, this));413m_handler_show_progress = m_wallet->handleShowProgress(std::bind_front(ShowProgress, this));414m_handler_can_get_addrs_changed = m_wallet->handleCanGetAddressesChanged(std::bind_front(NotifyCanGetAddressesChanged, this));415}417void WalletModel::unsubscribeFromCoreSignals()418{419// Disconnect signals from wallet420m_handler_unload->disconnect();421m_handler_status_changed->disconnect();422m_handler_address_book_changed->disconnect();423m_handler_transaction_changed->disconnect();424m_handler_show_progress->disconnect();425m_handler_can_get_addrs_changed->disconnect();426}428// WalletModel::UnlockContext implementation429WalletModel::UnlockContext WalletModel::requestUnlock()430{431// Bugs in earlier versions may have resulted in wallets with private keys disabled to become "encrypted"432// (encryption keys are present, but not actually doing anything).433// To avoid issues with such wallets, check if the wallet has private keys disabled, and if so, return a context434// that indicates the wallet is not encrypted.435if (m_wallet->privateKeysDisabled()) {436return UnlockContext(this, /*valid=*/true, /*relock=*/false);437}438bool was_locked = getEncryptionStatus() == Locked;439if(was_locked)440{441// Request UI to unlock wallet442Q_EMIT requireUnlock();443}444// If wallet is still locked, unlock was failed or cancelled, mark context as invalid445bool valid = getEncryptionStatus() != Locked;447return UnlockContext(this, valid, was_locked);448}450WalletModel::UnlockContext::UnlockContext(WalletModel *_wallet, bool _valid, bool _relock):451wallet(_wallet),452valid(_valid),453relock(_relock)454{455}457WalletModel::UnlockContext::~UnlockContext()458{459if(valid && relock)460{461wallet->setWalletLocked(true);462}463}465bool WalletModel::bumpFee(Txid hash, Txid& new_hash)466{467CCoinControl coin_control;468std::vector<bilingual_str> errors;469CAmount old_fee;470CAmount new_fee;471CMutableTransaction mtx;472if (!m_wallet->createBumpTransaction(hash, coin_control, errors, old_fee, new_fee, mtx)) {473QMessageBox::critical(nullptr, tr("Fee bump error"), tr("Increasing transaction fee failed") + "<br />(" +474(errors.size() ? QString::fromStdString(errors[0].translated) : "") +")");475return false;476}478// allow a user based fee verification479/*: Asks a user if they would like to manually increase the fee of a transaction that has already been created. */480QString questionString = tr("Do you want to increase the fee?");481questionString.append("<br />");482questionString.append("<table style=\"text-align: left;\">");483questionString.append("<tr><td>");484questionString.append(tr("Current fee:"));485questionString.append("</td><td>");486questionString.append(BitcoinUnits::formatHtmlWithUnit(getOptionsModel()->getDisplayUnit(), old_fee));487questionString.append("</td></tr><tr><td>");488questionString.append(tr("Increase:"));489questionString.append("</td><td>");490questionString.append(BitcoinUnits::formatHtmlWithUnit(getOptionsModel()->getDisplayUnit(), new_fee - old_fee));491questionString.append("</td></tr><tr><td>");492questionString.append(tr("New fee:"));493questionString.append("</td><td>");494questionString.append(BitcoinUnits::formatHtmlWithUnit(getOptionsModel()->getDisplayUnit(), new_fee));495questionString.append("</td></tr></table>");497// Display warning in the "Confirm fee bump" window if the "Coin Control Features" option is enabled498if (getOptionsModel()->getCoinControlFeatures()) {499questionString.append("<br><br>");500questionString.append(tr("Warning: This may pay the additional fee by reducing change outputs or adding inputs, when necessary. It may add a new change output if one does not already exist. These changes may potentially leak privacy."));
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.