ObsidianDragon - DragonX ImGui Wallet
Full-node GUI wallet for DragonX cryptocurrency. Built with Dear ImGui, SDL3, and OpenGL3/DX11. Features: - Send/receive shielded and transparent transactions - Autoshield with merged transaction display - Built-in CPU mining (xmrig) - Peer management and network monitoring - Wallet encryption with PIN lock - QR code generation for receive addresses - Transaction history with pagination - Console for direct RPC commands - Cross-platform (Linux, Windows)
This commit is contained in:
258
src/ui/windows/export_all_keys_dialog.cpp
Normal file
258
src/ui/windows/export_all_keys_dialog.cpp
Normal file
@@ -0,0 +1,258 @@
|
||||
// DragonX Wallet - ImGui Edition
|
||||
// Copyright 2024-2026 The Hush Developers
|
||||
// Released under the GPLv3
|
||||
|
||||
#include "export_all_keys_dialog.h"
|
||||
#include "../../app.h"
|
||||
#include "../../rpc/rpc_client.h"
|
||||
#include "../../rpc/rpc_worker.h"
|
||||
#include "../../util/i18n.h"
|
||||
#include "../../util/platform.h"
|
||||
#include "../notifications.h"
|
||||
#include "../schema/ui_schema.h"
|
||||
#include "../material/draw_helpers.h"
|
||||
#include "../material/type.h"
|
||||
#include "../theme.h"
|
||||
#include "../effects/imgui_acrylic.h"
|
||||
#include "../../embedded/IconsMaterialDesign.h"
|
||||
#include "imgui.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <ctime>
|
||||
|
||||
namespace dragonx {
|
||||
namespace ui {
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
// Static state
|
||||
static bool s_open = false;
|
||||
static bool s_exporting = false;
|
||||
static std::string s_status;
|
||||
static std::string s_exported_keys;
|
||||
static int s_total_addresses = 0;
|
||||
static int s_exported_count = 0;
|
||||
static bool s_include_z = true;
|
||||
static bool s_include_t = true;
|
||||
static char s_filename[256] = "";
|
||||
|
||||
void ExportAllKeysDialog::show()
|
||||
{
|
||||
s_open = true;
|
||||
s_exporting = false;
|
||||
s_status.clear();
|
||||
s_exported_keys.clear();
|
||||
s_total_addresses = 0;
|
||||
s_exported_count = 0;
|
||||
s_include_z = true;
|
||||
s_include_t = true;
|
||||
|
||||
// Generate default filename with timestamp
|
||||
std::time_t now = std::time(nullptr);
|
||||
char timebuf[32];
|
||||
std::strftime(timebuf, sizeof(timebuf), "%Y%m%d_%H%M%S", std::localtime(&now));
|
||||
snprintf(s_filename, sizeof(s_filename), "dragonx_keys_%s.txt", timebuf);
|
||||
}
|
||||
|
||||
bool ExportAllKeysDialog::isOpen()
|
||||
{
|
||||
return s_open;
|
||||
}
|
||||
|
||||
void ExportAllKeysDialog::render(App* app)
|
||||
{
|
||||
if (!s_open) return;
|
||||
|
||||
auto& S = schema::UI();
|
||||
auto win = S.window("dialogs.export-all-keys");
|
||||
auto exportBtn = S.button("dialogs.export-all-keys", "export-button");
|
||||
auto closeBtn = S.button("dialogs.export-all-keys", "close-button");
|
||||
|
||||
ImGui::SetNextWindowSize(ImVec2(win.width, win.height), ImGuiCond_FirstUseEver);
|
||||
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
||||
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
||||
ImGui::SetNextWindowFocus();
|
||||
|
||||
const auto& acrylicTheme = GetCurrentAcrylicTheme();
|
||||
ImGui::OpenPopup("Export All Private Keys");
|
||||
if (effects::ImGuiAcrylic::BeginAcrylicPopupModal("Export All Private Keys", &s_open, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar, acrylicTheme.popup)) {
|
||||
// Warning
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.4f, 0.4f, 1.0f));
|
||||
ImGui::PushFont(material::Type().iconSmall());
|
||||
ImGui::Text(ICON_MD_WARNING);
|
||||
ImGui::PopFont();
|
||||
ImGui::SameLine(0, 4.0f);
|
||||
ImGui::TextWrapped("DANGER: This will export ALL private keys from your wallet! "
|
||||
"Anyone with access to this file can steal your funds. "
|
||||
"Store it securely and delete after use.");
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::Separator();
|
||||
ImGui::Spacing();
|
||||
|
||||
if (s_exporting) {
|
||||
ImGui::BeginDisabled();
|
||||
}
|
||||
|
||||
// Options
|
||||
ImGui::Text("Export options:");
|
||||
ImGui::Checkbox("Include Z-addresses (shielded)", &s_include_z);
|
||||
ImGui::Checkbox("Include T-addresses (transparent)", &s_include_t);
|
||||
|
||||
ImGui::Spacing();
|
||||
|
||||
// Filename
|
||||
ImGui::Text("Output filename:");
|
||||
ImGui::SetNextItemWidth(-1);
|
||||
ImGui::InputText("##Filename", s_filename, sizeof(s_filename));
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::TextDisabled("File will be saved in: ~/.config/ObsidianDragon/");
|
||||
|
||||
if (s_exporting) {
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::Separator();
|
||||
ImGui::Spacing();
|
||||
|
||||
// Export button
|
||||
if (s_exporting) {
|
||||
ImGui::BeginDisabled();
|
||||
}
|
||||
|
||||
if (material::StyledButton("Export Keys", ImVec2(exportBtn.width, 0), S.resolveFont(exportBtn.font))) {
|
||||
if (!s_include_z && !s_include_t) {
|
||||
Notifications::instance().warning("Select at least one address type");
|
||||
} else if (!app->rpc() || !app->rpc()->isConnected()) {
|
||||
Notifications::instance().error("Not connected to daemon");
|
||||
} else {
|
||||
s_exporting = true;
|
||||
s_exported_keys.clear();
|
||||
s_exported_count = 0;
|
||||
s_status = "Exporting keys...";
|
||||
|
||||
const auto& state = app->getWalletState();
|
||||
|
||||
// Count total addresses to export
|
||||
s_total_addresses = 0;
|
||||
if (s_include_z) s_total_addresses += static_cast<int>(state.z_addresses.size());
|
||||
if (s_include_t) s_total_addresses += static_cast<int>(state.t_addresses.size());
|
||||
|
||||
if (s_total_addresses == 0) {
|
||||
s_exporting = false;
|
||||
s_status = "No addresses to export";
|
||||
return;
|
||||
}
|
||||
|
||||
// Collect addresses to export (copy for worker thread)
|
||||
std::vector<std::string> z_addrs, t_addrs;
|
||||
if (s_include_z) {
|
||||
for (const auto& a : state.z_addresses) z_addrs.push_back(a.address);
|
||||
}
|
||||
if (s_include_t) {
|
||||
for (const auto& a : state.t_addresses) t_addrs.push_back(a.address);
|
||||
}
|
||||
std::string filename(s_filename);
|
||||
|
||||
// Run all key exports on worker thread
|
||||
if (app->worker()) {
|
||||
app->worker()->post([rpc = app->rpc(), z_addrs, t_addrs, filename]() -> rpc::RPCWorker::MainCb {
|
||||
std::string keys;
|
||||
int exported = 0;
|
||||
int total = static_cast<int>(z_addrs.size() + t_addrs.size());
|
||||
|
||||
// Header
|
||||
keys = "# DragonX Wallet - Private Keys Export\n";
|
||||
keys += "# Generated: ";
|
||||
std::time_t now = std::time(nullptr);
|
||||
char timebuf[64];
|
||||
std::strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S\n", std::localtime(&now));
|
||||
keys += timebuf;
|
||||
keys += "# KEEP THIS FILE SECURE!\n\n";
|
||||
|
||||
// Export Z-addresses
|
||||
if (!z_addrs.empty()) {
|
||||
keys += "# === Z-Addresses (Shielded) ===\n\n";
|
||||
for (const auto& addr : z_addrs) {
|
||||
try {
|
||||
auto result = rpc->call("z_exportkey", {addr});
|
||||
if (result.is_string()) {
|
||||
keys += "# Address: " + addr + "\n";
|
||||
keys += result.get<std::string>() + "\n\n";
|
||||
}
|
||||
} catch (...) {}
|
||||
exported++;
|
||||
}
|
||||
}
|
||||
|
||||
// Export T-addresses
|
||||
if (!t_addrs.empty()) {
|
||||
keys += "# === T-Addresses (Transparent) ===\n\n";
|
||||
for (const auto& addr : t_addrs) {
|
||||
try {
|
||||
auto result = rpc->call("dumpprivkey", {addr});
|
||||
if (result.is_string()) {
|
||||
keys += "# Address: " + addr + "\n";
|
||||
keys += result.get<std::string>() + "\n\n";
|
||||
}
|
||||
} catch (...) {}
|
||||
exported++;
|
||||
}
|
||||
}
|
||||
|
||||
// Save to file (still on worker thread)
|
||||
std::string configDir = util::Platform::getConfigDir();
|
||||
std::string filepath = configDir + "/" + filename;
|
||||
bool writeOk = false;
|
||||
{
|
||||
std::ofstream file(filepath);
|
||||
if (file.is_open()) {
|
||||
file << keys;
|
||||
file.close();
|
||||
writeOk = true;
|
||||
}
|
||||
}
|
||||
|
||||
return [exported, total, filepath, writeOk]() {
|
||||
s_exported_count = exported;
|
||||
s_exporting = false;
|
||||
if (writeOk) {
|
||||
s_status = "Exported to: " + filepath;
|
||||
Notifications::instance().success("Keys exported successfully");
|
||||
} else {
|
||||
s_status = "Failed to write file";
|
||||
Notifications::instance().error("Failed to save key file");
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (s_exporting) {
|
||||
ImGui::EndDisabled();
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled("Exporting %d/%d...", s_exported_count, s_total_addresses);
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
if (material::StyledButton("Close", ImVec2(closeBtn.width, 0), S.resolveFont(closeBtn.font))) {
|
||||
s_open = false;
|
||||
}
|
||||
|
||||
// Status
|
||||
if (!s_status.empty()) {
|
||||
ImGui::Spacing();
|
||||
ImGui::TextWrapped("%s", s_status.c_str());
|
||||
}
|
||||
}
|
||||
effects::ImGuiAcrylic::EndAcrylicPopup();
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
} // namespace dragonx
|
||||
Reference in New Issue
Block a user