UNPKG

@dashevo/dashcore-p2p

Version:

Interface to the dash P2P network for Dashcore

41 lines (35 loc) 1.27 kB
'use strict'; var Message = require('../message'); var inherits = require('util').inherits; var dashcore = require('@dashevo/dashcore-lib'); var BufferUtil = dashcore.util.buffer; var $ = dashcore.util.preconditions; var _ = dashcore.deps._; /** * Contains information about a MerkleBlock * @see https://en.bitcoin.it/wiki/Protocol_documentation * @param {MerkleBlock} arg - An instance of MerkleBlock * @param {Object=} options * @param {Function} options.MerkleBlock - a MerkleBlock constructor * @extends Message * @constructor */ function MerkleblockMessage(arg, options) { Message.call(this, options); this.MerkleBlock = options.MerkleBlock; // constructor this.command = 'merkleblock'; $.checkArgument( _.isUndefined(arg) || arg instanceof this.MerkleBlock, 'An instance of MerkleBlock or undefined is expected' ); this.merkleBlock = arg; } inherits(MerkleblockMessage, Message); MerkleblockMessage.prototype.setPayload = function(payload) { $.checkArgument(BufferUtil.isBuffer(payload)); this.merkleBlock = this.MerkleBlock.fromBuffer(payload); }; MerkleblockMessage.prototype.getPayload = function() { return this.merkleBlock ? this.merkleBlock.toBuffer() : BufferUtil.EMPTY_BUFFER; }; module.exports = MerkleblockMessage;