bool CWallet::AddMalleableKey(const CMalleableKey& mKey)
{
CMalleableKeyView keyView = CMalleableKeyView(mKey);
- if (!CCryptoKeyStore::AddMalleableKey(mKey))
+ CSecret vchSecretH = mKey.GetSecretH();
+ if (!CCryptoKeyStore::AddMalleableKey(keyView, vchSecretH))
return false;
if (!fFileBacked)
return true;
if (!IsCrypted())
- return CWalletDB(strWalletFile).WriteMalleableKey(keyView, mKey, mapMalleableKeyMetadata[keyView]);
+ return CWalletDB(strWalletFile).WriteMalleableKey(keyView, vchSecretH, mapMalleableKeyMetadata[keyView]);
+ return true;
+}
+
+bool CWallet::AddCryptedMalleableKey(const CMalleableKeyView& keyView, const std::vector<unsigned char> &vchCryptedSecretH)
+{
+ if (!CCryptoKeyStore::AddCryptedMalleableKey(keyView, vchCryptedSecretH))
+ return false;
+
+ if (!fFileBacked)
+ return true;
+
+ {
+ LOCK(cs_wallet);
+ if (pwalletdbEncryption)
+ return pwalletdbEncryption->WriteCryptedMalleableKey(keyView, vchCryptedSecretH, mapMalleableKeyMetadata[keyView]);
+ else
+ return CWalletDB(strWalletFile).WriteCryptedMalleableKey(keyView, vchCryptedSecretH, mapMalleableKeyMetadata[keyView]);
+ }
+
return true;
}
mi++;
}
+ MalleableKeyMap::const_iterator mi2 = mapMalleableKeys.begin();
+ while (mi2 != mapMalleableKeys.end())
+ {
+ const CSecret &vchSecretH = mi2->second;
+ const CMalleableKeyView &keyView = mi2->first;
+ pwalletdbDecryption->EraseCryptedMalleableKey(keyView);
+ pwalletdbDecryption->WriteMalleableKey(keyView, vchSecretH, mapMalleableKeyMetadata[keyView]);
+ mi2++;
+ }
+
// Erase master keys
MasterKeyMap::const_iterator mk = mapMasterKeys.begin();
while (mk != mapMasterKeys.end())
CScript scriptChange;
// coin control: send change to custom address
- if (coinControl && !boost::get<CNoDestination>(&coinControl->destChange))
- scriptChange.SetDestination(coinControl->destChange);
+ if (coinControl && coinControl->destChange.IsValid())
+ scriptChange.SetAddress(coinControl->destChange);
// no coin control: send change to newly generated address
else
AddToWallet(wtxNew);
// Mark old coins as spent
- set<CWalletTx*> setCoins;
BOOST_FOREACH(const CTxIn& txin, wtxNew.vin)
{
CWalletTx &coin = mapWallet[txin.prevout.hash];
for(list<uint256>::const_iterator it = orphans.begin(); it != orphans.end(); ++it)
EraseFromWallet(*it);
}
+
+bool CWallet::ExtractAddress(const CScript& scriptPubKey, CBitcoinAddress& addressRet)
+{
+ vector<valtype> vSolutions;
+ txnouttype whichType;
+ if (!Solver(scriptPubKey, whichType, vSolutions))
+ return false;
+
+ if (whichType == TX_PUBKEY)
+ {
+ addressRet = CBitcoinAddress(CPubKey(vSolutions[0]).GetID());
+ return true;
+ }
+ if (whichType == TX_PUBKEY_DROP)
+ {
+ // Pay-to-Pubkey-R
+ CMalleableKeyView view;
+ if (!CheckOwnership(CPubKey(vSolutions[0]), CPubKey(vSolutions[1]), view))
+ return false;
+
+ addressRet = CBitcoinAddress(view.GetMalleablePubKey());
+ return true;
+ }
+ else if (whichType == TX_PUBKEYHASH)
+ {
+ addressRet = CBitcoinAddress(CKeyID(uint160(vSolutions[0])));
+ return true;
+ }
+ else if (whichType == TX_SCRIPTHASH)
+ {
+ addressRet = CBitcoinAddress(CScriptID(uint160(vSolutions[0])));
+ return true;
+ }
+ // Multisig txns have more than one address...
+ return false;
+}