forex.pm forex forum binary options trade - Binance - Сryptocurrency exchanges - Java: bitcoinj; how to download a full block?
  • Welcome to forex.pm forex forum binary options trade. Please login or sign up.
 

Java: bitcoinj; how to download a full block?

Started by Bitcoin, Mar 30, 2022, 05:37 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bitcoin

Java: bitcoinj; how to download a full block?

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 :)


Source: Java: bitcoinj; how to download a full block?