0
I would like to download a full block using Java and bitcoinj and then parse it to an array to be able to work with it. Here is some (very basic) pseudocode:
connect to network;
download latestBlock;
write/convert block to readable array;
read blockArray;
sout: blockArray[23][55] // this should get me eg. a txid, address, ...
// or similar. I just want to be able to read values from the block
Is there a way to do this? I found the following solution here (Using bitcoinj to discover peers and download the block chain):
public class DumpLastBlock {
public static void main(String args[]) throws Exception {
WalletAppKit kit = new WalletAppKit(MainNetParams.get(), new java.io.File("."), "test");
kit.startAndWait();
BlockChain chain = kit.chain();
BlockStore bs = chain.getBlockStore();
Peer peer = kit.peerGroup().getDownloadPeer();
Block b = peer.getBlock(bs.getChainHead().getHeader().getHash()).get();
System.out.println(b);
}
}
Unfortunately, kit.startAndWait() isn't available anymore.
Can someone help me to get the latest block and be able to read its values?
Thank you very much :)
Please add the details of the link as it relates to the question in your answer. In the current answer, if the link ceases to work, future users will not be able to get any information from it. – Raghav Sood – 2018-05-26T07:46:08.327