aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-12-06 15:59:28 +0000
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-12-06 15:59:28 +0000
commit865c3a23832e36d50cb873d38c976032b027b5d3 (patch)
tree66450fd4f6ccfe8eda984494aa36201c453bb4ec
parentf03304a9c79a6cc6096ed501ad38702fd012e7f7 (diff)
downloadbitcoin-865c3a23832e36d50cb873d38c976032b027b5d3.tar.xz
fix wallet.dat compatibility problem if you downgrade from 0.3.17 and then upgrade again
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@196 1a98c847-1fd6-4fd8-948a-caf3550aa51b
-rw-r--r--db.cpp24
-rw-r--r--main.h25
-rw-r--r--serialize.h2
3 files changed, 36 insertions, 15 deletions
diff --git a/db.cpp b/db.cpp
index fb4e48c596..8f02fffafa 100644
--- a/db.cpp
+++ b/db.cpp
@@ -656,6 +656,7 @@ bool CWalletDB::LoadWallet()
{
vchDefaultKey.clear();
int nFileVersion = 0;
+ vector<uint256> vWalletUpgrade;
// Modify defaults
#ifndef __WXMSW__
@@ -705,6 +706,25 @@ bool CWalletDB::LoadWallet()
if (wtx.GetHash() != hash)
printf("Error in wallet.dat, hash mismatch\n");
+ // Undo serialize changes in 31600
+ if (31404 <= wtx.fTimeReceivedIsTxTime && wtx.fTimeReceivedIsTxTime <= 31703)
+ {
+ if (!ssValue.empty())
+ {
+ char fTmp;
+ char fUnused;
+ ssValue >> fTmp >> fUnused >> wtx.strFromAccount;
+ printf("LoadWallet() upgrading tx ver=%d %d '%s' %s\n", wtx.fTimeReceivedIsTxTime, fTmp, wtx.strFromAccount.c_str(), hash.ToString().c_str());
+ wtx.fTimeReceivedIsTxTime = fTmp;
+ }
+ else
+ {
+ printf("LoadWallet() repairing tx ver=%d %s\n", wtx.fTimeReceivedIsTxTime, hash.ToString().c_str());
+ wtx.fTimeReceivedIsTxTime = 0;
+ }
+ vWalletUpgrade.push_back(hash);
+ }
+
//// debug print
//printf("LoadWallet %s\n", wtx.GetHash().ToString().c_str());
//printf(" %12I64d %s %s %s\n",
@@ -774,6 +794,9 @@ bool CWalletDB::LoadWallet()
pcursor->close();
}
+ foreach(uint256 hash, vWalletUpgrade)
+ WriteTx(hash, mapWallet[hash]);
+
printf("nFileVersion = %d\n", nFileVersion);
printf("fGenerateBitcoins = %d\n", fGenerateBitcoins);
printf("nTransactionFee = %"PRI64d"\n", nTransactionFee);
@@ -794,6 +817,7 @@ bool CWalletDB::LoadWallet()
WriteVersion(VERSION);
}
+
return true;
}
diff --git a/main.h b/main.h
index cca233896e..b221e62a7e 100644
--- a/main.h
+++ b/main.h
@@ -751,11 +751,10 @@ public:
vector<CMerkleTx> vtxPrev;
map<string, string> mapValue;
vector<pair<string, string> > vOrderForm;
+ unsigned int fTimeReceivedIsTxTime;
unsigned int nTimeReceived; // time received by this node
char fFromMe;
char fSpent;
- char fTimeReceivedIsTxTime;
- char fUnused;
string strFromAccount;
// memory only
@@ -792,11 +791,10 @@ public:
vtxPrev.clear();
mapValue.clear();
vOrderForm.clear();
+ fTimeReceivedIsTxTime = false;
nTimeReceived = 0;
fFromMe = false;
fSpent = false;
- fTimeReceivedIsTxTime = false;
- fUnused = false;
strFromAccount.clear();
fDebitCached = false;
fCreditCached = false;
@@ -811,24 +809,23 @@ public:
IMPLEMENT_SERIALIZE
(
+ CWalletTx* pthis = const_cast<CWalletTx*>(this);
if (fRead)
- const_cast<CWalletTx*>(this)->Init();
+ pthis->Init();
nSerSize += SerReadWrite(s, *(CMerkleTx*)this, nType, nVersion, ser_action);
READWRITE(vtxPrev);
+
+ pthis->mapValue["fromaccount"] = pthis->strFromAccount;
READWRITE(mapValue);
+ pthis->strFromAccount = pthis->mapValue["fromaccount"];
+ pthis->mapValue.erase("fromaccount");
+ pthis->mapValue.erase("version");
+
READWRITE(vOrderForm);
- READWRITE(nVersion);
- if (fRead && nVersion < 100)
- const_cast<CWalletTx*>(this)->fTimeReceivedIsTxTime = nVersion;
+ READWRITE(fTimeReceivedIsTxTime);
READWRITE(nTimeReceived);
READWRITE(fFromMe);
READWRITE(fSpent);
- if (nVersion >= 31404)
- {
- READWRITE(fTimeReceivedIsTxTime);
- READWRITE(fUnused);
- READWRITE(strFromAccount);
- }
)
int64 GetDebit() const
diff --git a/serialize.h b/serialize.h
index 7f47d0fcbb..eccea8f72e 100644
--- a/serialize.h
+++ b/serialize.h
@@ -25,7 +25,7 @@ class CDataStream;
class CAutoFile;
static const unsigned int MAX_SIZE = 0x02000000;
-static const int VERSION = 31703;
+static const int VERSION = 31704;
static const char* pszSubVer = "";