fcash-p2p
Version:
Interface to the bitcoin P2P network for fcash
42 lines (36 loc) • 1.07 kB
JavaScript
;
var Message = require('../message');
var inherits = require('util').inherits;
var fcash = require('fcash-lib');
var BufferUtil = fcash.util.buffer;
var BloomFilter = require('../../bloomfilter');
var $ = fcash.util.preconditions;
var _ = fcash.deps._;
/**
* Request peer to send inv messages based on a bloom filter
* @param {BloomFilter=} arg - An instance of BloomFilter
* @param {Object} options
* @extends Message
* @constructor
*/
function FilterloadMessage(arg, options) {
Message.call(this, options);
this.command = 'filterload';
$.checkArgument(
_.isUndefined(arg) || arg instanceof BloomFilter,
'An instance of BloomFilter or undefined is expected'
);
this.filter = arg;
}
inherits(FilterloadMessage, Message);
FilterloadMessage.prototype.setPayload = function(payload) {
this.filter = BloomFilter.fromBuffer(payload);
};
FilterloadMessage.prototype.getPayload = function() {
if(this.filter) {
return this.filter.toBuffer();
} else {
return BufferUtil.EMPTY_BUFFER;
}
};
module.exports = FilterloadMessage;