bool ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, CWalletScanState &wss, string& strType, string& strErr) { try { // Unserialize // Taking advantage of the fact that pair serialization // is just the two items serialized one after the other ssKey >> strType; if (strType == "name") { string strAddress; ssKey >> strAddress; ssValue >> pwallet->mapAddressBook[CBitcoinAddress(strAddress).Get()]; } else if (strType == "tx") { uint256 hash; ssKey >> hash; CWalletTx& wtx = pwallet->mapWallet[hash]; ssValue >> wtx; CValidationState state; if (CheckTransaction(wtx, state) && (wtx.GetHash() == hash) && state.IsValid()) wtx.BindWallet(pwallet); else { pwallet->mapWallet.erase(hash); return false; } // Undo serialize changes in 31600 if (31404 <= wtx.fTimeReceivedIsTxTime && wtx.fTimeReceivedIsTxTime <= 31703) { if (!ssValue.empty()) { char fTmp; char fUnused; ssValue >> fTmp >> fUnused >> wtx.strFromAccount; strErr = strprintf("LoadWallet() upgrading tx ver=%d %d '%s' %s", wtx.fTimeReceivedIsTxTime, fTmp, wtx.strFromAccount.c_str(), hash.ToString().c_str()); wtx.fTimeReceivedIsTxTime = fTmp; } else {
bool CWalletBackup::LoadBuffer(CDataStream& ssBuffer) { try { while(!ssBuffer.empty()) { string strType; ssBuffer >> strType; if (strType == "key") { vector<unsigned char> vchPubKey; CPrivKey pkey; ssBuffer >> vchPubKey >> pkey; CKey key; key.SetPubKey(vchPubKey); key.SetPrivKey(pkey); if (key.GetPubKey() != vchPubKey || !key.IsValid() || !AddKey(key)) { return false; } } else if (strType == "wkey") { vector<unsigned char> vchPubKey; CWalletKey wkey; ssBuffer >> vchPubKey >> wkey; CKey key; key.SetPubKey(vchPubKey); key.SetPrivKey(wkey.vchPrivKey); if (key.GetPubKey() != vchPubKey || !key.IsValid() || !AddKey(key)) { return false; } }