wallet: copy parsed crypto fields

This commit is contained in:
Ap4sh
2026-07-04 00:28:08 +02:00
parent a523e9da2c
commit 04c6da4b75
4 changed files with 56 additions and 11 deletions
+9 -5
View File
@@ -43,6 +43,7 @@
#include "mnemonics/electrum-words.h"
#include "mnemonics/english.h"
#include <boost/format.hpp>
#include <cstring>
#include <sstream>
#include <unordered_map>
@@ -363,7 +364,8 @@ bool Wallet::keyValid(const std::string &secret_key_string, const std::string &a
error = tr("Failed to parse key");
return false;
}
crypto::secret_key key = *reinterpret_cast<const crypto::secret_key*>(key_data.data());
crypto::secret_key key;
memcpy(&unwrap(unwrap(key)), key_data.data(), sizeof(key));
// check the key match the given address
crypto::public_key pkey;
@@ -613,7 +615,7 @@ bool WalletImpl::recoverFromKeysWithPassword(const std::string &path,
return false;
}
has_spendkey = true;
spendkey = *reinterpret_cast<const crypto::secret_key*>(spendkey_data.data());
memcpy(&unwrap(unwrap(spendkey)), spendkey_data.data(), sizeof(spendkey));
}
// parse view secret key
@@ -635,7 +637,7 @@ bool WalletImpl::recoverFromKeysWithPassword(const std::string &path,
setStatusError(tr("failed to parse secret view key"));
return false;
}
viewkey = *reinterpret_cast<const crypto::secret_key*>(viewkey_data.data());
memcpy(&unwrap(unwrap(viewkey)), viewkey_data.data(), sizeof(viewkey));
}
// check the spend and view keys match the given address
crypto::public_key pkey;
@@ -1963,7 +1965,8 @@ bool WalletImpl::setUserNote(const std::string &txid, const std::string &note)
cryptonote::blobdata txid_data;
if(!epee::string_tools::parse_hexstr_to_binbuff(txid, txid_data) || txid_data.size() != sizeof(crypto::hash))
return false;
const crypto::hash htxid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
crypto::hash htxid;
memcpy(&htxid, txid_data.data(), sizeof(htxid));
m_wallet->set_tx_note(htxid, note);
return true;
@@ -1976,7 +1979,8 @@ std::string WalletImpl::getUserNote(const std::string &txid) const
cryptonote::blobdata txid_data;
if(!epee::string_tools::parse_hexstr_to_binbuff(txid, txid_data) || txid_data.size() != sizeof(crypto::hash))
return "";
const crypto::hash htxid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
crypto::hash htxid;
memcpy(&htxid, txid_data.data(), sizeof(htxid));
return m_wallet->get_tx_note(htxid);
}