mirror of
https://github.com/monero-project/monero.git
synced 2025-08-21 10:58:18 -04:00
Merge pull request #3780
9c2a7b4
wallet-rpc: watch-only and cold wallet features added (ph4r05)
This commit is contained in:
commit
4e7897e57c
7 changed files with 495 additions and 98 deletions
|
@ -90,8 +90,6 @@ typedef cryptonote::simple_wallet sw;
|
|||
|
||||
#define MIN_RING_SIZE 7 // Used to inform user about min ring size -- does not track actual protocol
|
||||
|
||||
#define OUTPUT_EXPORT_FILE_MAGIC "Monero output export\003"
|
||||
|
||||
#define LOCK_IDLE_SCOPE() \
|
||||
bool auto_refresh_enabled = m_auto_refresh_enabled.load(std::memory_order_relaxed); \
|
||||
m_auto_refresh_enabled.store(false, std::memory_order_relaxed); \
|
||||
|
@ -7303,19 +7301,8 @@ bool simple_wallet::export_outputs(const std::vector<std::string> &args)
|
|||
LOCK_IDLE_SCOPE();
|
||||
try
|
||||
{
|
||||
std::vector<tools::wallet2::transfer_details> outs = m_wallet->export_outputs();
|
||||
|
||||
std::stringstream oss;
|
||||
boost::archive::portable_binary_oarchive ar(oss);
|
||||
ar << outs;
|
||||
|
||||
std::string magic(OUTPUT_EXPORT_FILE_MAGIC, strlen(OUTPUT_EXPORT_FILE_MAGIC));
|
||||
const cryptonote::account_public_address &keys = m_wallet->get_account().get_keys().m_account_address;
|
||||
std::string header;
|
||||
header += std::string((const char *)&keys.m_spend_public_key, sizeof(crypto::public_key));
|
||||
header += std::string((const char *)&keys.m_view_public_key, sizeof(crypto::public_key));
|
||||
std::string ciphertext = m_wallet->encrypt_with_view_secret_key(header + oss.str());
|
||||
bool r = epee::file_io_utils::save_string_to_file(filename, magic + ciphertext);
|
||||
std::string data = m_wallet->export_outputs_to_str();
|
||||
bool r = epee::file_io_utils::save_string_to_file(filename, data);
|
||||
if (!r)
|
||||
{
|
||||
fail_msg_writer() << tr("failed to save file ") << filename;
|
||||
|
@ -7354,63 +7341,16 @@ bool simple_wallet::import_outputs(const std::vector<std::string> &args)
|
|||
fail_msg_writer() << tr("failed to read file ") << filename;
|
||||
return true;
|
||||
}
|
||||
const size_t magiclen = strlen(OUTPUT_EXPORT_FILE_MAGIC);
|
||||
if (data.size() < magiclen || memcmp(data.data(), OUTPUT_EXPORT_FILE_MAGIC, magiclen))
|
||||
{
|
||||
fail_msg_writer() << "Bad output export file magic in " << filename;
|
||||
return true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
data = m_wallet->decrypt_with_view_secret_key(std::string(data, magiclen));
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
fail_msg_writer() << "Failed to decrypt " << filename << ": " << e.what();
|
||||
return true;
|
||||
}
|
||||
|
||||
const size_t headerlen = 2 * sizeof(crypto::public_key);
|
||||
if (data.size() < headerlen)
|
||||
{
|
||||
fail_msg_writer() << "Bad data size from file " << filename;
|
||||
return true;
|
||||
}
|
||||
const crypto::public_key &public_spend_key = *(const crypto::public_key*)&data[0];
|
||||
const crypto::public_key &public_view_key = *(const crypto::public_key*)&data[sizeof(crypto::public_key)];
|
||||
const cryptonote::account_public_address &keys = m_wallet->get_account().get_keys().m_account_address;
|
||||
if (public_spend_key != keys.m_spend_public_key || public_view_key != keys.m_view_public_key)
|
||||
{
|
||||
fail_msg_writer() << "Outputs from " << filename << " are for a different account";
|
||||
return true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
std::string body(data, headerlen);
|
||||
std::stringstream iss;
|
||||
iss << body;
|
||||
std::vector<tools::wallet2::transfer_details> outputs;
|
||||
try
|
||||
{
|
||||
boost::archive::portable_binary_iarchive ar(iss);
|
||||
ar >> outputs;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
iss.str("");
|
||||
iss << body;
|
||||
boost::archive::binary_iarchive ar(iss);
|
||||
ar >> outputs;
|
||||
}
|
||||
LOCK_IDLE_SCOPE();
|
||||
size_t n_outputs = m_wallet->import_outputs(outputs);
|
||||
size_t n_outputs = m_wallet->import_outputs_from_str(data);
|
||||
success_msg_writer() << boost::lexical_cast<std::string>(n_outputs) << " outputs imported";
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
fail_msg_writer() << "Failed to import outputs: " << e.what();
|
||||
fail_msg_writer() << "Failed to import outputs " << filename << ": " << e.what();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue