Skip to content

Get new address from selected wallet in receive tab #496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: qt6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ find_package(Qt 6.2 MODULE REQUIRED
COMPONENTS ${qt_components}
)
find_package(Libevent 2.1.8 MODULE REQUIRED)
find_package(QRencode MODULE REQUIRED)

# Do not build any executable targets from bitcoin submodule
set(BUILD_BENCH OFF)
Expand All @@ -47,6 +48,7 @@ set(BUILD_TX OFF)
set(BUILD_UTIL OFF)
set(BUILD_UTIL_CHAINSTATE OFF)
set(BUILD_WALLET_TOOL OFF)
set(USE_QRCODE TRUE)
# We need this libraries, can ignore the executable bitcoin-qt
set(BUILD_GUI ON)
set(ENABLE_WALLET ON)
Expand Down Expand Up @@ -100,6 +102,7 @@ target_link_libraries(bitcoinqml
bitcoin_node
univalue
Boost::headers
$<TARGET_NAME_IF_EXISTS:QRencode::QRencode>
Qt6::Qml
Qt6::Quick
Qt6::QuickControls2
Expand Down
71 changes: 71 additions & 0 deletions cmake/module/FindQRencode.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright (c) 2024-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

#[=======================================================================[
FindQRencode
------------

Finds the QRencode header and library.

This is a wrapper around find_package()/pkg_check_modules() commands that:
- facilitates searching in various build environments
- prints a standard log message

#]=======================================================================]

find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_QRencode QUIET libqrencode)
endif()

find_path(QRencode_INCLUDE_DIR
NAMES qrencode.h
HINTS ${PC_QRencode_INCLUDE_DIRS}
)

find_library(QRencode_LIBRARY_RELEASE
NAMES qrencode
HINTS ${PC_QRencode_LIBRARY_DIRS}
)
find_library(QRencode_LIBRARY_DEBUG
NAMES qrencoded qrencode
HINTS ${PC_QRencode_LIBRARY_DIRS}
)
include(SelectLibraryConfigurations)
select_library_configurations(QRencode)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(QRencode
REQUIRED_VARS QRencode_LIBRARY QRencode_INCLUDE_DIR
VERSION_VAR PC_QRencode_VERSION
)

if(QRencode_FOUND)
if(NOT TARGET QRencode::QRencode)
add_library(QRencode::QRencode UNKNOWN IMPORTED)
endif()
if(QRencode_LIBRARY_RELEASE)
set_property(TARGET QRencode::QRencode APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE
)
set_target_properties(QRencode::QRencode PROPERTIES
IMPORTED_LOCATION_RELEASE "${QRencode_LIBRARY_RELEASE}"
)
endif()
if(QRencode_LIBRARY_DEBUG)
set_property(TARGET QRencode::QRencode APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG
)
set_target_properties(QRencode::QRencode PROPERTIES
IMPORTED_LOCATION_DEBUG "${QRencode_LIBRARY_DEBUG}"
)
endif()
set_target_properties(QRencode::QRencode PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${QRencode_INCLUDE_DIR}"
)
endif()

mark_as_advanced(
QRencode_INCLUDE_DIR
)
10 changes: 10 additions & 0 deletions qml/models/walletqmlmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ QString WalletQmlModel::name() const
return QString::fromStdString(m_wallet->getWalletName());
}

QString WalletQmlModel::newAddress(QString label)
{
if (!m_wallet) {
return QString();
}
OutputType output_type = m_wallet->getDefaultAddressType();
util::Result<CTxDestination> dest{m_wallet->getNewDestination(output_type, label.toStdString())};
return QString::fromStdString(EncodeDestination(dest.value()));
}

std::set<interfaces::WalletTx> WalletQmlModel::getWalletTxs() const
{
if (!m_wallet) {
Expand Down
1 change: 1 addition & 0 deletions qml/models/walletqmlmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class WalletQmlModel : public QObject
WalletQmlModelTransaction* currentTransaction() const { return m_current_transaction; }
Q_INVOKABLE bool prepareTransaction();
Q_INVOKABLE void sendTransaction();
Q_INVOKABLE QString newAddress(QString label);

std::set<interfaces::WalletTx> getWalletTxs() const;
interfaces::WalletTx getWalletTx(const uint256& hash) const;
Expand Down
28 changes: 21 additions & 7 deletions qml/pages/wallet/RequestPayment.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Page {
background: null

property int requestCounter: 0
property WalletQmlModel wallet: walletController.selectedWallet

ScrollView {
clip: true
Expand Down Expand Up @@ -198,13 +199,23 @@ Page {
requestCounter = requestCounter + 1
clearRequest.visible = true
title.text = qsTr("Payment request #" + requestCounter)
address.text = "bc1q f5xe y2tf 89k9 zy6k gnru wszy 5fsa truy 9te1 bu"
qrImage.code = "bc1qf5xey2tf89k9zy6kgnruwszy5fsatruy9te1bu"
var newAddress = root.wallet.newAddress(label.text)
var groupedAddress = newAddress.replace(/(.{4})/g, "$1 ").trim()
address.text = groupedAddress
qrImage.code = newAddress
continueButton.text = qsTr("Copy payment request")
}
}
}

function clear() {
clearRequest.visible = false
title.text = qsTr("Request a payment")
address.text = ""
qrImage.code = ""
continueButton.text = qsTr("Create bitcoin address")
}

ContinueButton {
id: clearRequest
Layout.fillWidth: true
Expand All @@ -218,11 +229,14 @@ Page {
backgroundPressedColor: "transparent"
text: qsTr("Clear")
onClicked: {
clearRequest.visible = false
title.text = qsTr("Request a payment")
address.text = ""
qrImage.code = ""
continueButton.text = qsTr("Create bitcoin address")
columnLayout.clear()
}
}

Connections {
target: walletController
function onSelectedWalletChanged() {
columnLayout.clear()
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions qml/qrimageprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

#include <qml/qrimageprovider.h>

#if defined(HAVE_CONFIG_H)
#include <config/bitcoin-config.h> /* for USE_QRCODE */
#endif
#include <bitcoin-build-config.h> // IWYU pragma: keep

#ifdef USE_QRCODE
#include <qrencode.h>
Expand Down
Loading