<p>I have found a temporary solution:</p>

<pre><code>BlockStore blockStore = new MyCustomBlockStore(NETWORK_PARAMETERS);
blockStore.getChainHead();

blockChain = new BlockChain(NETWORK_PARAMETERS, blockStore);

PeerGroup peerGroup = new PeerGroup(NETWORK_PARAMETERS, blockChain);
peerGroup.setDownloadTxDependencies(1000);
peerGroup.setBloomFilteringEnabled(false);
peerGroup.addPeerDiscovery(new PeerDiscovery() {
    private final PeerDiscovery normalPeerDiscovery = new DnsDiscovery(NETWORK_PARAMETERS);

    @Override
    public InetSocketAddress[] getPeers(long services, long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException {
        final List&lt;InetSocketAddress&gt; peers = new LinkedList&lt;InetSocketAddress&gt;();
            peers.addAll(Arrays.asList(normalPeerDiscovery.getPeers(services, timeoutValue, timeoutUnit)));
            InetSocketAddress[] isas = new InetSocketAddress[0];
            return peers.toArray(isas);
        }

    @Override
    public void shutdown() {
        normalPeerDiscovery.shutdown();
    }
});

peerGroup.startAsync();
peerGroup.startBlockChainDownload(new PeerDataEventListener() {
    public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int i) {

        List&lt;Transaction&gt; transactionsList = block.getTransactions();
        int transactions = transactionsList == null ? 0 : transactionsList.size();

        long height = peer.getBestHeight() - i;
        //If the block contains transactions, it is likely to be complete.
        Log.e(TAG, "Downloaded block " + height + " with " + transactions + " transactions");
        blockUpdate(block);
    }

    private void blockUpdate(Block fBlock) throws IOException {
        //TODO: Update blockchain database with the full block.
    }

    public void onChainDownloadStarted(Peer peer, int i) {
        Log.i(TAG, "Started to download chain on peer " + peer);
    }

    @Nullable
    public List&lt;Message&gt; getData(Peer peer, GetDataMessage getDataMessage) {
        //Log.i(TAG, "getData from " + peer);
        return null;
    }

    public Message onPreMessageReceived(Peer peer, Message message) {
        //Log.i(TAG, "onPreMessageReceived (" + message.getClass().getSimpleName() + ") from " + peer);
        return message;
    }
});
</code></pre>

<p>In my case, I created a BlockStore that stores the blocks in a SQLite3 database. When I get the complete block, I overwrite the block register with the complete information (transactions, raw block, etc...)</p>

CC BY-SA 3.0
2017-04-05T19:48:41.880Z
2017-04-05T19:54:17.873Z
2017-04-05T19:54:17.873Z
Ander Acosta
<p>In its default configuration, bitcoinj only downloads filtered blocks and keeps only those transactions that are relevant to the connected wallet(s).</p>

CC BY-SA 3.0
2017-04-05T09:01:58.357Z
Is there a way to change the default configuration to download all blocks fully?
Murch
CC BY-SA 3.0
2017-04-05T07:47:35.973Z
2017-04-05T07:47:35.973Z
Andreas
<p>I'm trying to get the raw blocks with bitcoinj. I use <code>Block.bitcoinSerialize()</code> to get the bytes of each block when it is downloaded, but does not include transactions. How can I get the full raw block?</p>

<block><bitcoinj><java><raw-data>
bitcoinj get raw block
Ander Acosta
# bitcoinj get raw block

(Asked by: username_0 on 2017-04-04)

I'm trying to get the raw blocks with bitcoinj. I use `Block.bitcoinSerialize()` to get the bytes of each block when it is downloaded, but does not include transactions. How can I get the full raw block?

**Tags:** block, bitcoinj, java, raw-data


---

## 2 answers

### Answer by username_0 on 2017-04-05. Score: 1 | Accepted answer

I have found a temporary solution:

```
BlockStore blockStore = new MyCustomBlockStore(NETWORK_PARAMETERS);
blockStore.getChainHead();

blockChain = new BlockChain(NETWORK_PARAMETERS, blockStore);

PeerGroup peerGroup = new PeerGroup(NETWORK_PARAMETERS, blockChain);
peerGroup.setDownloadTxDependencies(1000);
peerGroup.setBloomFilteringEnabled(false);
peerGroup.addPeerDiscovery(new PeerDiscovery() {
    private final PeerDiscovery normalPeerDiscovery = new DnsDiscovery(NETWORK_PARAMETERS);

    @Override
    public InetSocketAddress[] getPeers(long services, long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException {
        final List<InetSocketAddress> peers = new LinkedList<InetSocketAddress>();
            peers.addAll(Arrays.asList(normalPeerDiscovery.getPeers(services, timeoutValue, timeoutUnit)));
            InetSocketAddress[] isas = new InetSocketAddress[0];
            return peers.toArray(isas);
        }

    @Override
    public void shutdown() {
        normalPeerDiscovery.shutdown();
    }
});

peerGroup.startAsync();
peerGroup.startBlockChainDownload(new PeerDataEventListener() {
    public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int i) {

        List<Transaction> transactionsList = block.getTransactions();
        int transactions = transactionsList == null ? 0 : transactionsList.size();

        long height = peer.getBestHeight() - i;
        //If the block contains transactions, it is likely to be complete.
        Log.e(TAG, "Downloaded block " + height + " with " + transactions + " transactions");
        blockUpdate(block);
    }

    private void blockUpdate(Block fBlock) throws IOException {
        //TODO: Update blockchain database with the full block.
    }

    public void onChainDownloadStarted(Peer peer, int i) {
        Log.i(TAG, "Started to download chain on peer " + peer);
    }

    @Nullable
    public List<Message> getData(Peer peer, GetDataMessage getDataMessage) {
        //Log.i(TAG, "getData from " + peer);
        return null;
    }

    public Message onPreMessageReceived(Peer peer, Message message) {
        //Log.i(TAG, "onPreMessageReceived (" + message.getClass().getSimpleName() + ") from " + peer);
        return message;
    }
});

```

In my case, I created a BlockStore that stores the blocks in a SQLite3 database. When I get the complete block, I overwrite the block register with the complete information (transactions, raw block, etc...)


---

### Answer by username_1 on 2017-04-05. Score: 0

In its default configuration, bitcoinj only downloads filtered blocks and keeps only those transactions that are relevant to the connected wallet(s).

> **Comments:**
> **username_2**: Is there a way to change the default configuration to download all blocks fully?  

---

