我下载了比特币同步: https ://bitcoin.org/bin/bitcoin-core-0.21.0/bitcoin-0.21.0-x86_64-linux-gnu.tar.gz
在 Java 中,我使用最新的bitcoinj-core
:
<dependency>
<groupId>org.bitcoinj</groupId>
<artifactId>bitcoinj-core</artifactId>
<version>0.15.10</version>
</dependency>
我有一个代码:
List<File> list = new ArrayList<>();
list.add(new File("/bitcoin/src/test/resources/rev00001.dat"));
MainNetParams params = MainNetParams.get();
Context context = new Context(params);
BlockFileLoader bfl = new BlockFileLoader(params, list);
for (Block block : bfl) {
System.out.println(block.getHashAsString());
}
我有一个例外:
java.lang.RuntimeException: unexpected problem with block in /bitcoin/src/test/resources/rev00001.dat
...
Caused by: java.lang.NegativeArraySizeException: -989849719
at org.bitcoinj.core.Message.readBytes(Message.java:337)