@axerunners/axecore-p2p
Version:
Interface to the axe P2P network for Axecore
37 lines (31 loc) • 913 B
JavaScript
;
var Message = require('../message');
var inherits = require('util').inherits;
var axecore = require('@axerunners/axecore-lib');
var $ = axecore.util.preconditions;
var _ = axecore.deps._;
/**
* @param {Block=} arg - An instance of a Block
* @param {Object} options
* @param {Function} options.Block - A block constructor
* @extends Message
* @constructor
*/
function BlockMessage(arg, options) {
Message.call(this, options);
this.Block = options.Block;
this.command = 'block';
$.checkArgument(
_.isUndefined(arg) || arg instanceof this.Block,
'An instance of Block or undefined is expected'
);
this.block = arg;
}
inherits(BlockMessage, Message);
BlockMessage.prototype.setPayload = function(payload) {
this.block = this.Block.fromBuffer(payload);
};
BlockMessage.prototype.getPayload = function() {
return this.block.toBuffer();
};
module.exports = BlockMessage;