aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorGregory Maxwell <gmaxwell@gmail.com>2012-05-08 12:37:27 -0700
committerGregory Maxwell <gmaxwell@gmail.com>2012-05-08 12:37:27 -0700
commitf1ae31d8af8e03acbd224d486542b4409acf01ff (patch)
treec8869fb430c7b33b235e870e1066c9edd47fc3d5 /src/main.cpp
parentfa8cc47c4f70bd3e2b0f4bc5076aba40597b12ec (diff)
parent1d740055daa6e1668f047186d208b0693c6b21ba (diff)
Merge pull request #883 from sipa/loadblock
Add -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 821bfbb476..238f7c69e4 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2028,6 +2028,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;
+}