mirror of
https://github.com/monero-project/monero.git
synced 2025-01-18 08:44:49 +00:00
freeze/that/isFrozen by public key
This commit is contained in:
parent
82f81c0e14
commit
9d9c73e442
5 changed files with 87 additions and 0 deletions
|
@ -30,8 +30,10 @@
|
|||
|
||||
|
||||
#include "wallet.h"
|
||||
#include "crypto/crypto.h"
|
||||
#include "enote_details.h"
|
||||
#include "pending_transaction.h"
|
||||
#include "string_tools.h"
|
||||
#include "unsigned_transaction.h"
|
||||
#include "transaction_history.h"
|
||||
#include "address_book.h"
|
||||
|
@ -2934,6 +2936,28 @@ void WalletImpl::freeze(const std::string &key_image)
|
|||
}
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void WalletImpl::freezeByPubKey(const std::string &public_key)
|
||||
{
|
||||
clearStatus();
|
||||
|
||||
crypto::public_key pk;
|
||||
if (!epee::string_tools::hex_to_pod(public_key, pk))
|
||||
{
|
||||
setStatusError((boost::format(tr("Failed to parse public key `%s`")) % public_key).str());
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
m_wallet->freeze(m_wallet->get_output_index(pk));
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
LOG_ERROR(__FUNCTION__ << " error: " << e.what());
|
||||
setStatusError((boost::format(tr("Failed to freeze enote with public key `%s`: %s")) % public_key % e.what()).str());
|
||||
}
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void WalletImpl::thaw(const std::string &key_image)
|
||||
{
|
||||
clearStatus();
|
||||
|
@ -2951,6 +2975,28 @@ void WalletImpl::thaw(const std::string &key_image)
|
|||
}
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void WalletImpl::thawByPubKey(const std::string &public_key)
|
||||
{
|
||||
clearStatus();
|
||||
|
||||
crypto::public_key pk;
|
||||
if (!epee::string_tools::hex_to_pod(public_key, pk))
|
||||
{
|
||||
setStatusError((boost::format(tr("Failed to parse public key `%s`")) % public_key).str());
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
m_wallet->thaw(m_wallet->get_output_index(pk));
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
LOG_ERROR(__FUNCTION__ << " error: " << e.what());
|
||||
setStatusError((boost::format(tr("Failed to thaw enote with public key `%s`: %s")) % public_key % e.what()).str());
|
||||
}
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
bool WalletImpl::isFrozen(const std::string &key_image) const
|
||||
{
|
||||
clearStatus();
|
||||
|
@ -2970,6 +3016,29 @@ bool WalletImpl::isFrozen(const std::string &key_image) const
|
|||
return false;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
bool WalletImpl::isFrozenByPubKey(const std::string &public_key)
|
||||
{
|
||||
clearStatus();
|
||||
|
||||
crypto::public_key pk;
|
||||
if (!epee::string_tools::hex_to_pod(public_key, pk))
|
||||
{
|
||||
setStatusError((boost::format(tr("Failed to parse public key `%s`")) % public_key).str());
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return m_wallet->frozen(m_wallet->get_output_index(pk));
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
LOG_ERROR(__FUNCTION__ << " error: " << e.what());
|
||||
setStatusError((boost::format(tr("Failed to determine if enote with public key `%s` is frozen: %s")) % public_key % e.what()).str());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void WalletImpl::createOneOffSubaddress(std::uint32_t account_index, std::uint32_t address_index)
|
||||
{
|
||||
m_wallet->create_one_off_subaddress({account_index, address_index});
|
||||
|
|
|
@ -238,8 +238,11 @@ public:
|
|||
std::string getMultisigSeed(const std::string &seed_offset) const override;
|
||||
std::pair<std::uint32_t, std::uint32_t> getSubaddressIndex(const std::string &address) const override;
|
||||
void freeze(const std::string &key_image) override;
|
||||
void freezeByPubKey(const std::string &public_key) override;
|
||||
void thaw(const std::string &key_image) override;
|
||||
void thawByPubKey(const std::string &public_key) override;
|
||||
bool isFrozen(const std::string &key_image) const override;
|
||||
bool isFrozenByPubKey(const std::string &public_key) override;
|
||||
void createOneOffSubaddress(std::uint32_t account_index, std::uint32_t address_index) override;
|
||||
WalletState getWalletState() const override;
|
||||
void rewriteWalletFile(const std::string &wallet_name, const std::string &password) override;
|
||||
|
|
|
@ -1233,22 +1233,28 @@ struct Wallet
|
|||
/**
|
||||
* brief: freeze - freeze enote "so they don't appear in balance, nor are considered when creating a transaction, etc." (https://github.com/monero-project/monero/pull/5333)
|
||||
* param: key_image - key image of enote
|
||||
* param: public_key - public key of enote
|
||||
* note: sets status error on fail
|
||||
*/
|
||||
virtual void freeze(const std::string &key_image) = 0;
|
||||
virtual void freezeByPubKey(const std::string &public_key) = 0;
|
||||
/**
|
||||
* brief: thaw - thaw enote that is frozen, so it appears in balance and can be spent in a transaction
|
||||
* param: key_image - key image of enote
|
||||
* param: public_key - public key of enote
|
||||
* note: sets status error on fail
|
||||
*/
|
||||
virtual void thaw(const std::string &key_image) = 0;
|
||||
virtual void thawByPubKey(const std::string &public_key) = 0;
|
||||
/**
|
||||
* brief: isFrozen - check if enote is frozen
|
||||
* param: key_image - key image of enote
|
||||
* param: public_key - public key of enote
|
||||
* return : true if enote is frozen, else false
|
||||
* note: sets status error on fail
|
||||
*/
|
||||
virtual bool isFrozen(const std::string &key_image) const = 0;
|
||||
virtual bool isFrozenByPubKey(const std::string &public_key) = 0;
|
||||
/**
|
||||
* brief: createOneOffSubaddress - create a subaddress for given index
|
||||
* param: account_index - major index
|
||||
|
|
|
@ -2082,6 +2082,13 @@ size_t wallet2::get_transfer_details(const crypto::key_image &ki) const
|
|||
CHECK_AND_ASSERT_THROW_MES(false, "Key image not found");
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
size_t wallet2::get_output_index(const crypto::public_key &pk) const
|
||||
{
|
||||
auto search = m_pub_keys.find(pk);
|
||||
CHECK_AND_ASSERT_THROW_MES(search == m_pub_keys.end(), "Public key not found in owned outputs");
|
||||
return search->second;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
bool wallet2::frozen(const transfer_details &td) const
|
||||
{
|
||||
return td.m_frozen;
|
||||
|
|
|
@ -1536,6 +1536,8 @@ private:
|
|||
uint64_t get_num_rct_outputs();
|
||||
size_t get_num_transfer_details() const { return m_transfers.size(); }
|
||||
const transfer_details &get_transfer_details(size_t idx) const;
|
||||
// similar to get_transfer_details(ki) below, but uses outputs pubkey instead of key image and this method is public
|
||||
size_t get_output_index(const crypto::public_key &pk) const;
|
||||
|
||||
uint8_t get_current_hard_fork();
|
||||
void get_hard_fork_info(uint8_t version, uint64_t &earliest_height);
|
||||
|
|
Loading…
Reference in a new issue