replace 'multisig()' with 'get_multisig_status()' using multisig_account_status and including '.kex_is_done' member

This commit is contained in:
koe 2021-08-11 07:35:43 -05:00
parent c5d10a4ac4
commit 8d94d08816
11 changed files with 197 additions and 154 deletions

View file

@ -65,7 +65,7 @@ using namespace epee;
#define CHECK_MULTISIG_ENABLED() \
do \
{ \
if (m_wallet->multisig() && !m_wallet->is_multisig_enabled()) \
if (m_wallet->get_multisig_status().multisig_is_active && !m_wallet->is_multisig_enabled()) \
{ \
er.code = WALLET_RPC_ERROR_CODE_DISABLED; \
er.message = "This wallet is multisig, and multisig is disabled. Multisig is an experimental feature and may have bugs. Things that could go wrong include: funds sent to a multisig wallet can't be spent at all, can only be spent with the participation of a malicious group member, or can be stolen by a malicious group member. You can enable it by running this once in monero-wallet-cli: set enable-multisig-experimental 1"; \
@ -459,7 +459,7 @@ namespace tools
{
res.balance = req.all_accounts ? m_wallet->balance_all(req.strict) : m_wallet->balance(req.account_index, req.strict);
res.unlocked_balance = req.all_accounts ? m_wallet->unlocked_balance_all(req.strict, &res.blocks_to_unlock, &res.time_to_unlock) : m_wallet->unlocked_balance(req.account_index, req.strict, &res.blocks_to_unlock, &res.time_to_unlock);
res.multisig_import_needed = m_wallet->multisig() && m_wallet->has_multisig_partial_key_images();
res.multisig_import_needed = m_wallet->get_multisig_status().multisig_is_active && m_wallet->has_multisig_partial_key_images();
std::map<uint32_t, std::map<uint32_t, uint64_t>> balance_per_subaddress_per_account;
std::map<uint32_t, std::map<uint32_t, std::pair<uint64_t, std::pair<uint64_t, uint64_t>>>> unlocked_balance_per_subaddress_per_account;
if (req.all_accounts)
@ -1018,7 +1018,7 @@ namespace tools
fill(spent_key_images, key_image_list);
}
if (m_wallet->multisig())
if (m_wallet->get_multisig_status().multisig_is_active)
{
multisig_txset = epee::string_tools::buff_to_hex_nodelimer(m_wallet->save_multisig_tx(ptx_vector));
if (multisig_txset.empty())
@ -2060,10 +2060,11 @@ namespace tools
if (req.key_type.compare("mnemonic") == 0)
{
epee::wipeable_string seed;
bool ready;
if (m_wallet->multisig(&ready))
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)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is multisig, but not yet finalized";
@ -3942,7 +3943,14 @@ namespace tools
bool wallet_rpc_server::on_is_multisig(const wallet_rpc::COMMAND_RPC_IS_MULTISIG::request& req, wallet_rpc::COMMAND_RPC_IS_MULTISIG::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
res.multisig = m_wallet->multisig(&res.ready, &res.threshold, &res.total);
const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
res.multisig = ms_status.multisig_is_active;
res.kex_is_done = ms_status.kex_is_done;
res.ready = ms_status.is_ready;
res.threshold = ms_status.threshold;
res.total = ms_status.total;
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
@ -3955,7 +3963,7 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
if (m_wallet->multisig())
if (m_wallet->get_multisig_status().multisig_is_active)
{
er.code = WALLET_RPC_ERROR_CODE_ALREADY_MULTISIG;
er.message = "This wallet is already multisig";
@ -3984,7 +3992,7 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
if (m_wallet->multisig())
if (m_wallet->get_multisig_status().multisig_is_active)
{
er.code = WALLET_RPC_ERROR_CODE_ALREADY_MULTISIG;
er.message = "This wallet is already multisig";
@ -4022,14 +4030,15 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
bool ready;
if (!m_wallet->multisig(&ready))
const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
if (!ms_status.multisig_is_active)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is not multisig";
return false;
}
if (!ready)
if (!ms_status.is_ready)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is multisig, but not yet finalized";
@ -4063,15 +4072,15 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
bool ready;
uint32_t threshold, total;
if (!m_wallet->multisig(&ready, &threshold, &total))
const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
if (!ms_status.multisig_is_active)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is not multisig";
return false;
}
if (!ready)
if (!ms_status.is_ready)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is multisig, but not yet finalized";
@ -4079,7 +4088,7 @@ namespace tools
}
CHECK_MULTISIG_ENABLED();
if (req.info.size() < threshold - 1)
if (req.info.size() + 1 < ms_status.threshold)
{
er.code = WALLET_RPC_ERROR_CODE_THRESHOLD_NOT_REACHED;
er.message = "Needs multisig export info from more participants";
@ -4143,9 +4152,9 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
bool ready;
uint32_t threshold, total;
if (!m_wallet->multisig(&ready, &threshold, &total))
multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
if (!ms_status.multisig_is_active)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is not multisig";
@ -4153,7 +4162,7 @@ namespace tools
}
CHECK_MULTISIG_ENABLED();
if (req.multisig_info.size() + 1 < total)
if (req.multisig_info.size() + 1 < ms_status.total)
{
er.code = WALLET_RPC_ERROR_CODE_THRESHOLD_NOT_REACHED;
er.message = "Needs multisig info from more participants";
@ -4163,8 +4172,8 @@ namespace tools
try
{
res.multisig_info = m_wallet->exchange_multisig_keys(req.password, req.multisig_info, req.force_update_use_with_caution);
m_wallet->multisig(&ready);
if (ready)
ms_status = m_wallet->get_multisig_status();
if (ms_status.is_ready)
{
res.address = m_wallet->get_account().get_public_address_str(m_wallet->nettype());
}
@ -4187,15 +4196,15 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
bool ready;
uint32_t threshold, total;
if (!m_wallet->multisig(&ready, &threshold, &total))
const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
if (!ms_status.multisig_is_active)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is not multisig";
return false;
}
if (!ready)
if (!ms_status.is_ready)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is multisig, but not yet finalized";
@ -4257,15 +4266,15 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
bool ready;
uint32_t threshold, total;
if (!m_wallet->multisig(&ready, &threshold, &total))
const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
if (!ms_status.multisig_is_active)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is not multisig";
return false;
}
if (!ready)
if (!ms_status.is_ready)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is multisig, but not yet finalized";
@ -4290,7 +4299,7 @@ namespace tools
return false;
}
if (txs.m_signers.size() < threshold)
if (txs.m_signers.size() < ms_status.threshold)
{
er.code = WALLET_RPC_ERROR_CODE_THRESHOLD_NOT_REACHED;
er.message = "Not enough signers signed this transaction.";