aboutsummaryrefslogtreecommitdiff
path: root/src/simplewallet/simplewallet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/simplewallet/simplewallet.cpp')
-rw-r--r--src/simplewallet/simplewallet.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 4a22dfa25..6cab628e6 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -69,10 +69,12 @@
#include "version.h"
#include <stdexcept>
#include "wallet/message_store.h"
+#include "QrCode.hpp"
#ifdef WIN32
#include <boost/locale.hpp>
#include <boost/filesystem.hpp>
+#include <fcntl.h>
#endif
#ifdef HAVE_READLINE
@@ -268,6 +270,7 @@ namespace
const char* USAGE_RPC_PAYMENT_INFO("rpc_payment_info");
const char* USAGE_START_MINING_FOR_RPC("start_mining_for_rpc");
const char* USAGE_STOP_MINING_FOR_RPC("stop_mining_for_rpc");
+ const char* USAGE_SHOW_QR_CODE("show_qr_code [<subaddress_index>]");
const char* USAGE_VERSION("version");
const char* USAGE_HELP_ADVANCED("help_advanced [<command>]");
const char* USAGE_HELP("help");
@@ -2387,6 +2390,62 @@ bool simple_wallet::stop_mining_for_rpc(const std::vector<std::string> &args)
return true;
}
+bool simple_wallet::show_qr_code(const std::vector<std::string> &args)
+{
+ uint32_t subaddress_index = 0;
+ if (args.size() >= 1)
+ {
+ if (!string_tools::get_xtype_from_string(subaddress_index, args[0]))
+ {
+ fail_msg_writer() << tr("invalid index: must be an unsigned integer");
+ return true;
+ }
+ if (subaddress_index >= m_wallet->get_num_subaddresses(m_current_subaddress_account))
+ {
+ fail_msg_writer() << tr("<subaddress_index> is out of bounds");
+ return true;
+ }
+ }
+
+#ifdef _WIN32
+#define PRINT_UTF8(pre, x) std::wcout << pre ## x
+#define WTEXTON() _setmode(_fileno(stdout), _O_WTEXT)
+#define WTEXTOFF() _setmode(_fileno(stdout), _O_TEXT)
+#else
+#define PRINT_UTF8(pre, x) std::cout << x
+#define WTEXTON()
+#define WTEXTOFF()
+#endif
+
+ WTEXTON();
+ try
+ {
+ const std::string address = "monero:" + m_wallet->get_subaddress_as_str({m_current_subaddress_account, subaddress_index});
+ const qrcodegen::QrCode qr = qrcodegen::QrCode::encodeText(address.c_str(), qrcodegen::QrCode::Ecc::LOW);
+ for (int y = -2; y < qr.getSize() + 2; y+=2)
+ {
+ for (int x = -2; x < qr.getSize() + 2; x++)
+ {
+ if (qr.getModule(x, y) && qr.getModule(x, y + 1))
+ PRINT_UTF8(L, "\u2588");
+ else if (qr.getModule(x, y) && !qr.getModule(x, y + 1))
+ PRINT_UTF8(L, "\u2580");
+ else if (!qr.getModule(x, y) && qr.getModule(x, y + 1))
+ PRINT_UTF8(L, "\u2584");
+ else
+ PRINT_UTF8(L, " ");
+ }
+ PRINT_UTF8(, std::endl);
+ }
+ }
+ catch (const std::length_error&)
+ {
+ fail_msg_writer() << tr("Failed to generate QR code, input too large");
+ }
+ WTEXTOFF();
+ return true;
+}
+
bool simple_wallet::set_always_confirm_transfers(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
{
const auto pwd_container = get_and_verify_password();
@@ -3610,6 +3669,10 @@ simple_wallet::simple_wallet()
boost::bind(&simple_wallet::stop_mining_for_rpc, this, _1),
tr(USAGE_STOP_MINING_FOR_RPC),
tr("Stop mining to pay for RPC access"));
+ m_cmd_binder.set_handler("show_qr_code",
+ boost::bind(&simple_wallet::on_command, this, &simple_wallet::show_qr_code, _1),
+ tr(USAGE_SHOW_QR_CODE),
+ tr("Show address as QR code"));
m_cmd_binder.set_handler("help_advanced",
boost::bind(&simple_wallet::on_command, this, &simple_wallet::help_advanced, _1),
tr(USAGE_HELP_ADVANCED),