From 5f69baa643f5457d752b678bd8e470b2a00586ab Mon Sep 17 00:00:00 2001 From: jwinterm Date: Fri, 26 Dec 2025 07:51:37 -0500 Subject: [PATCH] Add dump keys to file command to TUI --- src/views/settings.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/views/settings.cpp b/src/views/settings.cpp index 7846438..9063752 100644 --- a/src/views/settings.cpp +++ b/src/views/settings.cpp @@ -29,6 +29,8 @@ #include "wallet.h" #include +#include +#include #include #include #include @@ -178,6 +180,7 @@ namespace lwcli { namespace view const ftxui::Element title_; const ftxui::Component buttons_; const ftxui::Element display_; + const std::shared_ptr wal_; bool Focusable() const override final { return true; } ftxui::Component ActiveChild() override final { return buttons_; } @@ -196,12 +199,38 @@ namespace lwcli { namespace view }); } + void DumpKeys() + { + std::string filename = "lwcli_keys_dump.txt"; + std::string wallet_path = wal_->path(); + if (!wallet_path.empty()) + { + std::filesystem::path p(wallet_path); + filename = (p.parent_path() / filename).string(); + } + + std::ofstream out(filename); + if (out) + { + out << "Address: " << wal_->mainAddress() << "\n" + << "Spend Pub: " << wal_->publicSpendKey() << "\n" + << "View Pub: " << wal_->publicViewKey() << "\n" + << "Spend Key: " << wal_->secretSpendKey() << "\n" + << "View Key: " << wal_->secretViewKey() << "\n" + << "Seed: " << wal_->seed({}) << std::endl; + } + } + public: explicit show_keys_(const std::shared_ptr& wal) : ftxui::ComponentBase(), title_(ftxui::text(_("Wallet (Secret) Keys"))), - buttons_(ftxui::Button(_("Close"), [] () { throw event::close{}; }, ascii())), - display_(get_keys(wal)) + buttons_(ftxui::Container::Horizontal({ + ftxui::Button(_("Close"), [] () { throw event::close{}; }, ascii()), + ftxui::Button(_("Dump to File"), [this] { DumpKeys(); }, ascii()) + })), + display_(get_keys(wal)), + wal_(wal) {} bool OnEvent(ftxui::Event event) override final