mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-07 14:54:15 +00:00
Import from new block dir format
Also fixes a few minor bugs in BlockImporter.
This commit is contained in:
parent
726dd02472
commit
2e6e0661cb
@ -25,6 +25,7 @@ import com.google.bitcoin.store.H2FullPrunedBlockStore;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,19 +41,41 @@ public class BlockImporter {
|
|||||||
|
|
||||||
String defaultDataDir;
|
String defaultDataDir;
|
||||||
if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) {
|
if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) {
|
||||||
defaultDataDir = System.getenv("APPDATA") + "\\.bitcoin/";
|
defaultDataDir = System.getenv("APPDATA") + "\\.bitcoin\\blocks\\";
|
||||||
} else {
|
} else {
|
||||||
defaultDataDir = System.getProperty("user.home") + "/.bitcoin/";
|
defaultDataDir = System.getProperty("user.home") + "/.bitcoin/blocks/";
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Move this to a library function
|
// TODO: Move this to a library function
|
||||||
FileInputStream stream = new FileInputStream(new File(defaultDataDir + "blk0001.dat"));
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
for (int j = 0; true; j++) {
|
||||||
|
FileInputStream stream;
|
||||||
|
System.out.println("Opening " + defaultDataDir + String.format("blk%05d.dat", j));
|
||||||
|
try {
|
||||||
|
stream = new FileInputStream(new File(
|
||||||
|
defaultDataDir + String.format("blk%05d.dat", j)));
|
||||||
|
} catch (FileNotFoundException e1) {
|
||||||
|
System.out.println(defaultDataDir + String.format("blk%05d.dat", j));
|
||||||
|
break;
|
||||||
|
}
|
||||||
while (stream.available() > 0) {
|
while (stream.available() > 0) {
|
||||||
try {
|
try {
|
||||||
while(stream.read() != ((params.packetMagic >>> 24) & 0xff) || stream.read() != ((params.packetMagic >>> 16) & 0xff) ||
|
int nextChar = stream.read();
|
||||||
stream.read() != ((params.packetMagic >>> 8) & 0xff) || stream.read() != (params.packetMagic & 0xff))
|
while (nextChar != -1) {
|
||||||
;
|
if (nextChar != ((params.packetMagic >>> 24) & 0xff)) {
|
||||||
|
nextChar = stream.read();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
nextChar = stream.read();
|
||||||
|
if (nextChar != ((params.packetMagic >>> 16) & 0xff))
|
||||||
|
continue;
|
||||||
|
nextChar = stream.read();
|
||||||
|
if (nextChar != ((params.packetMagic >>> 8) & 0xff))
|
||||||
|
continue;
|
||||||
|
nextChar = stream.read();
|
||||||
|
if (nextChar == (params.packetMagic & 0xff))
|
||||||
|
break;
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -67,11 +90,13 @@ public class BlockImporter {
|
|||||||
if (store.get(block.getHash()) == null)
|
if (store.get(block.getHash()) == null)
|
||||||
chain.add(block);
|
chain.add(block);
|
||||||
|
|
||||||
if (i % 10000 == 0)
|
if (i % 1000 == 0)
|
||||||
System.out.println(i);
|
System.out.println(i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
stream.close();
|
stream.close();
|
||||||
|
}
|
||||||
System.out.println("Imported " + chain.getChainHead().getHeight() + " blocks.");
|
System.out.println("Imported " + chain.getChainHead().getHeight() + " blocks.");
|
||||||
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user