Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
var Message = require('../message');
var inherits = require('util').inherits;
var bitcore = require('bitcore-lib-cash');
var BufferUtil = bitcore.util.buffer;
var $ = bitcore.util.preconditions;
var _ = bitcore.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,
'use strict';
var Message = require('../message');
var inherits = require('util').inherits;
var bitcore = require('bitcore-lib-cash');
var utils = require('../utils');
var BufferReader = bitcore.encoding.BufferReader;
var BufferWriter = bitcore.encoding.BufferWriter;
var _ = bitcore.deps._;
/**
* @param {Object|Array=} - options - If options is an array will use as "inventory"
* @param {Array=} options.inventory - An array of inventory items
* @extends Message
* @constructor
*/
function GetdataMessage(arg, options) {
Message.call(this, options);
this.command = 'getdata';
utils.checkInventory(arg);
this.inventory = arg;
}
inherits(GetdataMessage, Message);
GetdataMessage.prototype.setPayload = function(payload) {
'use strict';
var Message = require('../message');
var inherits = require('util').inherits;
var bitcore = require('bitcore-lib-cash');
var utils = require('../utils');
var $ = bitcore.util.preconditions;
var _ = bitcore.deps._;
var BufferUtil = bitcore.util.buffer;
var BufferReader = bitcore.encoding.BufferReader;
/**
* A message to confirm that a connection is still valid.
* @param {Number} arg - A nonce for the Ping message
* @param {Object=} options
* @extends Message
* @constructor
*/
function PingMessage(arg, options) {
Message.call(this, options);
this.command = 'ping';
$.checkArgument(
_.isUndefined(arg) || (BufferUtil.isBuffer(arg) && arg.length === 8),
'First argument is expected to be an 8 byte buffer'
'use strict';
var Message = require('../message');
var inherits = require('util').inherits;
var bitcore = require('bitcore-lib-cash');
var utils = require('../utils');
var BufferReader = bitcore.encoding.BufferReader;
var BufferWriter = bitcore.encoding.BufferWriter;
var _ = bitcore.deps._;
/**
* @param {Array} arg - An array of inventory
* @param {Object} options
* @param {Array=} options.inventory - An array of inventory items
* @extends Message
* @constructor
*/
function NotfoundMessage(arg, options) {
Message.call(this, options);
this.command = 'notfound';
utils.checkInventory(arg);
this.inventory = arg;
}
inherits(NotfoundMessage, Message);
'use strict';
var Message = require('../message');
var inherits = require('util').inherits;
var bitcore = require('bitcore-lib-cash');
var BufferUtil = bitcore.util.buffer;
var BloomFilter = require('../../bloomfilter');
var $ = bitcore.util.preconditions;
var _ = bitcore.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;
'use strict';
var Message = require('../message');
var inherits = require('util').inherits;
var bitcore = require('bitcore-lib-cash');
var utils = require('../utils');
var BufferReader = bitcore.encoding.BufferReader;
var BufferWriter = bitcore.encoding.BufferWriter;
var _ = bitcore.deps._;
/**
* @param {Array=} arg - An array of inventory
* @param {Object} options
* @param {Array=} options.inventory - An array of inventory items
* @extends Message
* @constructor
*/
function InvMessage(arg, options) {
Message.call(this, options);
this.command = 'inv';
utils.checkInventory(arg);
this.inventory = arg;
}
inherits(InvMessage, Message);
'use strict';
var bitcore = require('bitcore-lib-cash');
var BufferUtil = bitcore.util.buffer;
var $ = bitcore.util.preconditions;
var _ = bitcore.deps._;
var utils;
module.exports = utils = {
checkInventory: function(arg) {
$.checkArgument(
_.isUndefined(arg) ||
(Array.isArray(arg) && arg.length === 0) ||
(Array.isArray(arg) && !_.isUndefined(arg[0].type) && !_.isUndefined(arg[0].hash)),
'Argument is expected to be an array of inventory objects'
);
},
checkFinished: function checkFinished(parser) {
if(!parser.finished()) {
throw new Error('Data still available after parsing');
}
},
'use strict';
var Message = require('../message');
var inherits = require('util').inherits;
var bitcore = require('bitcore-lib-cash');
var $ = bitcore.util.preconditions;
var _ = bitcore.deps._;
/**
* @param {Transaction=} arg - An instance of Transaction
* @param {Object} options
* @extends Message
* @constructor
*/
function TransactionMessage(arg, options) {
Message.call(this, options);
this.command = 'tx';
this.Transaction = options.Transaction;
$.checkArgument(
_.isUndefined(arg) || arg instanceof this.Transaction,
'An instance of Transaction or undefined is expected'
);
this.transaction = arg;
'use strict';
var Message = require('../message');
var inherits = require('util').inherits;
var bitcore = require('bitcore-lib-cash');
var $ = bitcore.util.preconditions;
var _ = bitcore.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'
);
'use strict';
var Message = require('../message');
var inherits = require('util').inherits;
var bitcore = require('bitcore-lib-cash');
var utils = require('../utils');
var $ = bitcore.util.preconditions;
var _ = bitcore.deps._;
var BufferReader = bitcore.encoding.BufferReader;
var BufferWriter = bitcore.encoding.BufferWriter;
/**
* @param {Array=} arg - An array of addrs
* @param {Object=} options
* @extends Message
* @constructor
*/
function AddrMessage(arg, options) {
Message.call(this, options);
this.command = 'addr';
$.checkArgument(
_.isUndefined(arg) ||
(Array.isArray(arg) &&
!_.isUndefined(arg[0].services) &&