Merge bitcoin/bitcoin#29015: kernel: Streamline util library
c7376babd1doc: Clarify distinction between util and common libraries in libraries.md (Ryan Ofsky)4f74c59334util: Move util/string.h functions to util namespace (Ryan Ofsky)4d05d3f3b4util: add TransactionError includes and namespace declarations (Ryan Ofsky)680eafdc74util: move fees.h and error.h to common/messages.h (Ryan Ofsky)02e62c6c9acommon: Add PSBTError enum (Ryan Ofsky)0d44c44ae3util: move error.h TransactionError enum to node/types.h (Ryan Ofsky)9bcce2608dutil: move spanparsing.h to script/parsing.h (Ryan Ofsky)6dd2ad4792util: move spanparsing.h Split functions to string.h (Ryan Ofsky)23cc8ddff4util: move HexStr and HexDigit from util to crypto (TheCharlatan)6861f954f8util: move util/message to common/signmessage (Ryan Ofsky)cc5f29fbeabuild: move memory_cleanse from util to crypto (Ryan Ofsky)5b9309420cbuild: move chainparamsbase from util to common (Ryan Ofsky)ffa27af24dtest: Add check-deps.sh script to check for unexpected library dependencies (Ryan Ofsky) Pull request description: Remove `fees.h`, `errors.h`, and `spanparsing.h` from the util library. Specifically: - Move `Split` functions from `util/spanparsing.h` to `util/string.h`, using `util` namespace for clarity. - Move remaining spanparsing functions to `script/parsing.h` since they are used for descriptor and miniscript parsing. - Combine `util/fees.h` and `util/errors.h` into `common/messages.h` so there is a place for simple functions that generate user messages to live, and these functions are not part of the util library. Motivation for this change is that the util library is a dependency of the kernel, and we should remove functionality from util that shouldn't be called by kernel code or kernel applications. These changes should also improve code organization and make functions easier to discover. Some of these same moves are (or were) part of #28690, but did not help with code organization, or made it worse, so it is better to move them and clean them up in the same PR so code only has to change one time. ACKs for top commit: achow101: ACKc7376babd1TheCharlatan: Re-ACKc7376babd1hebasto: re-ACKc7376babd1. Tree-SHA512: 5bcef16c1255463b1b69270548711e7ff78ca0dd34e300b95e3ca1ce52ceb34f83d9ddb2839e83800ba36b200de30396e504bbb04fa02c6d0c24a16d06ae523d
This commit is contained in:
121 files changed
+1023
-526
No files matched your search
@@ -85,6 +85,8 @@ Q_DECLARE_METATYPE(uint256)
|
||||
Q_DECLARE_METATYPE(wallet::AddressPurpose)
|
||||
#endif // ENABLE_WALLET
|
||||
|
||||
using util::MakeUnorderedList;
|
||||
|
||||
static void RegisterMetaTypes()
|
||||
{
|
||||
// Register meta types used for QMetaObject::invokeMethod and Qt::QueuedConnection
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
|
||||
#include <qt/psbtoperationsdialog.h>
|
||||
|
||||
#include <common/messages.h>
|
||||
#include <core_io.h>
|
||||
#include <interfaces/node.h>
|
||||
#include <key_io.h>
|
||||
#include <node/psbt.h>
|
||||
#include <node/types.h>
|
||||
#include <policy/policy.h>
|
||||
#include <qt/bitcoinunits.h>
|
||||
#include <qt/forms/ui_psbtoperationsdialog.h>
|
||||
@@ -20,9 +22,11 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using common::TransactionErrorString;
|
||||
using node::AnalyzePSBT;
|
||||
using node::DEFAULT_MAX_RAW_TX_FEE_RATE;
|
||||
using node::PSBTAnalysis;
|
||||
using node::TransactionError;
|
||||
|
||||
PSBTOperationsDialog::PSBTOperationsDialog(
|
||||
QWidget* parent, WalletModel* wallet_model, ClientModel* client_model) : QDialog(parent, GUIUtil::dialog_flags),
|
||||
@@ -55,10 +59,10 @@ void PSBTOperationsDialog::openWithPSBT(PartiallySignedTransaction psbtx)
|
||||
bool complete = FinalizePSBT(psbtx); // Make sure all existing signatures are fully combined before checking for completeness.
|
||||
if (m_wallet_model) {
|
||||
size_t n_could_sign;
|
||||
TransactionError err = m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/true, &n_could_sign, m_transaction_data, complete);
|
||||
if (err != TransactionError::OK) {
|
||||
const auto err{m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/true, &n_could_sign, m_transaction_data, complete)};
|
||||
if (err) {
|
||||
showStatus(tr("Failed to load transaction: %1")
|
||||
.arg(QString::fromStdString(TransactionErrorString(err).translated)),
|
||||
.arg(QString::fromStdString(PSBTErrorString(*err).translated)),
|
||||
StatusLevel::ERR);
|
||||
return;
|
||||
}
|
||||
@@ -79,11 +83,11 @@ void PSBTOperationsDialog::signTransaction()
|
||||
|
||||
WalletModel::UnlockContext ctx(m_wallet_model->requestUnlock());
|
||||
|
||||
TransactionError err = m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/true, /*bip32derivs=*/true, &n_signed, m_transaction_data, complete);
|
||||
const auto err{m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/true, /*bip32derivs=*/true, &n_signed, m_transaction_data, complete)};
|
||||
|
||||
if (err != TransactionError::OK) {
|
||||
if (err) {
|
||||
showStatus(tr("Failed to sign transaction: %1")
|
||||
.arg(QString::fromStdString(TransactionErrorString(err).translated)), StatusLevel::ERR);
|
||||
.arg(QString::fromStdString(PSBTErrorString(*err).translated)), StatusLevel::ERR);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -247,9 +251,9 @@ size_t PSBTOperationsDialog::couldSignInputs(const PartiallySignedTransaction &p
|
||||
|
||||
size_t n_signed;
|
||||
bool complete;
|
||||
TransactionError err = m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/false, &n_signed, m_transaction_data, complete);
|
||||
const auto err{m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/false, &n_signed, m_transaction_data, complete)};
|
||||
|
||||
if (err != TransactionError::OK) {
|
||||
if (err) {
|
||||
return 0;
|
||||
}
|
||||
return n_signed;
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#include <QLatin1Char>
|
||||
#include <QLatin1String>
|
||||
|
||||
using util::ToString;
|
||||
|
||||
RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) :
|
||||
QAbstractTableModel(parent), walletModel(parent)
|
||||
{
|
||||
|
||||
@@ -48,6 +48,8 @@
|
||||
|
||||
#include <chrono>
|
||||
|
||||
using util::Join;
|
||||
|
||||
const int CONSOLE_HISTORY = 50;
|
||||
const int INITIAL_TRAFFIC_GRAPH_MINS = 30;
|
||||
const QSize FONT_RANGE(4, 40);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <interfaces/node.h>
|
||||
#include <key_io.h>
|
||||
#include <node/interface_ui.h>
|
||||
#include <node/types.h>
|
||||
#include <policy/fees.h>
|
||||
#include <txmempool.h>
|
||||
#include <validation.h>
|
||||
@@ -37,6 +38,7 @@
|
||||
#include <QSettings>
|
||||
#include <QTextDocument>
|
||||
|
||||
using common::PSBTError;
|
||||
using wallet::CCoinControl;
|
||||
using wallet::DEFAULT_PAY_TX_FEE;
|
||||
|
||||
@@ -442,26 +444,26 @@ void SendCoinsDialog::presentPSBT(PartiallySignedTransaction& psbtx)
|
||||
}
|
||||
|
||||
bool SendCoinsDialog::signWithExternalSigner(PartiallySignedTransaction& psbtx, CMutableTransaction& mtx, bool& complete) {
|
||||
TransactionError err;
|
||||
std::optional<PSBTError> err;
|
||||
try {
|
||||
err = model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/true, /*bip32derivs=*/true, /*n_signed=*/nullptr, psbtx, complete);
|
||||
} catch (const std::runtime_error& e) {
|
||||
QMessageBox::critical(nullptr, tr("Sign failed"), e.what());
|
||||
return false;
|
||||
}
|
||||
if (err == TransactionError::EXTERNAL_SIGNER_NOT_FOUND) {
|
||||
if (err == PSBTError::EXTERNAL_SIGNER_NOT_FOUND) {
|
||||
//: "External signer" means using devices such as hardware wallets.
|
||||
const QString msg = tr("External signer not found");
|
||||
QMessageBox::critical(nullptr, msg, msg);
|
||||
return false;
|
||||
}
|
||||
if (err == TransactionError::EXTERNAL_SIGNER_FAILED) {
|
||||
if (err == PSBTError::EXTERNAL_SIGNER_FAILED) {
|
||||
//: "External signer" means using devices such as hardware wallets.
|
||||
const QString msg = tr("External signer failure");
|
||||
QMessageBox::critical(nullptr, msg, msg);
|
||||
return false;
|
||||
}
|
||||
if (err != TransactionError::OK) {
|
||||
if (err) {
|
||||
tfm::format(std::cerr, "Failed to sign PSBT");
|
||||
processSendCoinsReturn(WalletModel::TransactionCreationFailed);
|
||||
return false;
|
||||
@@ -501,9 +503,9 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
|
||||
PartiallySignedTransaction psbtx(mtx);
|
||||
bool complete = false;
|
||||
// Fill without signing
|
||||
TransactionError err = model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/true, /*n_signed=*/nullptr, psbtx, complete);
|
||||
const auto err{model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/true, /*n_signed=*/nullptr, psbtx, complete)};
|
||||
assert(!complete);
|
||||
assert(err == TransactionError::OK);
|
||||
assert(!err);
|
||||
|
||||
// Copy PSBT to clipboard and offer to save
|
||||
presentPSBT(psbtx);
|
||||
@@ -517,9 +519,9 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
|
||||
bool complete = false;
|
||||
// Always fill without signing first. This prevents an external signer
|
||||
// from being called prematurely and is not expensive.
|
||||
TransactionError err = model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/true, /*n_signed=*/nullptr, psbtx, complete);
|
||||
const auto err{model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/true, /*n_signed=*/nullptr, psbtx, complete)};
|
||||
assert(!complete);
|
||||
assert(err == TransactionError::OK);
|
||||
assert(!err);
|
||||
send_failure = !signWithExternalSigner(psbtx, mtx, complete);
|
||||
// Don't broadcast when user rejects it on the device or there's a failure:
|
||||
broadcast = complete && !send_failure;
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
#include <qt/platformstyle.h>
|
||||
#include <qt/walletmodel.h>
|
||||
|
||||
#include <common/signmessage.h> // For MessageSign(), MessageVerify()
|
||||
#include <config/bitcoin-config.h> // IWYU pragma: keep
|
||||
#include <key_io.h>
|
||||
#include <util/message.h> // For MessageSign(), MessageVerify()
|
||||
#include <wallet/wallet.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <QTimer>
|
||||
#include <QWindow>
|
||||
|
||||
using util::Join;
|
||||
using wallet::WALLET_FLAG_BLANK_WALLET;
|
||||
using wallet::WALLET_FLAG_DESCRIPTORS;
|
||||
using wallet::WALLET_FLAG_DISABLE_PRIVATE_KEYS;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <interfaces/node.h>
|
||||
#include <key_io.h>
|
||||
#include <node/interface_ui.h>
|
||||
#include <node/types.h>
|
||||
#include <psbt.h>
|
||||
#include <util/translation.h>
|
||||
#include <wallet/coincontrol.h>
|
||||
@@ -534,8 +535,8 @@ bool WalletModel::bumpFee(uint256 hash, uint256& new_hash)
|
||||
// "Create Unsigned" clicked
|
||||
PartiallySignedTransaction psbtx(mtx);
|
||||
bool complete = false;
|
||||
const TransactionError err = wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/true, nullptr, psbtx, complete);
|
||||
if (err != TransactionError::OK || complete) {
|
||||
const auto err{wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/true, nullptr, psbtx, complete)};
|
||||
if (err || complete) {
|
||||
QMessageBox::critical(nullptr, tr("Fee bump error"), tr("Can't draft transaction."));
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user