Add dump keys to file command to TUI

This commit is contained in:
jwinterm
2025-12-26 07:51:37 -05:00
parent 846be973c5
commit 5f69baa643
+31 -2
View File
@@ -29,6 +29,8 @@
#include "wallet.h"
#include <charconv>
#include <filesystem>
#include <fstream>
#include <ftxui/component/component.hpp>
#include <ftxui/component/event.hpp>
#include <lws_frontend.h>
@@ -178,6 +180,7 @@ namespace lwcli { namespace view
const ftxui::Element title_;
const ftxui::Component buttons_;
const ftxui::Element display_;
const std::shared_ptr<Monero::Wallet> 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<Monero::Wallet>& 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