aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-02-20 20:50:26 +0100
committerPieter Wuille <pieter.wuille@gmail.com>2012-04-22 03:09:35 +0200
commit1d740055daa6e1668f047186d208b0693c6b21ba (patch)
tree1462b3f673bd286490b9b527381d3a91167b860c /src/main.cpp
parent7dbe393629a263675ccfd6fce8e7fc12496c808a (diff)
downloadbitcoin-1d740055daa6e1668f047186d208b0693c6b21ba.tar.xz
-loadblock to load from an external blk000?.dat file
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 78d84d9064..e2f1af4091 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2011,6 +2011,62 @@ void PrintBlockTree()
}
}
+bool LoadExternalBlockFile(FILE* fileIn)
+{
+ int nLoaded = 0;
+ {
+ LOCK(cs_main);
+ try {
+ CAutoFile blkdat(fileIn, SER_DISK, CLIENT_VERSION);
+ unsigned int nPos = 0;
+ while (nPos != -1 && blkdat.good() && !fRequestShutdown)
+ {
+ unsigned char pchData[65536];
+ do {
+ fseek(blkdat, nPos, SEEK_SET);
+ int nRead = fread(pchData, 1, sizeof(pchData), blkdat);
+ if (nRead <= 8)
+ {
+ nPos = -1;
+ break;
+ }
+ void* nFind = memchr(pchData, pchMessageStart[0], nRead+1-sizeof(pchMessageStart));
+ if (nFind)
+ {
+ if (memcmp(nFind, pchMessageStart, sizeof(pchMessageStart))==0)
+ {
+ nPos += ((unsigned char*)nFind - pchData) + sizeof(pchMessageStart);
+ break;
+ }
+ nPos += ((unsigned char*)nFind - pchData) + 1;
+ }
+ else
+ nPos += sizeof(pchData) - sizeof(pchMessageStart) + 1;
+ } while(!fRequestShutdown);
+ if (nPos == -1)
+ break;
+ fseek(blkdat, nPos, SEEK_SET);
+ unsigned int nSize;
+ blkdat >> nSize;
+ if (nSize > 0 && nSize <= MAX_BLOCK_SIZE)
+ {
+ CBlock block;
+ blkdat >> block;
+ if (ProcessBlock(NULL,&block))
+ {
+ nLoaded++;
+ nPos += 4 + nSize;
+ }
+ }
+ }
+ }
+ catch (std::exception &e)
+ {
+ }
+ }
+ printf("Loaded %i blocks from external file\n", nLoaded);
+ return nLoaded > 0;
+}