Fix addrProxy setting
authorPieter Wuille <pieter.wuille@gmail.com>
Sat, 25 Feb 2012 19:59:18 +0000 (20:59 +0100)
committerPieter Wuille <pieter.wuille@gmail.com>
Sat, 25 Feb 2012 20:13:34 +0000 (21:13 +0100)
Before 0.6 addrProxy was a CAddress, but netbase changed it to CService.
Retain compatibility by wrapping/unwrapping with a CAddress when saving
or loading.

This commit retains compatibility with 0.6.0rc1 (which wrote the setting
as a CService) by trying to parse twice.

src/db.cpp
src/qt/optionsmodel.cpp

index ea6d46a..4d4a3c4 100644 (file)
@@ -931,7 +931,21 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
                 if (strKey == "fMinimizeToTray")    ssValue >> fMinimizeToTray;
                 if (strKey == "fMinimizeOnClose")   ssValue >> fMinimizeOnClose;
                 if (strKey == "fUseProxy")          ssValue >> fUseProxy;
-                if (strKey == "addrProxy")          ssValue >> addrProxy;
+                if (strKey == "addrProxy")
+                {
+                    CAddress addr; 
+                    CDataStream ssValue2 = ssValue;
+                    // 0.6.0rc1 saved this as a CService, which causes failure when parsing as a CAddress
+                    try
+                    {
+                        ssValue >> addr;
+                        addrProxy = addr;
+                    }
+                    catch (std::ios_base::failure &e)
+                    {
+                        ssValue2 >> addrProxy;
+                    }
+                }
                 if (fHaveUPnP && strKey == "fUseUPnP")           ssValue >> fUseUPnP;
             }
             else if (strType == "minversion")
index edc1d61..dd69093 100644 (file)
@@ -91,7 +91,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
                 if (addr.IsValid())
                 {
                     addrProxy.SetIP(addr);
-                    walletdb.WriteSetting("addrProxy", addrProxy);
+                    walletdb.WriteSetting("addrProxy", CAddress(addrProxy));
                 }
                 else
                 {
@@ -105,7 +105,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
                 if (nPort > 0 && nPort < std::numeric_limits<unsigned short>::max())
                 {
                     addrProxy.SetPort(nPort);
-                    walletdb.WriteSetting("addrProxy", addrProxy);
+                    walletdb.WriteSetting("addrProxy", CAddress(addrProxy));
                 }
                 else
                 {