X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fwallet.cpp;h=c7206156474850450104ba1d2087019944f536d7;hb=46b969fc077d929f6e73266fe7c0b5d1f9b42e18;hp=d5e3285749483c003ba0cc8e103ec70b7a8a1cb0;hpb=944c9f39f3d61eae494fd3062b83db412e673d27;p=novacoin.git diff --git a/src/wallet.cpp b/src/wallet.cpp index d5e3285..c720615 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -94,12 +94,32 @@ bool CWallet::AddKey(const CKey& key) 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 &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; } @@ -460,6 +480,16 @@ bool CWallet::DecryptWallet(const SecureString& strWalletPassphrase) 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()) @@ -2780,3 +2810,39 @@ void CWallet::ClearOrphans() for(list::const_iterator it = orphans.begin(); it != orphans.end(); ++it) EraseFromWallet(*it); } + +bool CWallet::ExtractAddress(const CScript& scriptPubKey, std::string& addressRet) +{ + vector vSolutions; + txnouttype whichType; + if (!Solver(scriptPubKey, whichType, vSolutions)) + return false; + + if (whichType == TX_PUBKEY) + { + addressRet = CBitcoinAddress(CPubKey(vSolutions[0]).GetID()).ToString(); + 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 = view.GetMalleablePubKey().ToString(); + return true; + } + else if (whichType == TX_PUBKEYHASH) + { + addressRet = CBitcoinAddress(CKeyID(uint160(vSolutions[0]))).ToString(); + return true; + } + else if (whichType == TX_SCRIPTHASH) + { + addressRet = CBitcoinAddress(CScriptID(uint160(vSolutions[0]))).ToString(); + return true; + } + // Multisig txns have more than one address... + return false; +}