upstream: sync against wallet_keys_unlocker PR #9860

This commit is contained in:
jeffro256
2025-04-24 00:03:19 -05:00
committed by akildemir
parent 66552f14ca
commit 638034c35f
10 changed files with 551 additions and 274 deletions
+69 -77
View File
@@ -898,7 +898,6 @@ bool simple_wallet::print_seed(bool encrypted)
{
bool success = false;
epee::wipeable_string seed;
bool ready, multisig;
if (m_wallet->key_on_device())
{
@@ -912,10 +911,10 @@ bool simple_wallet::print_seed(bool encrypted)
}
CHECK_IF_BACKGROUND_SYNCING("has no seed");
multisig = m_wallet->multisig(&ready);
if (multisig)
const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
if (ms_status.multisig_is_active)
{
if (!ready)
if (!ms_status.is_ready)
{
fail_msg_writer() << tr("wallet is multisig but not yet finalized");
return true;
@@ -924,7 +923,7 @@ bool simple_wallet::print_seed(bool encrypted)
SCOPED_WALLET_UNLOCK();
if (!multisig && !m_wallet->is_deterministic())
if (!ms_status.multisig_is_active && !m_wallet->is_deterministic())
{
fail_msg_writer() << tr("wallet is non-deterministic and has no seed");
return true;
@@ -939,7 +938,7 @@ bool simple_wallet::print_seed(bool encrypted)
seed_pass = pwd_container->password();
}
if (multisig)
if (ms_status.multisig_is_active)
success = m_wallet->get_multisig_seed(seed, seed_pass);
else if (m_wallet->is_deterministic())
success = m_wallet->get_seed(seed, seed_pass);
@@ -978,7 +977,7 @@ bool simple_wallet::seed_set_language(const std::vector<std::string> &args/* = s
fail_msg_writer() << tr("command not supported by HW wallet");
return true;
}
if (m_wallet->multisig())
if (m_wallet->get_multisig_status().multisig_is_active)
{
fail_msg_writer() << tr("wallet is multisig and has no seed");
return true;
@@ -1125,7 +1124,7 @@ bool simple_wallet::prepare_multisig_main(const std::vector<std::string> &args,
fail_msg_writer() << tr("command not supported by HW wallet");
return false;
}
if (m_wallet->multisig())
if (m_wallet->get_multisig_status().multisig_is_active)
{
fail_msg_writer() << tr("This wallet is already multisig");
return false;
@@ -1173,7 +1172,7 @@ bool simple_wallet::make_multisig_main(const std::vector<std::string> &args, boo
fail_msg_writer() << tr("command not supported by HW wallet");
return false;
}
if (m_wallet->multisig())
if (m_wallet->get_multisig_status().multisig_is_active)
{
fail_msg_writer() << tr("This wallet is already multisig");
return false;
@@ -1218,9 +1217,7 @@ bool simple_wallet::make_multisig_main(const std::vector<std::string> &args, boo
auto local_args = args;
local_args.erase(local_args.begin());
std::string multisig_extra_info = m_wallet->make_multisig(orig_pwd_container->password(), local_args, threshold);
bool ready;
m_wallet->multisig(&ready);
if (!ready)
if (!m_wallet->get_multisig_status().is_ready)
{
success_msg_writer() << tr("Another step is needed");
success_msg_writer() << multisig_extra_info;
@@ -1238,13 +1235,13 @@ bool simple_wallet::make_multisig_main(const std::vector<std::string> &args, boo
return false;
}
uint32_t total;
if (!m_wallet->multisig(NULL, &threshold, &total))
const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
if (!ms_status.multisig_is_active)
{
fail_msg_writer() << tr("Error creating multisig: new wallet is not multisig");
return false;
}
success_msg_writer() << std::to_string(threshold) << "/" << total << tr(" multisig address: ")
success_msg_writer() << std::to_string(ms_status.threshold) << "/" << ms_status.total << tr(" multisig address: ")
<< m_wallet->get_account().get_public_address_str(m_wallet->nettype());
return true;
@@ -1270,18 +1267,18 @@ bool simple_wallet::exchange_multisig_keys_main(const std::vector<std::string> &
const bool force_update_use_with_caution,
const bool called_by_mms) {
CHECK_MULTISIG_ENABLED();
bool ready;
const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
if (m_wallet->key_on_device())
{
fail_msg_writer() << tr("command not supported by HW wallet");
return false;
}
if (!m_wallet->multisig(&ready))
if (!ms_status.multisig_is_active)
{
fail_msg_writer() << tr("This wallet is not multisig");
return false;
}
if (ready)
if (ms_status.is_ready)
{
fail_msg_writer() << tr("This wallet is already finalized");
return false;
@@ -1297,9 +1294,7 @@ bool simple_wallet::exchange_multisig_keys_main(const std::vector<std::string> &
try
{
std::string multisig_extra_info = m_wallet->exchange_multisig_keys(orig_pwd_container->password(), args, force_update_use_with_caution);
bool ready;
m_wallet->multisig(&ready);
if (!ready)
if (!m_wallet->get_multisig_status().is_ready)
{
message_writer() << tr("Another step is needed");
message_writer() << multisig_extra_info;
@@ -1310,9 +1305,8 @@ bool simple_wallet::exchange_multisig_keys_main(const std::vector<std::string> &
}
return true;
} else {
uint32_t threshold, total;
m_wallet->multisig(NULL, &threshold, &total);
success_msg_writer() << tr("Multisig wallet has been successfully created. Current wallet type: ") << threshold << "/" << total;
const multisig::multisig_account_status ms_status_new{m_wallet->get_multisig_status()};
success_msg_writer() << tr("Multisig wallet has been successfully created. Current wallet type: ") << ms_status_new.threshold << "/" << ms_status_new.total;
success_msg_writer() << tr("Multisig address: ") << m_wallet->get_account().get_public_address_str(m_wallet->nettype());
}
}
@@ -1335,18 +1329,18 @@ bool simple_wallet::export_multisig(const std::vector<std::string> &args)
bool simple_wallet::export_multisig_main(const std::vector<std::string> &args, bool called_by_mms)
{
CHECK_MULTISIG_ENABLED();
bool ready;
const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
if (m_wallet->key_on_device())
{
fail_msg_writer() << tr("command not supported by HW wallet");
return false;
}
if (!m_wallet->multisig(&ready))
if (!ms_status.multisig_is_active)
{
fail_msg_writer() << tr("This wallet is not multisig");
return false;
}
if (!ready)
if (!ms_status.is_ready)
{
fail_msg_writer() << tr("This multisig wallet is not yet finalized");
return false;
@@ -1402,24 +1396,24 @@ bool simple_wallet::import_multisig(const std::vector<std::string> &args)
bool simple_wallet::import_multisig_main(const std::vector<std::string> &args, bool called_by_mms)
{
CHECK_MULTISIG_ENABLED();
bool ready;
uint32_t threshold, total;
const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
if (m_wallet->key_on_device())
{
fail_msg_writer() << tr("command not supported by HW wallet");
return false;
}
if (!m_wallet->multisig(&ready, &threshold, &total))
if (!ms_status.multisig_is_active)
{
fail_msg_writer() << tr("This wallet is not multisig");
return false;
}
if (!ready)
if (!ms_status.is_ready)
{
fail_msg_writer() << tr("This multisig wallet is not yet finalized");
return false;
}
if (args.size() < threshold - 1)
if (args.size() + 1 < ms_status.threshold)
{
PRINT_USAGE(USAGE_IMPORT_MULTISIG_INFO);
return false;
@@ -1499,18 +1493,19 @@ bool simple_wallet::sign_multisig(const std::vector<std::string> &args)
bool simple_wallet::sign_multisig_main(const std::vector<std::string> &args, bool called_by_mms)
{
CHECK_MULTISIG_ENABLED();
bool ready;
const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};\
if (m_wallet->key_on_device())
{
fail_msg_writer() << tr("command not supported by HW wallet");
return false;
}
if(!m_wallet->multisig(&ready))
if (!ms_status.multisig_is_active)
{
fail_msg_writer() << tr("This is not a multisig wallet");
return false;
}
if (!ready)
if (!ms_status.is_ready)
{
fail_msg_writer() << tr("This multisig wallet is not yet finalized");
return false;
@@ -1584,9 +1579,7 @@ bool simple_wallet::sign_multisig_main(const std::vector<std::string> &args, boo
if (txids.empty())
{
uint32_t threshold;
m_wallet->multisig(NULL, &threshold);
uint32_t signers_needed = threshold - signers - 1;
uint32_t signers_needed = ms_status.threshold - signers - 1;
success_msg_writer(true) << tr("Transaction successfully signed to file ") << filename << ", "
<< signers_needed << " more signer(s) needed";
return true;
@@ -1616,19 +1609,19 @@ bool simple_wallet::submit_multisig(const std::vector<std::string> &args)
bool simple_wallet::submit_multisig_main(const std::vector<std::string> &args, bool called_by_mms)
{
CHECK_MULTISIG_ENABLED();
bool ready;
uint32_t threshold;
const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
if (m_wallet->key_on_device())
{
fail_msg_writer() << tr("command not supported by HW wallet");
return false;
}
if (!m_wallet->multisig(&ready, &threshold))
if (!ms_status.multisig_is_active)
{
fail_msg_writer() << tr("This is not a multisig wallet");
return false;
}
if (!ready)
if (!ms_status.is_ready)
{
fail_msg_writer() << tr("This multisig wallet is not yet finalized");
return false;
@@ -1666,10 +1659,10 @@ bool simple_wallet::submit_multisig_main(const std::vector<std::string> &args, b
return false;
}
}
if (txs.m_signers.size() < threshold)
if (txs.m_signers.size() < ms_status.threshold)
{
fail_msg_writer() << (boost::format(tr("Multisig transaction signed by only %u signers, needs %u more signatures"))
% txs.m_signers.size() % (threshold - txs.m_signers.size())).str();
% txs.m_signers.size() % (ms_status.threshold - txs.m_signers.size())).str();
return false;
}
@@ -1698,19 +1691,19 @@ bool simple_wallet::submit_multisig_main(const std::vector<std::string> &args, b
bool simple_wallet::export_raw_multisig(const std::vector<std::string> &args)
{
CHECK_MULTISIG_ENABLED();
bool ready;
uint32_t threshold;
const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
if (m_wallet->key_on_device())
{
fail_msg_writer() << tr("command not supported by HW wallet");
return true;
}
if (!m_wallet->multisig(&ready, &threshold))
if (!ms_status.multisig_is_active)
{
fail_msg_writer() << tr("This is not a multisig wallet");
return true;
}
if (!ready)
if (!ms_status.is_ready)
{
fail_msg_writer() << tr("This multisig wallet is not yet finalized");
return true;
@@ -1736,10 +1729,10 @@ bool simple_wallet::export_raw_multisig(const std::vector<std::string> &args)
fail_msg_writer() << tr("Failed to load multisig transaction from file");
return true;
}
if (txs.m_signers.size() < threshold)
if (txs.m_signers.size() < ms_status.threshold)
{
fail_msg_writer() << (boost::format(tr("Multisig transaction signed by only %u signers, needs %u more signatures"))
% txs.m_signers.size() % (threshold - txs.m_signers.size())).str();
% txs.m_signers.size() % (ms_status.threshold - txs.m_signers.size())).str();
return true;
}
@@ -3082,7 +3075,7 @@ bool simple_wallet::set_track_uses(const std::vector<std::string> &args/* = std:
bool simple_wallet::setup_background_sync(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
{
if (m_wallet->multisig())
if (m_wallet->get_multisig_status().multisig_is_active)
{
fail_msg_writer() << tr("background sync not implemented for multisig wallet");
return true;
@@ -4311,7 +4304,7 @@ void simple_wallet::print_seed(const epee::wipeable_string &seed)
{
success_msg_writer(true) << "\n" << boost::format(tr("NOTE: the following %s can be used to recover access to your wallet. "
"Write them down and store them somewhere safe and secure. Please do not store them in "
"your email or on file storage services outside of your immediate control.\n")) % (m_wallet->multisig() ? tr("string") : tr("25 words"));
"your email or on file storage services outside of your immediate control.\n")) % (m_wallet->get_multisig_status().multisig_is_active ? tr("string") : tr("25 words"));
// don't log
int space_index = 0;
size_t len = seed.size();
@@ -5332,7 +5325,7 @@ boost::optional<epee::wipeable_string> simple_wallet::new_wallet(const boost::pr
}
//----------------------------------------------------------------------------------------------------
boost::optional<epee::wipeable_string> simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
const epee::wipeable_string &multisig_keys, const epee::wipeable_string &seed_pass, const std::string &old_language)
const epee::wipeable_string &multisig_keys, const epee::wipeable_string &seed_pass, const std::string &old_language)
{
std::pair<std::unique_ptr<tools::wallet2>, tools::password_container> rc;
try { rc = tools::wallet2::make_new(vm, false, password_prompter); }
@@ -5376,14 +5369,14 @@ boost::optional<epee::wipeable_string> simple_wallet::new_wallet(const boost::pr
const epee::wipeable_string &msig_keys = m_wallet->decrypt<epee::wipeable_string>(std::string(multisig_keys.data(), multisig_keys.size()), key, true);
m_wallet->generate(m_wallet_file, std::move(rc.second).password(), msig_keys, create_address_file);
}
bool ready;
uint32_t threshold, total;
if (!m_wallet->multisig(&ready, &threshold, &total) || !ready)
const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
if (!ms_status.multisig_is_active || !ms_status.is_ready)
{
fail_msg_writer() << tr("failed to generate new mutlisig wallet");
return {};
}
message_writer(console_color_white, true) << boost::format(tr("Generated new %u/%u multisig wallet: ")) % threshold % total
message_writer(console_color_white, true) << boost::format(tr("Generated new %u/%u multisig wallet: ")) % ms_status.threshold % ms_status.total
<< m_wallet->get_account().get_public_address_str(m_wallet->nettype());
}
catch (const std::exception& e)
@@ -5427,12 +5420,11 @@ boost::optional<epee::wipeable_string> simple_wallet::open_wallet(const boost::p
m_wallet->callback(this);
m_wallet->load(m_wallet_file, password);
std::string prefix;
bool ready;
uint32_t threshold, total;
const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
if (m_wallet->watch_only())
prefix = tr("Opened watch-only wallet");
else if (m_wallet->multisig(&ready, &threshold, &total))
prefix = (boost::format(tr("Opened %u/%u multisig wallet%s")) % threshold % total % (ready ? "" : " (not yet finalized)")).str();
else if (ms_status.multisig_is_active)
prefix = (boost::format(tr("Opened %u/%u multisig wallet%s")) % ms_status.threshold % ms_status.total % (ms_status.is_ready ? "" : " (not yet finalized)")).str();
else if (m_wallet->is_background_wallet())
prefix = tr("Opened background wallet");
else
@@ -5553,7 +5545,7 @@ bool simple_wallet::save(const std::vector<std::string> &args)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::save_watch_only(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
{
if (m_wallet->multisig())
if (m_wallet->get_multisig_status().multisig_is_active)
{
fail_msg_writer() << tr("wallet is multisig and cannot save a watch-only version");
return true;
@@ -7362,7 +7354,7 @@ bool simple_wallet::transfer_main(
}
// actually commit the transactions
if (m_wallet->multisig() && called_by_mms)
if (m_wallet->get_multisig_status().multisig_is_active && called_by_mms)
{
std::string ciphertext = m_wallet->save_multisig_tx(ptx_vector);
if (!ciphertext.empty())
@@ -7371,7 +7363,7 @@ bool simple_wallet::transfer_main(
success_msg_writer(true) << tr("Unsigned transaction(s) successfully written to MMS");
}
}
else if (m_wallet->multisig())
else if (m_wallet->get_multisig_status().multisig_is_active)
{
bool r = m_wallet->save_multisig_tx(ptx_vector, "multisig_salvium_tx");
if (!r)
@@ -7579,7 +7571,7 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
}
// actually commit the transactions
if (m_wallet->multisig())
if (m_wallet->get_multisig_status().multisig_is_active)
{
CHECK_MULTISIG_ENABLED();
bool r = m_wallet->save_multisig_tx(ptx_vector, "multisig_salvium_tx");
@@ -7888,7 +7880,7 @@ bool simple_wallet::sweep_main(uint32_t account, uint64_t below, bool locked, co
}
// actually commit the transactions
if (m_wallet->multisig())
if (m_wallet->get_multisig_status().multisig_is_active)
{
CHECK_MULTISIG_ENABLED();
bool r = m_wallet->save_multisig_tx(ptx_vector, "multisig_salvium_tx");
@@ -8124,7 +8116,7 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
}
// actually commit the transactions
if (m_wallet->multisig())
if (m_wallet->get_multisig_status().multisig_is_active)
{
CHECK_MULTISIG_ENABLED();
bool r = m_wallet->save_multisig_tx(ptx_vector, "multisig_salvium_tx");
@@ -8375,7 +8367,7 @@ bool simple_wallet::return_payment(const std::vector<std::string> &args_)
}
// actually commit the transactions
if (m_wallet->multisig())
if (m_wallet->get_multisig_status().multisig_is_active)
{
CHECK_MULTISIG_ENABLED();
bool r = m_wallet->save_multisig_tx(ptx_vector, "multisig_salvium_tx");
@@ -8577,7 +8569,7 @@ bool simple_wallet::audit(const std::vector<std::string> &args_)
return true;
}
if(m_wallet->multisig())
if(m_wallet->get_multisig_status().multisig_is_active)
{
fail_msg_writer() << tr("This is a multisig wallet, staking is not currently supported");
return true;
@@ -8606,7 +8598,7 @@ bool simple_wallet::stake(const std::vector<std::string> &args_)
return true;
}
if(m_wallet->multisig())
if(m_wallet->get_multisig_status().multisig_is_active)
{
fail_msg_writer() << tr("This is a multisig wallet, staking is not currently supported");
return true;
@@ -8994,7 +8986,7 @@ bool simple_wallet::sign_transfer(const std::vector<std::string> &args_)
fail_msg_writer() << tr("command not supported by HW wallet");
return true;
}
if(m_wallet->multisig())
if(m_wallet->get_multisig_status().multisig_is_active)
{
fail_msg_writer() << tr("This is a multisig wallet, it can only sign with sign_multisig");
return true;
@@ -9536,7 +9528,7 @@ bool simple_wallet::get_reserve_proof(const std::vector<std::string> &args)
return true;
}
if (m_wallet->watch_only() || m_wallet->multisig())
if (m_wallet->watch_only() || m_wallet->get_multisig_status().multisig_is_active)
{
fail_msg_writer() << tr("The reserve proof can be generated only by a full wallet");
return true;
@@ -11160,8 +11152,8 @@ bool simple_wallet::status(const std::vector<std::string> &args)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::wallet_info(const std::vector<std::string> &args)
{
bool ready;
uint32_t threshold, total;
const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
std::string description = m_wallet->get_description();
if (description.empty())
{
@@ -11173,8 +11165,8 @@ bool simple_wallet::wallet_info(const std::vector<std::string> &args)
std::string type;
if (m_wallet->watch_only())
type = tr("Watch only");
else if (m_wallet->multisig(&ready, &threshold, &total))
type = (boost::format(tr("%u/%u multisig%s")) % threshold % total % (ready ? "" : " (not yet finalized)")).str();
else if (ms_status.multisig_is_active)
type = (boost::format(tr("%u/%u multisig%s")) % ms_status.threshold % ms_status.total % (ms_status.is_ready ? "" : " (not yet finalized)")).str();
else if (m_wallet->is_background_wallet())
type = tr("Background wallet");
else
@@ -11204,7 +11196,7 @@ bool simple_wallet::sign(const std::vector<std::string> &args)
fail_msg_writer() << tr("wallet is watch-only and cannot sign");
return true;
}
if (m_wallet->multisig())
if (m_wallet->get_multisig_status().multisig_is_active)
{
fail_msg_writer() << tr("This wallet is multisig and cannot sign");
return true;