Bloom-filter

Hi,

I’m trying this code:

var Pool = require('bitcore-p2p').Pool;
var BloomFilter = require('bitcore-p2p').BloomFilter;
var Networks = require('bitcore-lib').Networks;
var Messages = require('bitcore-p2p').Messages;

var pool = new Pool({network: Networks.livenet});
pool.connect();

var code = new Buffer('1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC','base64');
var filter = BloomFilter.create(1, 0.1);
filter.insert(code);

var messages = new Messages();
var lessRecent = messages.GetData.forBlock('000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e');
var messageFilter = messages.FilterLoad(filter);

pool.on('peerblock', function(peer, message) {
last = message;
});

then I call:

pool.sendMessage(messageFilter);
pool.sendMessage(lessRecent);

LessRecent is a request for a block that is supposed to be blocked by the filter, but seems that the peers disregard my request for load the filter.

You may need to use peermerkleblock instead. You should also notice a decrease in the number of tx inv messages once the filter is loaded.

Ok, thanks.

I have changed getData.forBlock() with getData.forFilteredBlock() and I listen for peermerkleblock.

Now it seem that work.
When I have the merkleBlock how can I do for check if the merkleBlock contain a tx that match my filter?

There is a hasTransaction method on merkleBlock: https://github.com/bitpay/bitcore-lib/blob/master/lib/block/merkleblock.js#L224