Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 272 Lines • ▼ Show 20 Lines | |||||
bool CWallet::LoadCScript(const CScript &redeemScript) { | bool CWallet::LoadCScript(const CScript &redeemScript) { | ||||
/** | /** | ||||
* A sanity check was added in pull #3843 to avoid adding redeemScripts that | * A sanity check was added in pull #3843 to avoid adding redeemScripts that | ||||
* never can be redeemed. However, old wallets may still contain these. Do | * never can be redeemed. However, old wallets may still contain these. Do | ||||
* not add them to the wallet and warn. | * not add them to the wallet and warn. | ||||
*/ | */ | ||||
if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE) { | if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE) { | ||||
std::string strAddr = | std::string strAddr = EncodeDestination(CScriptID(redeemScript)); | ||||
CBitcoinAddress(CScriptID(redeemScript)).ToString(); | |||||
LogPrintf("%s: Warning: This wallet contains a redeemScript of size %i " | LogPrintf("%s: Warning: This wallet contains a redeemScript of size %i " | ||||
"which exceeds maximum size %i thus can never be redeemed. " | "which exceeds maximum size %i thus can never be redeemed. " | ||||
"Do not use address %s.\n", | "Do not use address %s.\n", | ||||
__func__, redeemScript.size(), MAX_SCRIPT_ELEMENT_SIZE, | __func__, redeemScript.size(), MAX_SCRIPT_ELEMENT_SIZE, | ||||
strAddr); | strAddr); | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,940 Lines • ▼ Show 20 Lines | NotifyAddressBookChanged(this, address, strName, | ||||
::IsMine(*this, address) != ISMINE_NO, strPurpose, | ::IsMine(*this, address) != ISMINE_NO, strPurpose, | ||||
(fUpdated ? CT_UPDATED : CT_NEW)); | (fUpdated ? CT_UPDATED : CT_NEW)); | ||||
if (!fFileBacked) { | if (!fFileBacked) { | ||||
return false; | return false; | ||||
} | } | ||||
if (!strPurpose.empty() && | if (!strPurpose.empty() && | ||||
!CWalletDB(strWalletFile) | !CWalletDB(strWalletFile) | ||||
.WritePurpose(CBitcoinAddress(address).ToString(), strPurpose)) { | .WritePurpose(EncodeDestination(address), strPurpose)) { | ||||
return false; | return false; | ||||
} | } | ||||
return CWalletDB(strWalletFile) | return CWalletDB(strWalletFile) | ||||
.WriteName(CBitcoinAddress(address).ToString(), strName); | .WriteName(EncodeDestination(address), strName); | ||||
} | } | ||||
bool CWallet::DelAddressBook(const CTxDestination &address) { | bool CWallet::DelAddressBook(const CTxDestination &address) { | ||||
{ | { | ||||
// mapAddressBook | // mapAddressBook | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
if (fFileBacked) { | if (fFileBacked) { | ||||
// Delete destdata tuples associated with address. | // Delete destdata tuples associated with address. | ||||
std::string strAddress = CBitcoinAddress(address).ToString(); | std::string strAddress = EncodeDestination(address); | ||||
for (const std::pair<std::string, std::string> &item : | for (const std::pair<std::string, std::string> &item : | ||||
mapAddressBook[address].destdata) { | mapAddressBook[address].destdata) { | ||||
CWalletDB(strWalletFile).EraseDestData(strAddress, item.first); | CWalletDB(strWalletFile).EraseDestData(strAddress, item.first); | ||||
} | } | ||||
} | } | ||||
mapAddressBook.erase(address); | mapAddressBook.erase(address); | ||||
} | } | ||||
NotifyAddressBookChanged(this, address, "", | NotifyAddressBookChanged(this, address, "", | ||||
::IsMine(*this, address) != ISMINE_NO, "", | ::IsMine(*this, address) != ISMINE_NO, "", | ||||
CT_DELETED); | CT_DELETED); | ||||
if (!fFileBacked) { | if (!fFileBacked) { | ||||
return false; | return false; | ||||
} | } | ||||
CWalletDB(strWalletFile).ErasePurpose(CBitcoinAddress(address).ToString()); | CWalletDB(strWalletFile).ErasePurpose(EncodeDestination(address)); | ||||
return CWalletDB(strWalletFile) | return CWalletDB(strWalletFile).EraseName(EncodeDestination(address)); | ||||
.EraseName(CBitcoinAddress(address).ToString()); | |||||
} | } | ||||
bool CWallet::SetDefaultKey(const CPubKey &vchPubKey) { | bool CWallet::SetDefaultKey(const CPubKey &vchPubKey) { | ||||
if (fFileBacked && !CWalletDB(strWalletFile).WriteDefaultKey(vchPubKey)) { | if (fFileBacked && !CWalletDB(strWalletFile).WriteDefaultKey(vchPubKey)) { | ||||
return false; | return false; | ||||
} | } | ||||
vchDefaultKey = vchPubKey; | vchDefaultKey = vchPubKey; | ||||
▲ Show 20 Lines • Show All 583 Lines • ▼ Show 20 Lines | bool CWallet::AddDestData(const CTxDestination &dest, const std::string &key, | ||||
} | } | ||||
mapAddressBook[dest].destdata.insert(std::make_pair(key, value)); | mapAddressBook[dest].destdata.insert(std::make_pair(key, value)); | ||||
if (!fFileBacked) { | if (!fFileBacked) { | ||||
return true; | return true; | ||||
} | } | ||||
return CWalletDB(strWalletFile) | return CWalletDB(strWalletFile) | ||||
.WriteDestData(CBitcoinAddress(dest).ToString(), key, value); | .WriteDestData(EncodeDestination(dest), key, value); | ||||
} | } | ||||
bool CWallet::EraseDestData(const CTxDestination &dest, | bool CWallet::EraseDestData(const CTxDestination &dest, | ||||
const std::string &key) { | const std::string &key) { | ||||
if (!mapAddressBook[dest].destdata.erase(key)) { | if (!mapAddressBook[dest].destdata.erase(key)) { | ||||
return false; | return false; | ||||
} | } | ||||
if (!fFileBacked) { | if (!fFileBacked) { | ||||
return true; | return true; | ||||
} | } | ||||
return CWalletDB(strWalletFile) | return CWalletDB(strWalletFile).EraseDestData(EncodeDestination(dest), key); | ||||
.EraseDestData(CBitcoinAddress(dest).ToString(), key); | |||||
} | } | ||||
bool CWallet::LoadDestData(const CTxDestination &dest, const std::string &key, | bool CWallet::LoadDestData(const CTxDestination &dest, const std::string &key, | ||||
const std::string &value) { | const std::string &value) { | ||||
mapAddressBook[dest].destdata.insert(std::make_pair(key, value)); | mapAddressBook[dest].destdata.insert(std::make_pair(key, value)); | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 588 Lines • Show Last 20 Lines |