Skip to content
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.

Add wallet upgrader binary #876

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/CMakeLists.txt
Expand Up @@ -43,6 +43,7 @@ file(GLOB_RECURSE Wallet wallet/*)
file(GLOB_RECURSE WalletApi walletapi/*)
file(GLOB_RECURSE WalletBackend walletbackend/*)
file(GLOB_RECURSE WalletService walletservice/*)
file(GLOB_RECURSE WalletUpgrader walletupgrader/*)
file(GLOB_RECURSE zedwallet zedwallet/*)
file(GLOB_RECURSE zedwallet++ zedwallet++/*)

Expand All @@ -55,7 +56,7 @@ else ()
endif ()

# Group the files together in IDEs
source_group("" FILES $${Common} ${Config} ${Crypto} ${CryptoNoteCore} ${CryptoNoteProtocol} ${TurtleCoind} ${JsonRpcServer} ${Http} ${Logging} ${Logger} ${miner} ${Mnemonics} ${Nigel} ${NodeRpcProxy} ${P2p} ${Rpc} ${Serialization} ${System} ${Transfers} ${Wallet} ${WalletApi} ${WalletBackend} ${WalletService} ${zedwallet} ${zedwallet++} ${CryptoTest} ${Errors} ${Utilities} ${SubWallets})
source_group("" FILES $${Common} ${Config} ${Crypto} ${CryptoNoteCore} ${CryptoNoteProtocol} ${TurtleCoind} ${JsonRpcServer} ${Http} ${Logging} ${Logger} ${miner} ${Mnemonics} ${Nigel} ${NodeRpcProxy} ${P2p} ${Rpc} ${Serialization} ${System} ${Transfers} ${Wallet} ${WalletApi} ${WalletBackend} ${WalletService} ${zedwallet} ${zedwallet++} ${CryptoTest} ${Errors} ${Utilities} ${WalletUpgrader} ${SubWallets})

# Define a group of files as a library to link against
add_library(BlockchainExplorer STATIC ${BlockchainExplorer})
Expand Down Expand Up @@ -100,13 +101,17 @@ if (MSVC)
set(WALLET_API_SOURCES_OS
binaryinfo/walletapi.rc
)
set(WALLET_UPGRADER_SOURCES_OS
binaryinfo/walletupgrader.rc
)
endif ()

add_executable(cryptotest ${CryptoTest} ${CT_SOURCES_OS})
add_executable(miner ${miner} ${MINER_SOURCES_OS})
add_executable(WalletService ${WalletService} ${PG_SOURCES_OS})
add_executable(TurtleCoind ${TurtleCoind} ${DAEMON_SOURCES_OS})
add_executable(WalletApi ${WalletApi} ${WALLET_API_SOURCES_OS})
add_executable(WalletUpgrader ${WalletUpgrader} ${WALLET_UPGRADER_SOURCES_OS})
add_executable(zedwallet ${zedwallet} ${ZED_WALLET_SOURCES_OS})
add_executable(zedwallet++ ${zedwallet++} ${ZED_WALLET_SOURCES_OS})

Expand All @@ -118,6 +123,7 @@ if (MSVC)
target_link_libraries(WalletApi ws2_32 advapi32 crypt32 gdi32 user32)
target_link_libraries(miner ws2_32 advapi32 crypt32 gdi32 user32)
target_link_libraries(zedwallet ws2_32 advapi32 crypt32 gdi32 user32)
target_link_libraries(WalletUpgrader ws2_32 advapi32 crypt32 gdi32 user32)
endif ()

# A bit of hackery so we don't have to do the if/else/ for every target that
Expand Down Expand Up @@ -157,6 +163,7 @@ target_link_libraries(Wallet NodeRpcProxy Transfers CryptoNoteCore Common Wallet
target_link_libraries(WalletApi WalletBackend)
target_link_libraries(WalletBackend Serialization Mnemonics Nigel cryptopp-static __filesystem Utilities SubWallets Logger Config Wallet)
target_link_libraries(WalletService JsonRpcServer Wallet Mnemonics Errors)
target_link_libraries(WalletUpgrader Utilities WalletBackend Common)
target_link_libraries(zedwallet Mnemonics Wallet Utilities Errors)
target_link_libraries(zedwallet++ WalletBackend)

Expand All @@ -177,6 +184,7 @@ add_dependencies(JsonRpcServer version)
add_dependencies(P2P version)
add_dependencies(Rpc version)
add_dependencies(TurtleCoind version)
add_dependencies(WalletUpgrader version)
add_dependencies(WalletApi version)
add_dependencies(WalletService version)
add_dependencies(zedwallet version)
Expand All @@ -189,6 +197,7 @@ set_property(TARGET WalletService PROPERTY OUTPUT_NAME "turtle-service")
set_property(TARGET miner PROPERTY OUTPUT_NAME "miner")
set_property(TARGET cryptotest PROPERTY OUTPUT_NAME "cryptotest")
set_property(TARGET WalletApi PROPERTY OUTPUT_NAME "wallet-api")
set_property(TARGET WalletUpgrader PROPERTY OUTPUT_NAME "wallet-upgrader")

# Additional make targets, can be used to build a subset of the targets
# e.g. make pool will build only TurtleCoind and service
Expand Down
37 changes: 37 additions & 0 deletions src/binaryinfo/walletupgrader.rc
@@ -0,0 +1,37 @@
#include <windows.h>
#include "version.h"

IDI_ICON1 ICON DISCARDABLE "../config/icon.ico"

VS_VERSION_INFO VERSIONINFO
FILEVERSION APP_VER_MAJOR,APP_VER_MINOR,APP_VER_REV,APP_VER_BUILD
PRODUCTVERSION APP_VER_MAJOR,APP_VER_MINOR,APP_VER_REV,APP_VER_BUILD
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "000004b0"
BEGIN
VALUE "CompanyName", PROJECT_SITE
VALUE "FileDescription", PROJECT_NAME " wallet-upgrader " PROJECT_VERSION_LONG
VALUE "FileVersion", PROJECT_VERSION_BUILD_NO
VALUE "LegalCopyright", PROJECT_COPYRIGHT
VALUE "OriginalFilename", "wallet-upgrader.exe"
VALUE "ProductName", PROJECT_NAME
VALUE "ProductVersion", PROJECT_VERSION
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0, 1200
END
END

4 changes: 3 additions & 1 deletion src/wallet/WalletGreen.cpp
Expand Up @@ -482,7 +482,9 @@ namespace CryptoNote
}
});

ContainerStorage newStorage(path, FileMappedVectorOpenMode::CREATE, m_containerStorage.prefixSize());
ContainerStorage newStorage(path, FileMappedVectorOpenMode::OPEN_OR_CREATE, m_containerStorage.prefixSize());
newStorage.clear();

storageCreated = true;

chacha8_key newStorageKey;
Expand Down
13 changes: 7 additions & 6 deletions src/walletbackend/WalletBackend.h
Expand Up @@ -247,6 +247,12 @@ class WalletBackend

std::vector<std::tuple<std::string, uint64_t, uint64_t>> getBalances() const;

static bool tryUpgradeWalletFormat(
const std::string filename,
const std::string password,
const std::string daemonHost,
const uint16_t daemonPort);

/////////////////////////////
/* Public member variables */
/////////////////////////////
Expand Down Expand Up @@ -291,12 +297,7 @@ class WalletBackend

void init();

static bool tryUpgradeWalletFormat(
const std::string filename,
const std::string password,
const std::string daemonHost,
const uint16_t daemonPort);


//////////////////////////////
/* Private member variables */
//////////////////////////////
Expand Down
160 changes: 160 additions & 0 deletions src/walletupgrader/Main.cpp
@@ -0,0 +1,160 @@
// Copyright (c) 2019, The TurtleCoin Developers
//
// Please see the included LICENSE file for more information.

#include <iostream>

#include <config/CliHeader.h>
#include <common/ConsoleTools.h>
#include <common/FileSystemShim.h>
#include <cxxopts.hpp>
#include <utilities/PasswordContainer.h>
#include <utilities/ColouredMsg.h>
#include <walletbackend/WalletBackend.h>

int main(int argc, char **argv)
{
std::string walletName;
std::string walletPass;

bool help;
bool version;

cxxopts::Options options(argv[0], CryptoNote::getProjectCLIHeader());

options.add_options("Core")(
"h,help", "Display this help message", cxxopts::value<bool>(help)->implicit_value("true"))

("v,version",
"Output software version information",
cxxopts::value<bool>(version)->default_value("false")->implicit_value("true"));

options.add_options("Wallet")(
"w,wallet-file", "Open the wallet <file>", cxxopts::value<std::string>(walletName), "<file>")

("p,password",
"Use the password <pass> to open the wallet",
cxxopts::value<std::string>(walletPass),
"<pass>");

bool walletGiven = false;
bool passGiven = false;

try
{
const auto result = options.parse(argc, argv);

walletGiven = result.count("wallet-file") != 0;

/* We could check if the string is empty, but an empty password is valid */
passGiven = result.count("password") != 0;
}
catch (const cxxopts::OptionException &e)
{
std::cout << "Error: Unable to parse command line argument options: " << e.what() << std::endl << std::endl;
std::cout << options.help({}) << std::endl;
exit(1);
}

if (help) // Do we want to display the help message?
{
std::cout << options.help({}) << std::endl;
exit(0);
}
else if (version) // Do we want to display the software version?
{
std::cout << CryptoNote::getProjectCLIHeader() << std::endl;
exit(0);
}

while (true)
{
std::string filename;

while (true)
{
if (!walletGiven)
{
std::cout << InformationMsg("What is the name of the wallet ") << InformationMsg("you want to upgrade?: ");

std::getline(std::cin, walletName);
}

const std::string walletFileName = walletName + ".wallet";

try
{
if (walletName == "")
{
std::cout << WarningMsg("\nWallet name can't be blank! Try again.\n\n");
}
/* Allow people to enter wallet name with or without file extension */
else if (fs::exists(walletName))
{
filename = walletName;
break;
}
else if (fs::exists(walletFileName))
{
filename = walletFileName;
break;
}
else
{
std::cout << WarningMsg("\nA wallet with the filename ") << InformationMsg(walletName)
<< WarningMsg(" or ") << InformationMsg(walletFileName) << WarningMsg(" doesn't exist!\n")
<< "Ensure you entered your wallet name correctly.\n\n";
}
}
catch (const fs::filesystem_error &)
{
std::cout << WarningMsg("\nInvalid wallet filename! Try again.\n\n");
}

if (walletGiven)
{
return 1;
}
}

if (!passGiven)
{
Tools::PasswordContainer pwdContainer;
pwdContainer.read_password(false, "Enter wallet password: ");
walletPass = pwdContainer.password();
}

passGiven = false;

std::cout << InformationMsg("Upgrading...") << std::endl;

const auto [error, wallet] = WalletBackend::openWallet(filename, walletPass, "DEADBEEF", 0, 1);

if (!error)
{
std::cout << SuccessMsg("Done!") << std::endl;

std::cout << InformationMsg("You can now open your wallet in proton, zedwallet-beta or wallet-api.") << std::endl;
break;
}
else
{
std::cout << WarningMsg("Sorry, we were unable to upgrade your wallet.. Are you sure this is a wallet file?") << std::endl;
std::cout << WarningMsg(error) << std::endl;
std::cout << WarningMsg("Or, maybe you just typed your password wrong.") << std::endl;
std::cout << InformationMsg("Try again.\n") << std::endl;
return 1;
}
}

if (Common::Console::isConsoleTty())
{
std::cout << InformationMsg("Hit enter to exit: ");

std::string dummy;

std::getline(std::cin, dummy);
}

return 0;
}
2 changes: 1 addition & 1 deletion src/zedwallet++/Open.cpp
Expand Up @@ -15,7 +15,7 @@
#include <utilities/Input.h>
#include <utilities/String.h>
#include <zedwallet++/CommandImplementations.h>
#include <zedwallet++/PasswordContainer.h>
#include <utilities/PasswordContainer.h>
#include <zedwallet++/Utilities.h>

std::shared_ptr<WalletBackend> importViewWallet(const ZedConfig &config)
Expand Down
2 changes: 1 addition & 1 deletion src/zedwallet++/Utilities.cpp
Expand Up @@ -12,7 +12,7 @@
#include <iostream>
#include <utilities/ColouredMsg.h>
#include <utilities/String.h>
#include <zedwallet++/PasswordContainer.h>
#include <utilities/PasswordContainer.h>

namespace ZedUtilities
{
Expand Down
2 changes: 1 addition & 1 deletion src/zedwallet/Open.cpp
Expand Up @@ -13,7 +13,7 @@
#include <utilities/ColouredMsg.h>
#include <wallet/WalletErrors.h>
#include <zedwallet/CommandImplementations.h>
#include <zedwallet/PasswordContainer.h>
#include <utilities/PasswordContainer.h>
#include <zedwallet/Tools.h>
#include <zedwallet/Transfer.h>
#include <zedwallet/Types.h>
Expand Down