Skip to content

Commit a904558

Browse files
committed
fix: QML interface compatibility with modern upstream Bitcoin Core
Addresses multiple compilation and runtime issues introduced by incoming interface updates: - qml/bitcoin.cpp: Update ThreadSafeMessageBox UI callback signature and switch LogPrintf to LogInfo. - qml/models/chainmodel.cpp: Avoid calling getBlockHash on a hardcoded snapshot height that is not yet locally fetched; use AssumeutxoData.blockhash natively to prevent out-of-bound crashes. - qml/models/chainmodel.h: Guard out chain headers with Q_MOC_RUN to avoid standard-concept parser errors inside QT automoc. - qml/models/options_model.cpp: Add inline SettingToInt/SettingToBool helpers to operate safely over common::SettingsValue. - qml/models/peerdetailsmodel.h: Fallback to the new presync_height field dynamically inside CNodeStateStats as m_starting_height has been deprecated. - qml/models/walletqmlmodel.cpp: Supply std::nullopt to correctly satisfy the modernized interfaces::Wallet::createTransaction 4-argument parameters interface. - qml/models/transaction.cpp & walletqmlmodel.cpp: Drop obsolete uint256::FromUint256 wrappers in favor of executing the respective Txid.ToUint256() functionality. - qml/peerstatsutil.cpp: Add missing PRIVATE_BROADCAST enum handling inside ConnectionTypeToQString mapping. - test/mocks/mocknode.h: Update getProxy signature and insert missing snapshot & handleSnapshotLoadProgress mock definitions. - qml/walletqmlcontroller.cpp: Provide true for the trailing `load_after_restore` argument on interfaces::WalletLoader::restoreWallet. - qml/models/walletqmlmodel.cpp: Drop trailing nullptr (purpose) as the updated interfaces::Wallet::getAddress now strictly asks for 3 parameters.
1 parent 42830d8 commit a904558

10 files changed

Lines changed: 52 additions & 22 deletions

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ set(USE_QRCODE TRUE)
5454
# We need this libraries, can ignore the executable bitcoin-qt
5555
set(BUILD_GUI ON)
5656
set(ENABLE_WALLET ON)
57+
set(ENABLE_IPC OFF)
5758

5859
# Bitcoin Core codebase
5960
# Builds libraries: univalue, core_interface, bitcoin_node, bitcoin_wallet

qml/bitcoin.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ AppMode SetupAppMode()
122122

123123
bool InitErrorMessageBox(
124124
const bilingual_str& message,
125-
[[maybe_unused]] const std::string& caption,
126125
[[maybe_unused]] unsigned int style)
127126
{
128127
QQmlApplicationEngine engine;
@@ -146,7 +145,7 @@ void DebugMessageHandler(QtMsgType type, const QMessageLogContext& context, cons
146145
if (type == QtDebugMsg) {
147146
LogDebug(BCLog::QT, "GUI: %s\n", msg.toStdString());
148147
} else {
149-
LogPrintf("GUI: %s\n", msg.toStdString());
148+
LogInfo("GUI: %s\n", msg.toStdString());
150149
}
151150
}
152151

qml/models/chainmodel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
#ifndef BITCOIN_QML_MODELS_CHAINMODEL_H
66
#define BITCOIN_QML_MODELS_CHAINMODEL_H
77

8+
#ifndef Q_MOC_RUN
89
#include <chainparams.h>
910
#include <interfaces/chain.h>
11+
#endif
1012

1113
#include <QObject>
1214
#include <QString>

qml/models/options_model.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,32 @@ OptionsQmlModel::OptionsQmlModel(interfaces::Node& node, bool is_onboarded)
4040
: m_node{node}
4141
, m_onboarded{is_onboarded}
4242
{
43+
auto SettingToInt = [](const common::SettingsValue& val, int64_t def) -> int64_t {
44+
if (val.isNull()) return def;
45+
const common::SettingsValue* v = &val;
46+
if (v->isArray() && !v->empty()) {
47+
v = &v->getValues()[0];
48+
}
49+
if (v->isNum()) return v->getInt<int64_t>();
50+
if (v->isStr()) {
51+
try { return std::stoll(v->get_str()); } catch (...) { return def; }
52+
}
53+
return def;
54+
};
55+
auto SettingToBool = [](const common::SettingsValue& val, bool def) -> bool {
56+
if (val.isNull()) return def;
57+
const common::SettingsValue* v = &val;
58+
if (v->isArray() && !v->empty()) {
59+
v = &v->getValues()[0];
60+
}
61+
if (v->isBool()) return v->get_bool();
62+
if (v->isNum()) return v->getInt<int64_t>() != 0;
63+
if (v->isStr()) {
64+
std::string s = v->get_str();
65+
return s == "1" || s == "true" || s == "yes";
66+
}
67+
return def;
68+
};
4369
m_dbcache_size_mib = SettingToInt(m_node.getPersistentSetting("dbcache"), DEFAULT_DB_CACHE >> 20);
4470

4571
m_listen = SettingToBool(m_node.getPersistentSetting("listen"), DEFAULT_LISTEN);

qml/models/peerdetailsmodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class PeerDetailsModel : public QObject
5454
QString services() const { return PeerStatsUtil::FormatServicesStr(m_combinedStats->nodeStateStats.their_services); }
5555
bool transactionRelay() const { return m_combinedStats->nodeStateStats.m_relay_txs; }
5656
bool addressRelay() const { return m_combinedStats->nodeStateStats.m_addr_relay_enabled; }
57-
QString startingHeight() const { return QString::number(m_combinedStats->nodeStateStats.m_starting_height); }
57+
QString startingHeight() const { return QString::number(m_combinedStats->nodeStateStats.presync_height); }
5858
QString syncedHeaders() const { return QString::number(m_combinedStats->nodeStateStats.nSyncHeight); }
5959
QString syncedBlocks() const { return QString::number(m_combinedStats->nodeStateStats.nCommonHeight); }
6060
QString direction() const { return QString::fromStdString(m_combinedStats->nodeStats.fInbound ? "Inbound" : "Outbound"); }

qml/models/transaction.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111
#include <QDateTime>
1212

13-
using wallet::ISMINE_SPENDABLE;
14-
using wallet::ISMINE_NO;
15-
using wallet::isminetype;
16-
1713
namespace {
1814
const int RecommendedNumConfirmations = 6;
1915
}
@@ -138,18 +134,18 @@ QList<QSharedPointer<Transaction>> Transaction::fromWalletTx(const interfaces::W
138134
CAmount nCredit = wtx.credit;
139135
CAmount nDebit = wtx.debit;
140136
CAmount nNet = nCredit - nDebit;
141-
uint256 hash = wtx.tx->GetHash();
137+
uint256 hash = wtx.tx->GetHash().ToUint256();
142138
std::map<std::string, std::string> mapValue = wtx.value_map;
143139

144140
bool involvesWatchAddress = false;
145-
isminetype fAllFromMe = ISMINE_SPENDABLE;
141+
bool fAllFromMe = true;
146142
bool any_from_me = false;
147143
if (wtx.is_coinbase) {
148-
fAllFromMe = ISMINE_NO;
144+
fAllFromMe = false;
149145
} else {
150-
for (const isminetype mine : wtx.txin_is_mine)
146+
for (const bool mine : wtx.txin_is_mine)
151147
{
152-
if(fAllFromMe > mine) fAllFromMe = mine;
148+
if (!mine) fAllFromMe = false;
153149
if (mine) any_from_me = true;
154150
}
155151
}
@@ -202,7 +198,7 @@ QList<QSharedPointer<Transaction>> Transaction::fromWalletTx(const interfaces::W
202198
parts.append(sub);
203199
}
204200

205-
isminetype mine = wtx.txout_is_mine[i];
201+
bool mine = wtx.txout_is_mine[i];
206202
if(mine)
207203
{
208204
//

qml/models/walletqmlmodel.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ QString WalletQmlModel::getAddressLabel(const QString& address) const
233233
}
234234

235235
std::string label;
236-
if (!m_wallet->getAddress(destination, &label, nullptr, nullptr)) {
236+
if (!m_wallet->getAddress(destination, &label, nullptr)) {
237237
return {};
238238
}
239239

@@ -245,7 +245,11 @@ std::unique_ptr<interfaces::Handler> WalletQmlModel::handleTransactionChanged(Tr
245245
if (!m_wallet) {
246246
return nullptr;
247247
}
248-
return m_wallet->handleTransactionChanged(fn);
248+
// Convert the function to match the expected signature
249+
auto converted_fn = [fn](const Txid& txid, ChangeType change_type) {
250+
fn(txid.ToUint256(), change_type);
251+
};
252+
return m_wallet->handleTransactionChanged(converted_fn);
249253
}
250254

251255
bool WalletQmlModel::prepareTransaction()
@@ -269,17 +273,15 @@ bool WalletQmlModel::prepareTransaction()
269273
return false;
270274
}
271275

272-
int nChangePosRet = -1;
273-
CAmount nFeeRequired = 0;
274-
const auto& res = m_wallet->createTransaction(vecSend, m_coin_control, true, nChangePosRet, nFeeRequired);
276+
const auto& res = m_wallet->createTransaction(vecSend, m_coin_control, true, std::nullopt);
275277
if (res) {
276278
if (m_current_transaction) {
277279
delete m_current_transaction;
278280
}
279-
CTransactionRef newTx = *res;
281+
CTransactionRef newTx = res->tx;
280282
m_current_transaction = new WalletQmlModelTransaction(m_send_recipients, this);
281283
m_current_transaction->setWtx(newTx);
282-
m_current_transaction->setTransactionFee(nFeeRequired);
284+
m_current_transaction->setTransactionFee(res->fee);
283285
Q_EMIT currentTransactionChanged();
284286
return true;
285287
} else {

qml/peerstatsutil.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ QString ConnectionTypeToQString(ConnectionType conn_type, bool prepend_direction
3232
case ConnectionType::MANUAL: return prefix + QObject::tr("Manual");
3333
case ConnectionType::FEELER: return prefix + QObject::tr("Feeler");
3434
case ConnectionType::ADDR_FETCH: return prefix + QObject::tr("Address Fetch");
35+
case ConnectionType::PRIVATE_BROADCAST: return prefix + QObject::tr("Private Broadcast");
3536
}
3637
assert(false);
3738
}

qml/walletqmlcontroller.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,8 @@ void WalletQmlController::startWalletImport(const QString& path)
396396
auto wallet = m_node.walletLoader().restoreWallet(
397397
fs::PathFromString(normalized_path.toStdString()),
398398
restore_wallet_name.toStdString(),
399-
warning_messages);
399+
warning_messages,
400+
true);
400401
const QString warnings = JoinWarnings(warning_messages);
401402

402403
if (!wallet) {

test/mocks/mocknode.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ class MockNode : public interfaces::Node
5050
MOCK_METHOD(void, forceSetting, (const std::string&, const common::SettingsValue&), (override));
5151
MOCK_METHOD(void, resetSettings, (), (override));
5252
MOCK_METHOD(void, mapPort, (bool), (override));
53-
MOCK_METHOD(bool, getProxy, (Network, Proxy&), (override));
53+
MOCK_METHOD(std::optional<Proxy>, getProxy, (Network), (override));
54+
MOCK_METHOD((std::unique_ptr<interfaces::Snapshot>), snapshot, (const fs::path&), (override));
55+
MOCK_METHOD((std::unique_ptr<interfaces::Handler>), handleSnapshotLoadProgress, (SnapshotLoadProgressFn), (override));
5456
MOCK_METHOD(size_t, getNodeCount, (ConnectionDirection), (override));
5557
MOCK_METHOD(bool, getNodesStats, (NodesStats&), (override));
5658
MOCK_METHOD(bool, getBanned, (banmap_t&), (override));

0 commit comments

Comments
 (0)