Mercurial > hg > bitcoin
annotate src/db.cpp @ 2205:8a17a73180e3 draft
Remove path.make_preferred() calls, and fix compiler error in bitcoinrpc RE: boost::system
author | Gavin Andresen <gavinandresen@gmail.com> |
---|---|
date | Wed, 11 Apr 2012 14:00:48 -0400 |
parents | 35ce79f542b0 |
children | 34d7dc611b26 |
rev | line source |
---|---|
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1 // Copyright (c) 2009-2010 Satoshi Nakamoto |
1818
20667468f95b
Update all copyrights to 2012
Gavin Andresen <gavinandresen@gmail.com>
parents:
1813
diff
changeset
|
2 // Copyright (c) 2009-2012 The Bitcoin developers |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
3 // Distributed under the MIT/X11 software license, see the accompanying |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
4 // file license.txt or http://www.opensource.org/licenses/mit-license.php. |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
5 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
6 #include "headers.h" |
605
1ae81ad9b0e5
Only include db.h when we have to.
Jordan Lewis <jordanthelewis@gmail.com>
parents:
595
diff
changeset
|
7 #include "db.h" |
607
92e329774c81
Only include net.h when we have to
Jordan Lewis <jordanthelewis@gmail.com>
parents:
605
diff
changeset
|
8 #include "net.h" |
1840
0760e07f7938
Added 'Backup Wallet' menu option
sje397 <sje397@gmail.com>
parents:
1818
diff
changeset
|
9 #include <boost/version.hpp> |
695
9609c7af94ba
Fix missing includes needed for Boost 1.46.
Shane Wegner <shane-github@csy.ca>
parents:
690
diff
changeset
|
10 #include <boost/filesystem.hpp> |
611
503d51554676
Only include certain boost headers if necessary.
Jordan Lewis <jordanthelewis@gmail.com>
parents:
607
diff
changeset
|
11 #include <boost/filesystem/fstream.hpp> |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
12 |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
576
diff
changeset
|
13 using namespace std; |
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
576
diff
changeset
|
14 using namespace boost; |
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
576
diff
changeset
|
15 |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
16 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
17 unsigned int nWalletDBUpdated; |
1616
997b708d15b8
Revert "Use standard C99 (and Qt) types for 64-bit integers"
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
1615
diff
changeset
|
18 uint64 nAccountingEntryNumber = 0; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
19 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
20 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
21 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
22 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
23 // CDB |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
24 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
25 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
26 static CCriticalSection cs_db; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
27 static bool fDbEnvInit = false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
28 DbEnv dbenv(0); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
29 static map<string, int> mapFileUseCount; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
30 static map<string, Db*> mapDb; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
31 |
1509
e1415e140a58
Only remove database log files on shutdown after wallet encryption/rewrite
Gavin Andresen <gavinandresen@gmail.com>
parents:
1506
diff
changeset
|
32 static void EnvShutdown() |
1501
26d0f350347a
Obsolete keypool and make sure database removes log files on shutdown.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1500
diff
changeset
|
33 { |
26d0f350347a
Obsolete keypool and make sure database removes log files on shutdown.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1500
diff
changeset
|
34 if (!fDbEnvInit) |
26d0f350347a
Obsolete keypool and make sure database removes log files on shutdown.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1500
diff
changeset
|
35 return; |
26d0f350347a
Obsolete keypool and make sure database removes log files on shutdown.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1500
diff
changeset
|
36 |
26d0f350347a
Obsolete keypool and make sure database removes log files on shutdown.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1500
diff
changeset
|
37 fDbEnvInit = false; |
1505
d54fc7452031
Fix crash-on-osx-on-shutdown bug. And cleanup CDB handling in Rewrite.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1504
diff
changeset
|
38 try |
d54fc7452031
Fix crash-on-osx-on-shutdown bug. And cleanup CDB handling in Rewrite.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1504
diff
changeset
|
39 { |
d54fc7452031
Fix crash-on-osx-on-shutdown bug. And cleanup CDB handling in Rewrite.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1504
diff
changeset
|
40 dbenv.close(0); |
d54fc7452031
Fix crash-on-osx-on-shutdown bug. And cleanup CDB handling in Rewrite.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1504
diff
changeset
|
41 } |
d54fc7452031
Fix crash-on-osx-on-shutdown bug. And cleanup CDB handling in Rewrite.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1504
diff
changeset
|
42 catch (const DbException& e) |
d54fc7452031
Fix crash-on-osx-on-shutdown bug. And cleanup CDB handling in Rewrite.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1504
diff
changeset
|
43 { |
d54fc7452031
Fix crash-on-osx-on-shutdown bug. And cleanup CDB handling in Rewrite.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1504
diff
changeset
|
44 printf("EnvShutdown exception: %s (%d)\n", e.what(), e.get_errno()); |
d54fc7452031
Fix crash-on-osx-on-shutdown bug. And cleanup CDB handling in Rewrite.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1504
diff
changeset
|
45 } |
1501
26d0f350347a
Obsolete keypool and make sure database removes log files on shutdown.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1500
diff
changeset
|
46 DbEnv(0).remove(GetDataDir().c_str(), 0); |
26d0f350347a
Obsolete keypool and make sure database removes log files on shutdown.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1500
diff
changeset
|
47 } |
26d0f350347a
Obsolete keypool and make sure database removes log files on shutdown.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1500
diff
changeset
|
48 |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
49 class CDBInit |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
50 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
51 public: |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
52 CDBInit() |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
53 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
54 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
55 ~CDBInit() |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
56 { |
1509
e1415e140a58
Only remove database log files on shutdown after wallet encryption/rewrite
Gavin Andresen <gavinandresen@gmail.com>
parents:
1506
diff
changeset
|
57 EnvShutdown(); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
58 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
59 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
60 instance_of_cdbinit; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
61 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
62 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
63 CDB::CDB(const char* pszFile, const char* pszMode) : pdb(NULL) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
64 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
65 int ret; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
66 if (pszFile == NULL) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
67 return; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
68 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
69 fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w')); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
70 bool fCreate = strchr(pszMode, 'c'); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
71 unsigned int nFlags = DB_THREAD; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
72 if (fCreate) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
73 nFlags |= DB_CREATE; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
74 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
75 { |
2190
60fe81a4849b
Use scoped locks instead of CRITICAL_BLOCK
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2176
diff
changeset
|
76 LOCK(cs_db); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
77 if (!fDbEnvInit) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
78 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
79 if (fShutdown) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
80 return; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
81 string strDataDir = GetDataDir(); |
2183
e50d5fc913ea
updated db.cpp to use make_preferred()
Philip Kaufmann <phil.kaufmann@t-online.de>
parents:
2176
diff
changeset
|
82 filesystem::path pathLogDir(strDataDir + "/database"); |
e50d5fc913ea
updated db.cpp to use make_preferred()
Philip Kaufmann <phil.kaufmann@t-online.de>
parents:
2176
diff
changeset
|
83 filesystem::create_directory(pathLogDir); |
e50d5fc913ea
updated db.cpp to use make_preferred()
Philip Kaufmann <phil.kaufmann@t-online.de>
parents:
2176
diff
changeset
|
84 filesystem::path pathErrorFile(strDataDir + "/db.log"); |
e50d5fc913ea
updated db.cpp to use make_preferred()
Philip Kaufmann <phil.kaufmann@t-online.de>
parents:
2176
diff
changeset
|
85 printf("dbenv.open LogDir=%s ErrorFile=%s\n", pathLogDir.string().c_str(), pathErrorFile.string().c_str()); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
86 |
2062
d6479f2e1371
Speed up block downloading
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
87 int nDbCache = GetArg("-dbcache", 25); |
2183
e50d5fc913ea
updated db.cpp to use make_preferred()
Philip Kaufmann <phil.kaufmann@t-online.de>
parents:
2176
diff
changeset
|
88 dbenv.set_lg_dir(pathLogDir.string().c_str()); |
2062
d6479f2e1371
Speed up block downloading
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
89 dbenv.set_cachesize(nDbCache / 1024, (nDbCache % 1024)*1048576, 1); |
2114
8c6353ab7e73
Auto-remove logs, and decrease logfile size to 10M
Gavin Andresen <gavinandresen@gmail.com>
parents:
2097
diff
changeset
|
90 dbenv.set_lg_bsize(1048576); |
8c6353ab7e73
Auto-remove logs, and decrease logfile size to 10M
Gavin Andresen <gavinandresen@gmail.com>
parents:
2097
diff
changeset
|
91 dbenv.set_lg_max(10485760); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
92 dbenv.set_lk_max_locks(10000); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
93 dbenv.set_lk_max_objects(10000); |
2183
e50d5fc913ea
updated db.cpp to use make_preferred()
Philip Kaufmann <phil.kaufmann@t-online.de>
parents:
2176
diff
changeset
|
94 dbenv.set_errfile(fopen(pathErrorFile.string().c_str(), "a")); /// debug |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
95 dbenv.set_flags(DB_AUTO_COMMIT, 1); |
2114
8c6353ab7e73
Auto-remove logs, and decrease logfile size to 10M
Gavin Andresen <gavinandresen@gmail.com>
parents:
2097
diff
changeset
|
96 dbenv.log_set_config(DB_LOG_AUTO_REMOVE, 1); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
97 ret = dbenv.open(strDataDir.c_str(), |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
98 DB_CREATE | |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
99 DB_INIT_LOCK | |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
100 DB_INIT_LOG | |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
101 DB_INIT_MPOOL | |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
102 DB_INIT_TXN | |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
103 DB_THREAD | |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
104 DB_RECOVER, |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
105 S_IRUSR | S_IWUSR); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
106 if (ret > 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
107 throw runtime_error(strprintf("CDB() : error %d opening database environment", ret)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
108 fDbEnvInit = true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
109 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
110 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
111 strFile = pszFile; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
112 ++mapFileUseCount[strFile]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
113 pdb = mapDb[strFile]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
114 if (pdb == NULL) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
115 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
116 pdb = new Db(&dbenv, 0); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
117 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
118 ret = pdb->open(NULL, // Txn pointer |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
119 pszFile, // Filename |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
120 "main", // Logical db name |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
121 DB_BTREE, // Database type |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
122 nFlags, // Flags |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
123 0); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
124 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
125 if (ret > 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
126 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
127 delete pdb; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
128 pdb = NULL; |
2190
60fe81a4849b
Use scoped locks instead of CRITICAL_BLOCK
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2176
diff
changeset
|
129 { |
60fe81a4849b
Use scoped locks instead of CRITICAL_BLOCK
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2176
diff
changeset
|
130 LOCK(cs_db); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
131 --mapFileUseCount[strFile]; |
2190
60fe81a4849b
Use scoped locks instead of CRITICAL_BLOCK
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2176
diff
changeset
|
132 } |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
133 strFile = ""; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
134 throw runtime_error(strprintf("CDB() : can't open database file %s, error %d", pszFile, ret)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
135 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
136 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
137 if (fCreate && !Exists(string("version"))) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
138 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
139 bool fTmp = fReadOnly; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
140 fReadOnly = false; |
1584
a67f13278e2c
Implement BIP 14 : separate protocol version from client version
Gavin Andresen <gavinandresen@gmail.com>
parents:
1511
diff
changeset
|
141 WriteVersion(CLIENT_VERSION); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
142 fReadOnly = fTmp; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
143 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
144 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
145 mapDb[strFile] = pdb; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
146 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
147 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
148 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
149 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
150 void CDB::Close() |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
151 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
152 if (!pdb) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
153 return; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
154 if (!vTxn.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
155 vTxn.front()->abort(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
156 vTxn.clear(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
157 pdb = NULL; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
158 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
159 // Flush database activity from memory pool to disk log |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
160 unsigned int nMinutes = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
161 if (fReadOnly) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
162 nMinutes = 1; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
163 if (strFile == "addr.dat") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
164 nMinutes = 2; |
2116
94844608a7d7
Use transactions-updated as flush condition
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2114
diff
changeset
|
165 if (strFile == "blkindex.dat" && IsInitialBlockDownload()) |
94844608a7d7
Use transactions-updated as flush condition
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2114
diff
changeset
|
166 nMinutes = 5; |
94844608a7d7
Use transactions-updated as flush condition
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2114
diff
changeset
|
167 |
2176
ad3ef2ebaef0
Flush on log size instead of transaction count
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2120
diff
changeset
|
168 dbenv.txn_checkpoint(nMinutes ? GetArg("-dblogsize", 100)*1024 : 0, nMinutes, 0); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
169 |
2190
60fe81a4849b
Use scoped locks instead of CRITICAL_BLOCK
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2176
diff
changeset
|
170 { |
60fe81a4849b
Use scoped locks instead of CRITICAL_BLOCK
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2176
diff
changeset
|
171 LOCK(cs_db); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
172 --mapFileUseCount[strFile]; |
2190
60fe81a4849b
Use scoped locks instead of CRITICAL_BLOCK
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2176
diff
changeset
|
173 } |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
174 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
175 |
690 | 176 void static CloseDb(const string& strFile) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
177 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
178 { |
2190
60fe81a4849b
Use scoped locks instead of CRITICAL_BLOCK
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2176
diff
changeset
|
179 LOCK(cs_db); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
180 if (mapDb[strFile] != NULL) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
181 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
182 // Close the database handle |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
183 Db* pdb = mapDb[strFile]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
184 pdb->close(0); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
185 delete pdb; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
186 mapDb[strFile] = NULL; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
187 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
188 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
189 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
190 |
1501
26d0f350347a
Obsolete keypool and make sure database removes log files on shutdown.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1500
diff
changeset
|
191 bool CDB::Rewrite(const string& strFile, const char* pszSkip) |
1500 | 192 { |
193 while (!fShutdown) | |
194 { | |
195 { | |
2190
60fe81a4849b
Use scoped locks instead of CRITICAL_BLOCK
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2176
diff
changeset
|
196 LOCK(cs_db); |
1500 | 197 if (!mapFileUseCount.count(strFile) || mapFileUseCount[strFile] == 0) |
198 { | |
199 // Flush log data to the dat file | |
200 CloseDb(strFile); | |
201 dbenv.txn_checkpoint(0, 0, 0); | |
202 dbenv.lsn_reset(strFile.c_str(), 0); | |
203 mapFileUseCount.erase(strFile); | |
204 | |
205 bool fSuccess = true; | |
1501
26d0f350347a
Obsolete keypool and make sure database removes log files on shutdown.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1500
diff
changeset
|
206 printf("Rewriting %s...\n", strFile.c_str()); |
26d0f350347a
Obsolete keypool and make sure database removes log files on shutdown.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1500
diff
changeset
|
207 string strFileRes = strFile + ".rewrite"; |
1511
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
208 { // surround usage of db with extra {} |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
209 CDB db(strFile.c_str(), "r"); |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
210 Db* pdbCopy = new Db(&dbenv, 0); |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
211 |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
212 int ret = pdbCopy->open(NULL, // Txn pointer |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
213 strFileRes.c_str(), // Filename |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
214 "main", // Logical db name |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
215 DB_BTREE, // Database type |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
216 DB_CREATE, // Flags |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
217 0); |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
218 if (ret > 0) |
1500 | 219 { |
1511
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
220 printf("Cannot create database file %s\n", strFileRes.c_str()); |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
221 fSuccess = false; |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
222 } |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
223 |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
224 Dbc* pcursor = db.GetCursor(); |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
225 if (pcursor) |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
226 while (fSuccess) |
1505
d54fc7452031
Fix crash-on-osx-on-shutdown bug. And cleanup CDB handling in Rewrite.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1504
diff
changeset
|
227 { |
1511
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
228 CDataStream ssKey; |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
229 CDataStream ssValue; |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
230 int ret = db.ReadAtCursor(pcursor, ssKey, ssValue, DB_NEXT); |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
231 if (ret == DB_NOTFOUND) |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
232 { |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
233 pcursor->close(); |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
234 break; |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
235 } |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
236 else if (ret != 0) |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
237 { |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
238 pcursor->close(); |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
239 fSuccess = false; |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
240 break; |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
241 } |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
242 if (pszSkip && |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
243 strncmp(&ssKey[0], pszSkip, std::min(ssKey.size(), strlen(pszSkip))) == 0) |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
244 continue; |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
245 if (strncmp(&ssKey[0], "\x07version", 8) == 0) |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
246 { |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
247 // Update version: |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
248 ssValue.clear(); |
1584
a67f13278e2c
Implement BIP 14 : separate protocol version from client version
Gavin Andresen <gavinandresen@gmail.com>
parents:
1511
diff
changeset
|
249 ssValue << CLIENT_VERSION; |
1511
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
250 } |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
251 Dbt datKey(&ssKey[0], ssKey.size()); |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
252 Dbt datValue(&ssValue[0], ssValue.size()); |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
253 int ret2 = pdbCopy->put(NULL, &datKey, &datValue, DB_NOOVERWRITE); |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
254 if (ret2 > 0) |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
255 fSuccess = false; |
1505
d54fc7452031
Fix crash-on-osx-on-shutdown bug. And cleanup CDB handling in Rewrite.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1504
diff
changeset
|
256 } |
1511
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
257 if (fSuccess) |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
258 { |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
259 db.Close(); |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
260 CloseDb(strFile); |
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
261 if (pdbCopy->close(0)) |
1500 | 262 fSuccess = false; |
1511
bdff5864eff3
close old db when rewriting
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1510
diff
changeset
|
263 delete pdbCopy; |
1500 | 264 } |
265 } | |
266 if (fSuccess) | |
267 { | |
268 Db dbA(&dbenv, 0); | |
269 if (dbA.remove(strFile.c_str(), NULL, 0)) | |
270 fSuccess = false; | |
271 Db dbB(&dbenv, 0); | |
272 if (dbB.rename(strFileRes.c_str(), NULL, strFile.c_str(), 0)) | |
273 fSuccess = false; | |
274 } | |
275 if (!fSuccess) | |
1501
26d0f350347a
Obsolete keypool and make sure database removes log files on shutdown.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1500
diff
changeset
|
276 printf("Rewriting of %s FAILED!\n", strFileRes.c_str()); |
1500 | 277 return fSuccess; |
278 } | |
279 } | |
280 Sleep(100); | |
281 } | |
282 return false; | |
283 } | |
284 | |
285 | |
1509
e1415e140a58
Only remove database log files on shutdown after wallet encryption/rewrite
Gavin Andresen <gavinandresen@gmail.com>
parents:
1506
diff
changeset
|
286 void DBFlush(bool fShutdown) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
287 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
288 // Flush log data to the actual data file |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
289 // on all files that are not in use |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
290 printf("DBFlush(%s)%s\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
291 if (!fDbEnvInit) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
292 return; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
293 { |
2190
60fe81a4849b
Use scoped locks instead of CRITICAL_BLOCK
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2176
diff
changeset
|
294 LOCK(cs_db); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
295 map<string, int>::iterator mi = mapFileUseCount.begin(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
296 while (mi != mapFileUseCount.end()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
297 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
298 string strFile = (*mi).first; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
299 int nRefCount = (*mi).second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
300 printf("%s refcount=%d\n", strFile.c_str(), nRefCount); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
301 if (nRefCount == 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
302 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
303 // Move log data to the dat file |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
304 CloseDb(strFile); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
305 dbenv.txn_checkpoint(0, 0, 0); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
306 printf("%s flush\n", strFile.c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
307 dbenv.lsn_reset(strFile.c_str(), 0); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
308 mapFileUseCount.erase(mi++); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
309 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
310 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
311 mi++; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
312 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
313 if (fShutdown) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
314 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
315 char** listp; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
316 if (mapFileUseCount.empty()) |
1501
26d0f350347a
Obsolete keypool and make sure database removes log files on shutdown.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1500
diff
changeset
|
317 { |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
318 dbenv.log_archive(&listp, DB_ARCH_REMOVE); |
1509
e1415e140a58
Only remove database log files on shutdown after wallet encryption/rewrite
Gavin Andresen <gavinandresen@gmail.com>
parents:
1506
diff
changeset
|
319 EnvShutdown(); |
1501
26d0f350347a
Obsolete keypool and make sure database removes log files on shutdown.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1500
diff
changeset
|
320 } |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
321 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
322 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
323 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
324 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
325 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
326 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
327 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
328 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
329 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
330 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
331 // CTxDB |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
332 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
333 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
334 bool CTxDB::ReadTxIndex(uint256 hash, CTxIndex& txindex) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
335 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
336 assert(!fClient); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
337 txindex.SetNull(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
338 return Read(make_pair(string("tx"), hash), txindex); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
339 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
340 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
341 bool CTxDB::UpdateTxIndex(uint256 hash, const CTxIndex& txindex) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
342 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
343 assert(!fClient); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
344 return Write(make_pair(string("tx"), hash), txindex); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
345 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
346 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
347 bool CTxDB::AddTxIndex(const CTransaction& tx, const CDiskTxPos& pos, int nHeight) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
348 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
349 assert(!fClient); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
350 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
351 // Add to tx index |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
352 uint256 hash = tx.GetHash(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
353 CTxIndex txindex(pos, tx.vout.size()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
354 return Write(make_pair(string("tx"), hash), txindex); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
355 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
356 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
357 bool CTxDB::EraseTxIndex(const CTransaction& tx) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
358 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
359 assert(!fClient); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
360 uint256 hash = tx.GetHash(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
361 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
362 return Erase(make_pair(string("tx"), hash)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
363 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
364 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
365 bool CTxDB::ContainsTx(uint256 hash) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
366 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
367 assert(!fClient); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
368 return Exists(make_pair(string("tx"), hash)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
369 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
370 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
371 bool CTxDB::ReadOwnerTxes(uint160 hash160, int nMinHeight, vector<CTransaction>& vtx) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
372 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
373 assert(!fClient); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
374 vtx.clear(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
375 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
376 // Get cursor |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
377 Dbc* pcursor = GetCursor(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
378 if (!pcursor) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
379 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
380 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
381 unsigned int fFlags = DB_SET_RANGE; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
382 loop |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
383 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
384 // Read next record |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
385 CDataStream ssKey; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
386 if (fFlags == DB_SET_RANGE) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
387 ssKey << string("owner") << hash160 << CDiskTxPos(0, 0, 0); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
388 CDataStream ssValue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
389 int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
390 fFlags = DB_NEXT; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
391 if (ret == DB_NOTFOUND) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
392 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
393 else if (ret != 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
394 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
395 pcursor->close(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
396 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
397 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
398 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
399 // Unserialize |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
400 string strType; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
401 uint160 hashItem; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
402 CDiskTxPos pos; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
403 ssKey >> strType >> hashItem >> pos; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
404 int nItemHeight; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
405 ssValue >> nItemHeight; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
406 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
407 // Read transaction |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
408 if (strType != "owner" || hashItem != hash160) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
409 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
410 if (nItemHeight >= nMinHeight) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
411 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
412 vtx.resize(vtx.size()+1); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
413 if (!vtx.back().ReadFromDisk(pos)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
414 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
415 pcursor->close(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
416 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
417 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
418 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
419 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
420 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
421 pcursor->close(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
422 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
423 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
424 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
425 bool CTxDB::ReadDiskTx(uint256 hash, CTransaction& tx, CTxIndex& txindex) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
426 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
427 assert(!fClient); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
428 tx.SetNull(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
429 if (!ReadTxIndex(hash, txindex)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
430 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
431 return (tx.ReadFromDisk(txindex.pos)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
432 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
433 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
434 bool CTxDB::ReadDiskTx(uint256 hash, CTransaction& tx) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
435 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
436 CTxIndex txindex; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
437 return ReadDiskTx(hash, tx, txindex); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
438 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
439 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
440 bool CTxDB::ReadDiskTx(COutPoint outpoint, CTransaction& tx, CTxIndex& txindex) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
441 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
442 return ReadDiskTx(outpoint.hash, tx, txindex); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
443 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
444 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
445 bool CTxDB::ReadDiskTx(COutPoint outpoint, CTransaction& tx) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
446 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
447 CTxIndex txindex; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
448 return ReadDiskTx(outpoint.hash, tx, txindex); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
449 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
450 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
451 bool CTxDB::WriteBlockIndex(const CDiskBlockIndex& blockindex) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
452 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
453 return Write(make_pair(string("blockindex"), blockindex.GetBlockHash()), blockindex); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
454 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
455 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
456 bool CTxDB::EraseBlockIndex(uint256 hash) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
457 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
458 return Erase(make_pair(string("blockindex"), hash)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
459 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
460 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
461 bool CTxDB::ReadHashBestChain(uint256& hashBestChain) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
462 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
463 return Read(string("hashBestChain"), hashBestChain); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
464 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
465 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
466 bool CTxDB::WriteHashBestChain(uint256 hashBestChain) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
467 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
468 return Write(string("hashBestChain"), hashBestChain); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
469 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
470 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
471 bool CTxDB::ReadBestInvalidWork(CBigNum& bnBestInvalidWork) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
472 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
473 return Read(string("bnBestInvalidWork"), bnBestInvalidWork); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
474 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
475 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
476 bool CTxDB::WriteBestInvalidWork(CBigNum bnBestInvalidWork) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
477 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
478 return Write(string("bnBestInvalidWork"), bnBestInvalidWork); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
479 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
480 |
690 | 481 CBlockIndex static * InsertBlockIndex(uint256 hash) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
482 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
483 if (hash == 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
484 return NULL; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
485 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
486 // Return existing |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
487 map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hash); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
488 if (mi != mapBlockIndex.end()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
489 return (*mi).second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
490 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
491 // Create new |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
492 CBlockIndex* pindexNew = new CBlockIndex(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
493 if (!pindexNew) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
494 throw runtime_error("LoadBlockIndex() : new CBlockIndex failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
495 mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
496 pindexNew->phashBlock = &((*mi).first); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
497 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
498 return pindexNew; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
499 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
500 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
501 bool CTxDB::LoadBlockIndex() |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
502 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
503 // Get database cursor |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
504 Dbc* pcursor = GetCursor(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
505 if (!pcursor) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
506 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
507 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
508 // Load mapBlockIndex |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
509 unsigned int fFlags = DB_SET_RANGE; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
510 loop |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
511 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
512 // Read next record |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
513 CDataStream ssKey; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
514 if (fFlags == DB_SET_RANGE) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
515 ssKey << make_pair(string("blockindex"), uint256(0)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
516 CDataStream ssValue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
517 int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
518 fFlags = DB_NEXT; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
519 if (ret == DB_NOTFOUND) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
520 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
521 else if (ret != 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
522 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
523 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
524 // Unserialize |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
525 string strType; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
526 ssKey >> strType; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
527 if (strType == "blockindex") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
528 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
529 CDiskBlockIndex diskindex; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
530 ssValue >> diskindex; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
531 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
532 // Construct block index object |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
533 CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetBlockHash()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
534 pindexNew->pprev = InsertBlockIndex(diskindex.hashPrev); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
535 pindexNew->pnext = InsertBlockIndex(diskindex.hashNext); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
536 pindexNew->nFile = diskindex.nFile; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
537 pindexNew->nBlockPos = diskindex.nBlockPos; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
538 pindexNew->nHeight = diskindex.nHeight; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
539 pindexNew->nVersion = diskindex.nVersion; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
540 pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
541 pindexNew->nTime = diskindex.nTime; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
542 pindexNew->nBits = diskindex.nBits; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
543 pindexNew->nNonce = diskindex.nNonce; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
544 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
545 // Watch for genesis block |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
546 if (pindexGenesisBlock == NULL && diskindex.GetBlockHash() == hashGenesisBlock) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
547 pindexGenesisBlock = pindexNew; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
548 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
549 if (!pindexNew->CheckIndex()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
550 return error("LoadBlockIndex() : CheckIndex failed at %d", pindexNew->nHeight); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
551 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
552 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
553 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
554 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
555 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
556 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
557 pcursor->close(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
558 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
559 // Calculate bnChainWork |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
560 vector<pair<int, CBlockIndex*> > vSortedByHeight; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
561 vSortedByHeight.reserve(mapBlockIndex.size()); |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
576
diff
changeset
|
562 BOOST_FOREACH(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
563 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
564 CBlockIndex* pindex = item.second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
565 vSortedByHeight.push_back(make_pair(pindex->nHeight, pindex)); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
566 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
567 sort(vSortedByHeight.begin(), vSortedByHeight.end()); |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
576
diff
changeset
|
568 BOOST_FOREACH(const PAIRTYPE(int, CBlockIndex*)& item, vSortedByHeight) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
569 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
570 CBlockIndex* pindex = item.second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
571 pindex->bnChainWork = (pindex->pprev ? pindex->pprev->bnChainWork : 0) + pindex->GetBlockWork(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
572 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
573 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
574 // Load hashBestChain pointer to end of best chain |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
575 if (!ReadHashBestChain(hashBestChain)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
576 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
577 if (pindexGenesisBlock == NULL) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
578 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
579 return error("CTxDB::LoadBlockIndex() : hashBestChain not loaded"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
580 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
581 if (!mapBlockIndex.count(hashBestChain)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
582 return error("CTxDB::LoadBlockIndex() : hashBestChain not found in the block index"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
583 pindexBest = mapBlockIndex[hashBestChain]; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
584 nBestHeight = pindexBest->nHeight; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
585 bnBestChainWork = pindexBest->bnChainWork; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
586 printf("LoadBlockIndex(): hashBestChain=%s height=%d\n", hashBestChain.ToString().substr(0,20).c_str(), nBestHeight); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
587 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
588 // Load bnBestInvalidWork, OK if it doesn't exist |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
589 ReadBestInvalidWork(bnBestInvalidWork); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
590 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
591 // Verify blocks in the best chain |
2076
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
592 int nCheckLevel = GetArg("-checklevel", 1); |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
593 int nCheckDepth = GetArg( "-checkblocks", 2500); |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
594 if (nCheckDepth == 0) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
595 nCheckDepth = 1000000000; // suffices until the year 19000 |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
596 if (nCheckDepth > nBestHeight) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
597 nCheckDepth = nBestHeight; |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
598 printf("Verifying last %i blocks at level %i\n", nCheckDepth, nCheckLevel); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
599 CBlockIndex* pindexFork = NULL; |
2076
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
600 map<pair<unsigned int, unsigned int>, CBlockIndex*> mapBlockPos; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
601 for (CBlockIndex* pindex = pindexBest; pindex && pindex->pprev; pindex = pindex->pprev) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
602 { |
2076
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
603 if (pindex->nHeight < nBestHeight-nCheckDepth) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
604 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
605 CBlock block; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
606 if (!block.ReadFromDisk(pindex)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
607 return error("LoadBlockIndex() : block.ReadFromDisk failed"); |
2076
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
608 // check level 1: verify block validity |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
609 if (nCheckLevel>0 && !block.CheckBlock()) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
610 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
611 printf("LoadBlockIndex() : *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
612 pindexFork = pindex->pprev; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
613 } |
2076
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
614 // check level 2: verify transaction index validity |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
615 if (nCheckLevel>1) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
616 { |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
617 pair<unsigned int, unsigned int> pos = make_pair(pindex->nFile, pindex->nBlockPos); |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
618 mapBlockPos[pos] = pindex; |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
619 BOOST_FOREACH(const CTransaction &tx, block.vtx) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
620 { |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
621 uint256 hashTx = tx.GetHash(); |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
622 CTxIndex txindex; |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
623 if (ReadTxIndex(hashTx, txindex)) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
624 { |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
625 // check level 3: checker transaction hashes |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
626 if (nCheckLevel>2 || pindex->nFile != txindex.pos.nFile || pindex->nBlockPos != txindex.pos.nBlockPos) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
627 { |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
628 // either an error or a duplicate transaction |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
629 CTransaction txFound; |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
630 if (!txFound.ReadFromDisk(txindex.pos)) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
631 { |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
632 printf("LoadBlockIndex() : *** cannot read mislocated transaction %s\n", hashTx.ToString().c_str()); |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
633 pindexFork = pindex->pprev; |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
634 } |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
635 else |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
636 if (txFound.GetHash() != hashTx) // not a duplicate tx |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
637 { |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
638 printf("LoadBlockIndex(): *** invalid tx position for %s\n", hashTx.ToString().c_str()); |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
639 pindexFork = pindex->pprev; |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
640 } |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
641 } |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
642 // check level 4: check whether spent txouts were spent within the main chain |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
643 int nOutput = 0; |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
644 if (nCheckLevel>3) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
645 BOOST_FOREACH(const CDiskTxPos &txpos, txindex.vSpent) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
646 { |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
647 if (!txpos.IsNull()) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
648 { |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
649 pair<unsigned int, unsigned int> posFind = make_pair(txpos.nFile, txpos.nBlockPos); |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
650 if (!mapBlockPos.count(posFind)) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
651 { |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
652 printf("LoadBlockIndex(): *** found bad spend at %d, hashBlock=%s, hashTx=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str(), hashTx.ToString().c_str()); |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
653 pindexFork = pindex->pprev; |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
654 } |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
655 // check level 6: check whether spent txouts were spent by a valid transaction that consume them |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
656 if (nCheckLevel>5) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
657 { |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
658 CTransaction txSpend; |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
659 if (!txSpend.ReadFromDisk(txpos)) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
660 { |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
661 printf("LoadBlockIndex(): *** cannot read spending transaction of %s:%i from disk\n", hashTx.ToString().c_str(), nOutput); |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
662 pindexFork = pindex->pprev; |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
663 } |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
664 else if (!txSpend.CheckTransaction()) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
665 { |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
666 printf("LoadBlockIndex(): *** spending transaction of %s:%i is invalid\n", hashTx.ToString().c_str(), nOutput); |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
667 pindexFork = pindex->pprev; |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
668 } |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
669 else |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
670 { |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
671 bool fFound = false; |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
672 BOOST_FOREACH(const CTxIn &txin, txSpend.vin) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
673 if (txin.prevout.hash == hashTx && txin.prevout.n == nOutput) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
674 fFound = true; |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
675 if (!fFound) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
676 { |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
677 printf("LoadBlockIndex(): *** spending transaction of %s:%i does not spend it\n", hashTx.ToString().c_str(), nOutput); |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
678 pindexFork = pindex->pprev; |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
679 } |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
680 } |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
681 } |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
682 } |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
683 nOutput++; |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
684 } |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
685 } |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
686 // check level 5: check whether all prevouts are marked spent |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
687 if (nCheckLevel>4) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
688 BOOST_FOREACH(const CTxIn &txin, tx.vin) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
689 { |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
690 CTxIndex txindex; |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
691 if (ReadTxIndex(txin.prevout.hash, txindex)) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
692 if (txindex.vSpent.size()-1 < txin.prevout.n || txindex.vSpent[txin.prevout.n].IsNull()) |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
693 { |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
694 printf("LoadBlockIndex(): *** found unspent prevout %s:%i in %s\n", txin.prevout.hash.ToString().c_str(), txin.prevout.n, hashTx.ToString().c_str()); |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
695 pindexFork = pindex->pprev; |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
696 } |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
697 } |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
698 } |
17f721892510
Add -checklevel and improve -checkblocks
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
699 } |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
700 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
701 if (pindexFork) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
702 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
703 // Reorg back to the fork |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
704 printf("LoadBlockIndex() : *** moving best chain pointer back to block %d\n", pindexFork->nHeight); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
705 CBlock block; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
706 if (!block.ReadFromDisk(pindexFork)) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
707 return error("LoadBlockIndex() : block.ReadFromDisk failed"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
708 CTxDB txdb; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
709 block.SetBestChain(txdb, pindexFork); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
710 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
711 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
712 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
713 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
714 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
715 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
716 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
717 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
718 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
719 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
720 // CAddrDB |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
721 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
722 |
1911
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
723 bool CAddrDB::WriteAddrman(const CAddrMan& addrman) |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
724 { |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
725 return Write(string("addrman"), addrman); |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
726 } |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
727 |
2097
3811124fc664
Use erase instead of rewrite to remove old addr entries
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2084
diff
changeset
|
728 bool CAddrDB::LoadAddresses() |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
729 { |
1911
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
730 if (Read(string("addrman"), addrman)) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
731 { |
1911
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
732 printf("Loaded %i addresses\n", addrman.size()); |
2117
84a09265db06
Workaround hangs when upgrading old addr.dat files
Gavin Andresen <gavinandresen@gmail.com>
parents:
2114
diff
changeset
|
733 return true; |
1911
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
734 } |
2117
84a09265db06
Workaround hangs when upgrading old addr.dat files
Gavin Andresen <gavinandresen@gmail.com>
parents:
2114
diff
changeset
|
735 |
84a09265db06
Workaround hangs when upgrading old addr.dat files
Gavin Andresen <gavinandresen@gmail.com>
parents:
2114
diff
changeset
|
736 // Read pre-0.6 addr records |
1911
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
737 |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
738 vector<CAddress> vAddr; |
2097
3811124fc664
Use erase instead of rewrite to remove old addr entries
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2084
diff
changeset
|
739 vector<vector<unsigned char> > vDelete; |
1911
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
740 |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
741 // Get cursor |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
742 Dbc* pcursor = GetCursor(); |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
743 if (!pcursor) |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
744 return false; |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
745 |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
746 loop |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
747 { |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
748 // Read next record |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
749 CDataStream ssKey; |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
750 CDataStream ssValue; |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
751 int ret = ReadAtCursor(pcursor, ssKey, ssValue); |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
752 if (ret == DB_NOTFOUND) |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
753 break; |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
754 else if (ret != 0) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
755 return false; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
756 |
1911
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
757 // Unserialize |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
758 string strType; |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
759 ssKey >> strType; |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
760 if (strType == "addr") |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
761 { |
2117
84a09265db06
Workaround hangs when upgrading old addr.dat files
Gavin Andresen <gavinandresen@gmail.com>
parents:
2114
diff
changeset
|
762 CAddress addr; |
84a09265db06
Workaround hangs when upgrading old addr.dat files
Gavin Andresen <gavinandresen@gmail.com>
parents:
2114
diff
changeset
|
763 ssValue >> addr; |
84a09265db06
Workaround hangs when upgrading old addr.dat files
Gavin Andresen <gavinandresen@gmail.com>
parents:
2114
diff
changeset
|
764 vAddr.push_back(addr); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
765 } |
1911
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
766 } |
a9190d020909
CAddrMan: stochastic address manager
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1873
diff
changeset
|
767 pcursor->close(); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
768 |
2117
84a09265db06
Workaround hangs when upgrading old addr.dat files
Gavin Andresen <gavinandresen@gmail.com>
parents:
2114
diff
changeset
|
769 addrman.Add(vAddr, CNetAddr("0.0.0.0")); |
84a09265db06
Workaround hangs when upgrading old addr.dat files
Gavin Andresen <gavinandresen@gmail.com>
parents:
2114
diff
changeset
|
770 printf("Loaded %i addresses\n", addrman.size()); |
2097
3811124fc664
Use erase instead of rewrite to remove old addr entries
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2084
diff
changeset
|
771 |
2117
84a09265db06
Workaround hangs when upgrading old addr.dat files
Gavin Andresen <gavinandresen@gmail.com>
parents:
2114
diff
changeset
|
772 // Note: old records left; we ran into hangs-on-startup |
84a09265db06
Workaround hangs when upgrading old addr.dat files
Gavin Andresen <gavinandresen@gmail.com>
parents:
2114
diff
changeset
|
773 // bugs for some users who (we think) were running after |
84a09265db06
Workaround hangs when upgrading old addr.dat files
Gavin Andresen <gavinandresen@gmail.com>
parents:
2114
diff
changeset
|
774 // an unclean shutdown. |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
775 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
776 return true; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
777 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
778 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
779 bool LoadAddresses() |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
780 { |
2097
3811124fc664
Use erase instead of rewrite to remove old addr entries
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2084
diff
changeset
|
781 return CAddrDB("cr+").LoadAddresses(); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
782 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
783 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
784 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
785 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
786 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
787 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
788 // CWalletDB |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
789 // |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
790 |
690 | 791 bool CWalletDB::WriteName(const string& strAddress, const string& strName) |
792 { | |
793 nWalletDBUpdated++; | |
794 return Write(make_pair(string("name"), strAddress), strName); | |
795 } | |
796 | |
797 bool CWalletDB::EraseName(const string& strAddress) | |
798 { | |
799 // This should only be used for sending addresses, never for receiving addresses, | |
800 // receiving addresses must always have an address book entry if they're not change return. | |
801 nWalletDBUpdated++; | |
802 return Erase(make_pair(string("name"), strAddress)); | |
803 } | |
804 | |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
805 bool CWalletDB::ReadAccount(const string& strAccount, CAccount& account) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
806 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
807 account.SetNull(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
808 return Read(make_pair(string("acc"), strAccount), account); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
809 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
810 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
811 bool CWalletDB::WriteAccount(const string& strAccount, const CAccount& account) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
812 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
813 return Write(make_pair(string("acc"), strAccount), account); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
814 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
815 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
816 bool CWalletDB::WriteAccountingEntry(const CAccountingEntry& acentry) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
817 { |
847
b0c5cacbefd1
Qualify make_tuple with boost:: namespace.
Venkatesh Srinivas <me@endeavour.zapto.org>
parents:
829
diff
changeset
|
818 return Write(boost::make_tuple(string("acentry"), acentry.strAccount, ++nAccountingEntryNumber), acentry); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
819 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
820 |
1616
997b708d15b8
Revert "Use standard C99 (and Qt) types for 64-bit integers"
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
1615
diff
changeset
|
821 int64 CWalletDB::GetAccountCreditDebit(const string& strAccount) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
822 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
823 list<CAccountingEntry> entries; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
824 ListAccountCreditDebit(strAccount, entries); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
825 |
1616
997b708d15b8
Revert "Use standard C99 (and Qt) types for 64-bit integers"
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
1615
diff
changeset
|
826 int64 nCreditDebit = 0; |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
576
diff
changeset
|
827 BOOST_FOREACH (const CAccountingEntry& entry, entries) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
828 nCreditDebit += entry.nCreditDebit; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
829 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
830 return nCreditDebit; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
831 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
832 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
833 void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountingEntry>& entries) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
834 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
835 bool fAllAccounts = (strAccount == "*"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
836 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
837 Dbc* pcursor = GetCursor(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
838 if (!pcursor) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
839 throw runtime_error("CWalletDB::ListAccountCreditDebit() : cannot create DB cursor"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
840 unsigned int fFlags = DB_SET_RANGE; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
841 loop |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
842 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
843 // Read next record |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
844 CDataStream ssKey; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
845 if (fFlags == DB_SET_RANGE) |
1616
997b708d15b8
Revert "Use standard C99 (and Qt) types for 64-bit integers"
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
1615
diff
changeset
|
846 ssKey << boost::make_tuple(string("acentry"), (fAllAccounts? string("") : strAccount), uint64(0)); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
847 CDataStream ssValue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
848 int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
849 fFlags = DB_NEXT; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
850 if (ret == DB_NOTFOUND) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
851 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
852 else if (ret != 0) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
853 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
854 pcursor->close(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
855 throw runtime_error("CWalletDB::ListAccountCreditDebit() : error scanning DB"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
856 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
857 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
858 // Unserialize |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
859 string strType; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
860 ssKey >> strType; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
861 if (strType != "acentry") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
862 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
863 CAccountingEntry acentry; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
864 ssKey >> acentry.strAccount; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
865 if (!fAllAccounts && acentry.strAccount != strAccount) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
866 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
867 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
868 ssValue >> acentry; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
869 entries.push_back(acentry); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
870 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
871 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
872 pcursor->close(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
873 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
874 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
875 |
746 | 876 int CWalletDB::LoadWallet(CWallet* pwallet) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
877 { |
690 | 878 pwallet->vchDefaultKey.clear(); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
879 int nFileVersion = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
880 vector<uint256> vWalletUpgrade; |
1500 | 881 bool fIsEncrypted = false; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
882 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
883 //// todo: shouldn't we catch exceptions and try to recover and continue? |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
884 { |
2190
60fe81a4849b
Use scoped locks instead of CRITICAL_BLOCK
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2176
diff
changeset
|
885 LOCK(pwallet->cs_wallet); |
2077
e7bff989672b
Check minversion before loading the rest of the wallet
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
886 int nMinVersion = 0; |
e7bff989672b
Check minversion before loading the rest of the wallet
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
887 if (Read((string)"minversion", nMinVersion)) |
e7bff989672b
Check minversion before loading the rest of the wallet
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
888 { |
e7bff989672b
Check minversion before loading the rest of the wallet
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
889 if (nMinVersion > CLIENT_VERSION) |
e7bff989672b
Check minversion before loading the rest of the wallet
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
890 return DB_TOO_NEW; |
e7bff989672b
Check minversion before loading the rest of the wallet
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
891 pwallet->LoadMinVersion(nMinVersion); |
e7bff989672b
Check minversion before loading the rest of the wallet
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
892 } |
e7bff989672b
Check minversion before loading the rest of the wallet
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2033
diff
changeset
|
893 |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
894 // Get cursor |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
895 Dbc* pcursor = GetCursor(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
896 if (!pcursor) |
2033
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
897 { |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
898 printf("Error getting wallet database cursor\n"); |
746 | 899 return DB_CORRUPT; |
2033
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
900 } |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
901 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
902 loop |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
903 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
904 // Read next record |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
905 CDataStream ssKey; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
906 CDataStream ssValue; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
907 int ret = ReadAtCursor(pcursor, ssKey, ssValue); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
908 if (ret == DB_NOTFOUND) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
909 break; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
910 else if (ret != 0) |
2033
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
911 { |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
912 printf("Error reading next record from wallet database\n"); |
746 | 913 return DB_CORRUPT; |
2033
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
914 } |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
915 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
916 // Unserialize |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
917 // Taking advantage of the fact that pair serialization |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
918 // is just the two items serialized one after the other |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
919 string strType; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
920 ssKey >> strType; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
921 if (strType == "name") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
922 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
923 string strAddress; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
924 ssKey >> strAddress; |
690 | 925 ssValue >> pwallet->mapAddressBook[strAddress]; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
926 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
927 else if (strType == "tx") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
928 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
929 uint256 hash; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
930 ssKey >> hash; |
690 | 931 CWalletTx& wtx = pwallet->mapWallet[hash]; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
932 ssValue >> wtx; |
1579
7e38a961d343
Make CWalletTx::pwallet private
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1511
diff
changeset
|
933 wtx.BindWallet(pwallet); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
934 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
935 if (wtx.GetHash() != hash) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
936 printf("Error in wallet.dat, hash mismatch\n"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
937 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
938 // Undo serialize changes in 31600 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
939 if (31404 <= wtx.fTimeReceivedIsTxTime && wtx.fTimeReceivedIsTxTime <= 31703) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
940 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
941 if (!ssValue.empty()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
942 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
943 char fTmp; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
944 char fUnused; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
945 ssValue >> fTmp >> fUnused >> wtx.strFromAccount; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
946 printf("LoadWallet() upgrading tx ver=%d %d '%s' %s\n", wtx.fTimeReceivedIsTxTime, fTmp, wtx.strFromAccount.c_str(), hash.ToString().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
947 wtx.fTimeReceivedIsTxTime = fTmp; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
948 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
949 else |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
950 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
951 printf("LoadWallet() repairing tx ver=%d %s\n", wtx.fTimeReceivedIsTxTime, hash.ToString().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
952 wtx.fTimeReceivedIsTxTime = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
953 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
954 vWalletUpgrade.push_back(hash); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
955 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
956 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
957 //// debug print |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
958 //printf("LoadWallet %s\n", wtx.GetHash().ToString().c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
959 //printf(" %12I64d %s %s %s\n", |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
960 // wtx.vout[0].nValue, |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
961 // DateTimeStrFormat("%x %H:%M:%S", wtx.GetBlockTime()).c_str(), |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
962 // wtx.hashBlock.ToString().substr(0,20).c_str(), |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
963 // wtx.mapValue["message"].c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
964 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
965 else if (strType == "acentry") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
966 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
967 string strAccount; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
968 ssKey >> strAccount; |
1616
997b708d15b8
Revert "Use standard C99 (and Qt) types for 64-bit integers"
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
1615
diff
changeset
|
969 uint64 nNumber; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
970 ssKey >> nNumber; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
971 if (nNumber > nAccountingEntryNumber) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
972 nAccountingEntryNumber = nNumber; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
973 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
974 else if (strType == "key" || strType == "wkey") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
975 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
976 vector<unsigned char> vchPubKey; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
977 ssKey >> vchPubKey; |
757
ee9183806240
Prepare codebase for Encrypted Keys.
Pieter Wuille <pieter.wuille@gmail.com>
parents:
695
diff
changeset
|
978 CKey key; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
979 if (strType == "key") |
757
ee9183806240
Prepare codebase for Encrypted Keys.
Pieter Wuille <pieter.wuille@gmail.com>
parents:
695
diff
changeset
|
980 { |
ee9183806240
Prepare codebase for Encrypted Keys.
Pieter Wuille <pieter.wuille@gmail.com>
parents:
695
diff
changeset
|
981 CPrivKey pkey; |
ee9183806240
Prepare codebase for Encrypted Keys.
Pieter Wuille <pieter.wuille@gmail.com>
parents:
695
diff
changeset
|
982 ssValue >> pkey; |
1734
adac2d60ce43
Compressed pubkeys
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1616
diff
changeset
|
983 key.SetPubKey(vchPubKey); |
757
ee9183806240
Prepare codebase for Encrypted Keys.
Pieter Wuille <pieter.wuille@gmail.com>
parents:
695
diff
changeset
|
984 key.SetPrivKey(pkey); |
2033
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
985 if (key.GetPubKey() != vchPubKey) |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
986 { |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
987 printf("Error reading wallet database: CPrivKey pubkey inconsistency\n"); |
1781
1f19caeaca2d
Check consistency of private keys
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1752
diff
changeset
|
988 return DB_CORRUPT; |
2033
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
989 } |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
990 if (!key.IsValid()) |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
991 { |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
992 printf("Error reading wallet database: invalid CPrivKey\n"); |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
993 return DB_CORRUPT; |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
994 } |
757
ee9183806240
Prepare codebase for Encrypted Keys.
Pieter Wuille <pieter.wuille@gmail.com>
parents:
695
diff
changeset
|
995 } |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
996 else |
757
ee9183806240
Prepare codebase for Encrypted Keys.
Pieter Wuille <pieter.wuille@gmail.com>
parents:
695
diff
changeset
|
997 { |
ee9183806240
Prepare codebase for Encrypted Keys.
Pieter Wuille <pieter.wuille@gmail.com>
parents:
695
diff
changeset
|
998 CWalletKey wkey; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
999 ssValue >> wkey; |
1734
adac2d60ce43
Compressed pubkeys
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1616
diff
changeset
|
1000 key.SetPubKey(vchPubKey); |
757
ee9183806240
Prepare codebase for Encrypted Keys.
Pieter Wuille <pieter.wuille@gmail.com>
parents:
695
diff
changeset
|
1001 key.SetPrivKey(wkey.vchPrivKey); |
2033
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1002 if (key.GetPubKey() != vchPubKey) |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1003 { |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1004 printf("Error reading wallet database: CWalletKey pubkey inconsistency\n"); |
1790
970e802a5b28
Full checking of all loaded keys
Pieter Wuille <pieter.wuille@gmail.com>
parents:
1781
diff
changeset
|
1005 return DB_CORRUPT; |
2033
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1006 } |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1007 if (!key.IsValid()) |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1008 { |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1009 printf("Error reading wallet database: invalid CWalletKey\n"); |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1010 return DB_CORRUPT; |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1011 } |
757
ee9183806240
Prepare codebase for Encrypted Keys.
Pieter Wuille <pieter.wuille@gmail.com>
parents:
695
diff
changeset
|
1012 } |
760
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1013 if (!pwallet->LoadKey(key)) |
2033
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1014 { |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1015 printf("Error reading wallet database: LoadKey failed\n"); |
802
4b444ebb854e
Fix bad return values in LoadWallet.
Matt Corallo <matt@bluematt.me>
parents:
780
diff
changeset
|
1016 return DB_CORRUPT; |
2033
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1017 } |
760
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1018 } |
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1019 else if (strType == "mkey") |
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1020 { |
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1021 unsigned int nID; |
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1022 ssKey >> nID; |
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1023 CMasterKey kMasterKey; |
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1024 ssValue >> kMasterKey; |
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1025 if(pwallet->mapMasterKeys.count(nID) != 0) |
2033
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1026 { |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1027 printf("Error reading wallet database: duplicate CMasterKey id %u\n", nID); |
802
4b444ebb854e
Fix bad return values in LoadWallet.
Matt Corallo <matt@bluematt.me>
parents:
780
diff
changeset
|
1028 return DB_CORRUPT; |
2033
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1029 } |
760
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1030 pwallet->mapMasterKeys[nID] = kMasterKey; |
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1031 if (pwallet->nMasterKeyMaxID < nID) |
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1032 pwallet->nMasterKeyMaxID = nID; |
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1033 } |
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1034 else if (strType == "ckey") |
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1035 { |
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1036 vector<unsigned char> vchPubKey; |
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1037 ssKey >> vchPubKey; |
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1038 vector<unsigned char> vchPrivKey; |
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1039 ssValue >> vchPrivKey; |
fd7e5b1cfc08
Add wallet privkey encryption.
Matt Corallo <matt@bluematt.me>
parents:
757
diff
changeset
|
1040 if (!pwallet->LoadCryptedKey(vchPubKey, vchPrivKey)) |
2033
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1041 { |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1042 printf("Error reading wallet database: LoadCryptedKey failed\n"); |
802
4b444ebb854e
Fix bad return values in LoadWallet.
Matt Corallo <matt@bluematt.me>
parents:
780
diff
changeset
|
1043 return DB_CORRUPT; |
2033
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1044 } |
1500 | 1045 fIsEncrypted = true; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1046 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1047 else if (strType == "defaultkey") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1048 { |
690 | 1049 ssValue >> pwallet->vchDefaultKey; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1050 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1051 else if (strType == "pool") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1052 { |
1616
997b708d15b8
Revert "Use standard C99 (and Qt) types for 64-bit integers"
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
1615
diff
changeset
|
1053 int64 nIndex; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1054 ssKey >> nIndex; |
690 | 1055 pwallet->setKeyPool.insert(nIndex); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1056 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1057 else if (strType == "version") |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1058 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1059 ssValue >> nFileVersion; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1060 if (nFileVersion == 10300) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1061 nFileVersion = 300; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1062 } |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1588
diff
changeset
|
1063 else if (strType == "cscript") |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1588
diff
changeset
|
1064 { |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1588
diff
changeset
|
1065 uint160 hash; |
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1588
diff
changeset
|
1066 ssKey >> hash; |
1604
2d635cbb6a2d
Use block times for 'hard' OP_EVAL switchover, and refactored EvalScript
Gavin Andresen <gavinandresen@gmail.com>
parents:
1600
diff
changeset
|
1067 CScript script; |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1588
diff
changeset
|
1068 ssValue >> script; |
1752
7b4383bddf3b
Replace OP_EVAL (BIP 12) with Pay-to-script-hash (BIP 16).
Gavin Andresen <gavinandresen@gmail.com>
parents:
1734
diff
changeset
|
1069 if (!pwallet->LoadCScript(script)) |
2033
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1070 { |
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1071 printf("Error reading wallet database: LoadCScript failed\n"); |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1588
diff
changeset
|
1072 return DB_CORRUPT; |
2033
2d8be499a5d4
Print more diagnostic info for the various DB_CORRUPT conditions
Luke Dashjr <luke-jr+git@utopios.org>
parents:
1920
diff
changeset
|
1073 } |
1600
dc663e46a784
OP_EVAL implementation
Gavin Andresen <gavinandresen@gmail.com>
parents:
1588
diff
changeset
|
1074 } |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1075 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1076 pcursor->close(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1077 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1078 |
595
e630bbb11629
make bitcoin include files more modular
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
576
diff
changeset
|
1079 BOOST_FOREACH(uint256 hash, vWalletUpgrade) |
690 | 1080 WriteTx(hash, pwallet->mapWallet[hash]); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1081 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1082 printf("nFileVersion = %d\n", nFileVersion); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1083 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1084 |
1501
26d0f350347a
Obsolete keypool and make sure database removes log files on shutdown.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1500
diff
changeset
|
1085 // Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc: |
26d0f350347a
Obsolete keypool and make sure database removes log files on shutdown.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1500
diff
changeset
|
1086 if (fIsEncrypted && (nFileVersion == 40000 || nFileVersion == 50000)) |
26d0f350347a
Obsolete keypool and make sure database removes log files on shutdown.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1500
diff
changeset
|
1087 return DB_NEED_REWRITE; |
26d0f350347a
Obsolete keypool and make sure database removes log files on shutdown.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1500
diff
changeset
|
1088 |
1584
a67f13278e2c
Implement BIP 14 : separate protocol version from client version
Gavin Andresen <gavinandresen@gmail.com>
parents:
1511
diff
changeset
|
1089 if (nFileVersion < CLIENT_VERSION) // Update |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1090 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1091 // Get rid of old debug.log file in current directory |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1092 if (nFileVersion <= 105 && !pszSetDataDir[0]) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1093 unlink("debug.log"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1094 |
1584
a67f13278e2c
Implement BIP 14 : separate protocol version from client version
Gavin Andresen <gavinandresen@gmail.com>
parents:
1511
diff
changeset
|
1095 WriteVersion(CLIENT_VERSION); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1096 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1097 |
746 | 1098 return DB_LOAD_OK; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1099 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1100 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1101 void ThreadFlushWalletDB(void* parg) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1102 { |
690 | 1103 const string& strFile = ((const string*)parg)[0]; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1104 static bool fOneThread; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1105 if (fOneThread) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1106 return; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1107 fOneThread = true; |
1813
89e8d0058523
Look for flushwallet/listen/irc/dnsseed/upnp instead of noflushwallet/etc. And switch default for irc to 0.
Gavin Andresen <gavinandresen@gmail.com>
parents:
1790
diff
changeset
|
1108 if (!GetBoolArg("-flushwallet", true)) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1109 return; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1110 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1111 unsigned int nLastSeen = nWalletDBUpdated; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1112 unsigned int nLastFlushed = nWalletDBUpdated; |
1616
997b708d15b8
Revert "Use standard C99 (and Qt) types for 64-bit integers"
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
1615
diff
changeset
|
1113 int64 nLastWalletUpdate = GetTime(); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1114 while (!fShutdown) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1115 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1116 Sleep(500); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1117 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1118 if (nLastSeen != nWalletDBUpdated) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1119 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1120 nLastSeen = nWalletDBUpdated; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1121 nLastWalletUpdate = GetTime(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1122 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1123 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1124 if (nLastFlushed != nWalletDBUpdated && GetTime() - nLastWalletUpdate >= 2) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1125 { |
2190
60fe81a4849b
Use scoped locks instead of CRITICAL_BLOCK
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2176
diff
changeset
|
1126 TRY_LOCK(cs_db,lockDb); |
60fe81a4849b
Use scoped locks instead of CRITICAL_BLOCK
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2176
diff
changeset
|
1127 if (lockDb) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1128 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1129 // Don't do this if any databases are in use |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1130 int nRefCount = 0; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1131 map<string, int>::iterator mi = mapFileUseCount.begin(); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1132 while (mi != mapFileUseCount.end()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1133 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1134 nRefCount += (*mi).second; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1135 mi++; |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1136 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1137 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1138 if (nRefCount == 0 && !fShutdown) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1139 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1140 map<string, int>::iterator mi = mapFileUseCount.find(strFile); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1141 if (mi != mapFileUseCount.end()) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1142 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1143 printf("%s ", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str()); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1144 printf("Flushing wallet.dat\n"); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1145 nLastFlushed = nWalletDBUpdated; |
1616
997b708d15b8
Revert "Use standard C99 (and Qt) types for 64-bit integers"
Wladimir J. van der Laan <laanwj@gmail.com>
parents:
1615
diff
changeset
|
1146 int64 nStart = GetTimeMillis(); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1147 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1148 // Flush wallet.dat so it's self contained |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1149 CloseDb(strFile); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1150 dbenv.txn_checkpoint(0, 0, 0); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1151 dbenv.lsn_reset(strFile.c_str(), 0); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1152 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1153 mapFileUseCount.erase(mi++); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1154 printf("Flushed wallet.dat %"PRI64d"ms\n", GetTimeMillis() - nStart); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1155 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1156 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1157 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1158 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1159 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1160 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1161 |
690 | 1162 bool BackupWallet(const CWallet& wallet, const string& strDest) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1163 { |
690 | 1164 if (!wallet.fFileBacked) |
1165 return false; | |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1166 while (!fShutdown) |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1167 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1168 { |
2190
60fe81a4849b
Use scoped locks instead of CRITICAL_BLOCK
Pieter Wuille <pieter.wuille@gmail.com>
parents:
2176
diff
changeset
|
1169 LOCK(cs_db); |
690 | 1170 if (!mapFileUseCount.count(wallet.strWalletFile) || mapFileUseCount[wallet.strWalletFile] == 0) |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1171 { |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1172 // Flush log data to the dat file |
690 | 1173 CloseDb(wallet.strWalletFile); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1174 dbenv.txn_checkpoint(0, 0, 0); |
690 | 1175 dbenv.lsn_reset(wallet.strWalletFile.c_str(), 0); |
1176 mapFileUseCount.erase(wallet.strWalletFile); | |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1177 |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1178 // Copy wallet.dat |
690 | 1179 filesystem::path pathSrc(GetDataDir() + "/" + wallet.strWalletFile); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1180 filesystem::path pathDest(strDest); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1181 if (filesystem::is_directory(pathDest)) |
690 | 1182 pathDest = pathDest / wallet.strWalletFile; |
1840
0760e07f7938
Added 'Backup Wallet' menu option
sje397 <sje397@gmail.com>
parents:
1818
diff
changeset
|
1183 |
0760e07f7938
Added 'Backup Wallet' menu option
sje397 <sje397@gmail.com>
parents:
1818
diff
changeset
|
1184 try { |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1185 #if BOOST_VERSION >= 104000 |
1840
0760e07f7938
Added 'Backup Wallet' menu option
sje397 <sje397@gmail.com>
parents:
1818
diff
changeset
|
1186 filesystem::copy_file(pathSrc, pathDest, filesystem::copy_option::overwrite_if_exists); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1187 #else |
1840
0760e07f7938
Added 'Backup Wallet' menu option
sje397 <sje397@gmail.com>
parents:
1818
diff
changeset
|
1188 filesystem::copy_file(pathSrc, pathDest); |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1189 #endif |
1840
0760e07f7938
Added 'Backup Wallet' menu option
sje397 <sje397@gmail.com>
parents:
1818
diff
changeset
|
1190 printf("copied wallet.dat to %s\n", pathDest.string().c_str()); |
0760e07f7938
Added 'Backup Wallet' menu option
sje397 <sje397@gmail.com>
parents:
1818
diff
changeset
|
1191 return true; |
0760e07f7938
Added 'Backup Wallet' menu option
sje397 <sje397@gmail.com>
parents:
1818
diff
changeset
|
1192 } catch(const filesystem::filesystem_error &e) { |
0760e07f7938
Added 'Backup Wallet' menu option
sje397 <sje397@gmail.com>
parents:
1818
diff
changeset
|
1193 printf("error copying wallet.dat to %s - %s\n", pathDest.string().c_str(), e.what()); |
0760e07f7938
Added 'Backup Wallet' menu option
sje397 <sje397@gmail.com>
parents:
1818
diff
changeset
|
1194 return false; |
0760e07f7938
Added 'Backup Wallet' menu option
sje397 <sje397@gmail.com>
parents:
1818
diff
changeset
|
1195 } |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1196 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1197 } |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1198 Sleep(100); |
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1199 } |
690 | 1200 return false; |
575
1a0476fe825f
directory re-organization (keeps the old build system)
Jaromil <jaromil@dyne.org>
parents:
diff
changeset
|
1201 } |