Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 633 Lines • ▼ Show 20 Lines | bool CWallet::EncryptWallet(const SecureString &strWalletPassphrase) { | ||||
if (!crypter.Encrypt(_vMasterKey, kMasterKey.vchCryptedKey)) { | if (!crypter.Encrypt(_vMasterKey, kMasterKey.vchCryptedKey)) { | ||||
return false; | return false; | ||||
} | } | ||||
{ | { | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
mapMasterKeys[++nMasterKeyMaxID] = kMasterKey; | mapMasterKeys[++nMasterKeyMaxID] = kMasterKey; | ||||
assert(!encrypted_batch); | WalletBatch *encrypted_batch = new WalletBatch(*database); | ||||
encrypted_batch = new WalletBatch(*database); | |||||
if (!encrypted_batch->TxnBegin()) { | if (!encrypted_batch->TxnBegin()) { | ||||
delete encrypted_batch; | delete encrypted_batch; | ||||
encrypted_batch = nullptr; | encrypted_batch = nullptr; | ||||
return false; | return false; | ||||
} | } | ||||
encrypted_batch->WriteMasterKey(nMasterKeyMaxID, kMasterKey); | encrypted_batch->WriteMasterKey(nMasterKeyMaxID, kMasterKey); | ||||
if (auto spk_man = m_spk_man.get()) { | if (auto spk_man = m_spk_man.get()) { | ||||
if (!spk_man->EncryptKeys(_vMasterKey)) { | if (!spk_man->Encrypt(_vMasterKey, encrypted_batch)) { | ||||
encrypted_batch->TxnAbort(); | encrypted_batch->TxnAbort(); | ||||
delete encrypted_batch; | delete encrypted_batch; | ||||
encrypted_batch = nullptr; | encrypted_batch = nullptr; | ||||
// We now probably have half of our keys encrypted in memory, | // We now probably have half of our keys encrypted in memory, | ||||
// and half not... die and let the user reload the unencrypted | // and half not... die and let the user reload the unencrypted | ||||
// wallet. | // wallet. | ||||
assert(false); | assert(false); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 3,802 Lines • ▼ Show 20 Lines | CWallet::GroupOutputs(const std::vector<COutput> &outputs, | ||||
if (!single_coin) { | if (!single_coin) { | ||||
for (const auto &it : gmap) { | for (const auto &it : gmap) { | ||||
groups.push_back(it.second); | groups.push_back(it.second); | ||||
} | } | ||||
} | } | ||||
return groups; | return groups; | ||||
} | } | ||||
bool CWallet::SetCrypted() { | bool CWallet::IsCrypted() const { | ||||
LOCK(cs_KeyStore); | return HasEncryptionKeys(); | ||||
if (fUseCrypto) { | |||||
return true; | |||||
} | |||||
if (!mapKeys.empty()) { | |||||
return false; | |||||
} | |||||
fUseCrypto = true; | |||||
return true; | |||||
} | } | ||||
bool CWallet::IsLocked() const { | bool CWallet::IsLocked() const { | ||||
if (!IsCrypted()) { | if (!IsCrypted()) { | ||||
return false; | return false; | ||||
} | } | ||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
return vMasterKey.empty(); | return vMasterKey.empty(); | ||||
} | } | ||||
bool CWallet::Lock() { | bool CWallet::Lock() { | ||||
if (!SetCrypted()) { | if (!IsCrypted()) { | ||||
return false; | return false; | ||||
} | } | ||||
{ | { | ||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
vMasterKey.clear(); | vMasterKey.clear(); | ||||
} | } | ||||
NotifyStatusChanged(this); | NotifyStatusChanged(this); | ||||
return true; | return true; | ||||
} | } | ||||
bool CWallet::Unlock(const CKeyingMaterial &vMasterKeyIn, bool accept_no_keys) { | |||||
{ | |||||
LOCK(cs_KeyStore); | |||||
if (m_spk_man) { | |||||
if (!m_spk_man->CheckDecryptionKey(vMasterKeyIn, accept_no_keys)) { | |||||
return false; | |||||
} | |||||
} | |||||
vMasterKey = vMasterKeyIn; | |||||
} | |||||
NotifyStatusChanged(this); | |||||
return true; | |||||
} | |||||
ScriptPubKeyMan *CWallet::GetScriptPubKeyMan(const CScript &script) const { | ScriptPubKeyMan *CWallet::GetScriptPubKeyMan(const CScript &script) const { | ||||
return m_spk_man.get(); | return m_spk_man.get(); | ||||
} | } | ||||
const SigningProvider * | const SigningProvider * | ||||
CWallet::GetSigningProvider(const CScript &script) const { | CWallet::GetSigningProvider(const CScript &script) const { | ||||
return m_spk_man.get(); | return m_spk_man.get(); | ||||
} | } | ||||
const SigningProvider * | const SigningProvider * | ||||
CWallet::GetSigningProvider(const CScript &script, | CWallet::GetSigningProvider(const CScript &script, | ||||
SignatureData &sigdata) const { | SignatureData &sigdata) const { | ||||
return m_spk_man.get(); | return m_spk_man.get(); | ||||
} | } | ||||
LegacyScriptPubKeyMan *CWallet::GetLegacyScriptPubKeyMan() const { | LegacyScriptPubKeyMan *CWallet::GetLegacyScriptPubKeyMan() const { | ||||
return m_spk_man.get(); | return m_spk_man.get(); | ||||
} | } | ||||
const CKeyingMaterial &CWallet::GetEncryptionKey() const { | |||||
return vMasterKey; | |||||
} | |||||
bool CWallet::HasEncryptionKeys() const { | |||||
return !mapMasterKeys.empty(); | |||||
} |