diff options
| author | Pieter Wuille <[email protected]> | 2012-02-20 20:50:26 +0100 |
|---|---|---|
| committer | Pieter Wuille <[email protected]> | 2012-04-22 03:09:35 +0200 |
| commit | 1d740055daa6e1668f047186d208b0693c6b21ba (patch) | |
| tree | 1462b3f673bd286490b9b527381d3a91167b860c /src/main.cpp | |
| parent | Merge pull request #1131 from laanwj/2012_04_hexstr (diff) | |
| download | discoin-1d740055daa6e1668f047186d208b0693c6b21ba.tar.xz discoin-1d740055daa6e1668f047186d208b0693c6b21ba.zip | |
-loadblock to load from an external blk000?.dat file
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp index 78d84d906..e2f1af409 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; +} |