forex.pm forex forum binary options trade

 Š”ryptocurrency exchanges => Binance - Š”ryptocurrency exchanges => Topic started by: Bitcoin on Mar 30, 2022, 05:37 am

Title: Java: bitcoinj; how to download a full block?
Post by: Bitcoin on Mar 30, 2022, 05:37 am
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? (https://bitcoin.stackexchange.com/questions/64001/java-bitcoinj-how-to-download-a-full-block)