Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bitcore-common-blockchain

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitcore-common-blockchain - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

README.md

400

index.js

@@ -1,18 +0,14 @@

'use strict';
'use strict'
var inherits = require('util').inherits;
var async = require('async');
var inherits = require('util').inherits
var async = require('async')
var bodyParser = require('body-parser')
var cbRouter = require('cb-express-router')
var bitcore = require('bitcore-lib')
var BaseService = require('./service')
var bitcore = require('bitcore-lib');
var BaseService = require('./service');
var Transaction = bitcore.Transaction
var JSUtil = bitcore.util.js
var $ = bitcore.util.preconditions
var Transaction = bitcore.Transaction;
var JSUtil = bitcore.util.js;
var $ = bitcore.util.preconditions;
/**

@@ -25,35 +21,33 @@ * This service exposes a common-blockchain (https://github.com/common-blockchain/common-blockchain) interface

var CommonBlockchainService = function (options) {
var self = this;
var self = this
BaseService.call(self, options);
BaseService.call(self, options)
self.addresses = new Addresses ({ parent: self });
self.transactions = new Transactions ({ parent: self });
self.blocks = new Blocks ({ parent: self });
};
self.addresses = new Addresses({ parent: self })
self.transactions = new Transactions({ parent: self })
self.blocks = new Blocks({ parent: self })
}
inherits(CommonBlockchainService, BaseService);
inherits(CommonBlockchainService, BaseService)
CommonBlockchainService.dependencies = [ 'address', 'db', 'bitcoind' ];
CommonBlockchainService.dependencies = [ 'address', 'db', 'bitcoind' ]
CommonBlockchainService.prototype.getAPIMethods = function () {
return [
[ 'addresses#summary', this, this.addresses.summary, 1 ],
[ 'addresses#transactions', this, this.addresses.transactions, 2 ],
[ 'addresses#unspents', this, this.addresses.unspents, 1 ],
[ 'addresses#summary', this, this.addresses.summary, 1 ],
[ 'addresses#transactions', this, this.addresses.transactions, 2 ],
[ 'addresses#unspents', this, this.addresses.unspents, 1 ],
[ 'transactions#get', this, this.transactions.get, 1 ],
[ 'transactions#summary', this, this.transactions.summary, 1 ],
[ 'transactions#unconfirmed', this, this.transactions.unconfirmed, 0 ],
[ 'transactions#propagate', this, this.transactions.propagate, 1 ],
[ 'transactions#get', this, this.transactions.get, 1 ],
[ 'transactions#summary', this, this.transactions.summary, 1 ],
// [ 'transactions#unconfirmed', this, this.transactions.unconfirmed, 0 ],
[ 'transactions#propagate', this, this.transactions.propagate, 1 ],
[ 'blocks#get', this, this.blocks.get, 1 ],
[ 'blocks#summary', this, this.blocks.summary, 1 ],
[ 'blocks#latest', this, this.blocks.latest, 1 ],
[ 'blocks#propagate', this, this.blocks.propagate, 1 ]
[ 'blocks#get', this, this.blocks.get, 1 ],
[ 'blocks#summary', this, this.blocks.summary, 1 ],
// [ 'blocks#latest', this, this.blocks.latest, 1 ],
// [ 'blocks#propagate', this, this.blocks.propagate, 1 ]
]
};
}
/**

@@ -66,47 +60,42 @@ * Exposes all the hooks as web-hooks

CommonBlockchainService.prototype.setupRoutes = function (app, express) {
var self = this;
var self = this
var bodyParser = require('body-parser');
app.use(bodyParser.json()); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
app.use(bodyParser.json()); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
}))
app.use(cbRouter(this));
app.use(cbRouter(this))
function extractAddresses(addrs) {
if (!addrs) return null;
function extractAddresses (addrs) {
if (!addrs) return null
return addrs.split(',').filter(function (addr) {
return bitcore.Address.isValid(addr);
});
return bitcore.Address.isValid(addr)
})
}
function extractHexs(txIds) {
if (!txIds) return null;
function extractHexs (txIds) {
if (!txIds) return null
return txIds.split(',').filter(function (txId) {
return JSUtil.isHexa(txId);
});
return JSUtil.isHexa(txId)
})
}
};
}
CommonBlockchainService.prototype.getRoutePrefix = function () {
return 'cb';
};
return 'cb'
}
function CommonBlockchainMicroService(options) {
this.parent = options.parent;
function CommonBlockchainMicroService (options) {
this.parent = options.parent
}
function Addresses(options) {
function Addresses (options) {
CommonBlockchainMicroService.call(this, options)
}
inherits(Addresses, CommonBlockchainMicroService);
inherits(Addresses, CommonBlockchainMicroService)
/**

@@ -119,27 +108,22 @@ * Gets summary for the address supplied

Addresses.prototype.summary = function (addresses, callback) {
// TODO: Replace with `typeforce`
$.checkArgument(Array.isArray(addresses), 'Must provide an array of addresses!');
$.checkArgument(Array.isArray(addresses), 'Must provide an array of addresses!')
var self = this;
var self = this
async.map(
addresses,
function (addr, callback) {
function (addr, reduce) {
self.parent.node.services.address.getAddressSummary(addr, { noTxList: true }, function (err, result) {
if (!err) {
callback(err, {
address: addr,
balance: result['balance'],
totalReceived: result['totalReceived'],
txCount: result['appearances']
})
} else {
callback(err, result);
}
reduce(err, !err && {
address: addr,
balance: result['balance'],
totalReceived: result['totalReceived'],
txCount: result['appearances']
})
})
},
callback
);
};
)
}

@@ -154,36 +138,30 @@ /**

Addresses.prototype.transactions = function (addresses, blockHeight, callback) {
// TODO: Replace with `typeforce`
$.checkArgument(Array.isArray(addresses), 'Must provide an array of addresses!');
$.checkArgument(Array.isArray(addresses), 'Must provide an array of addresses!')
var self = this;
var self = this
var options = {
start: Transaction.NLOCKTIME_MAX_VALUE,
end: blockHeight || 0,
start: Transaction.NLOCKTIME_MAX_VALUE,
end: blockHeight || 0,
queryMempool: false
};
}
self.parent.node.services.address.getAddressHistory(addresses, options, function (err, result) {
if (!err) {
async.map(
result['items'] || [], function (item, reduce) {
var tx = item.tx;
if (err) return callback(err)
reduce(null, {
blockHeight: item.height,
blockId: tx.blockHash,
txId: tx.id,
txHex: tx.serialize(/* unsafe = */ true)
});
},
callback
);
} else {
callback(err, result);
}
result = (result.items || []).map(function (item) {
var tx = item.tx
return {
blockHeight: item.height,
blockId: tx.blockHash,
txId: tx.id,
txHex: tx.serialize( /* unsafe = */ true)
}
})
callback(null, result)
})
};
}
/**

@@ -196,34 +174,29 @@ * Gets unspents outputs for the addresses supplied

Addresses.prototype.unspents = function (addresses, callback) {
// TODO: Replace with `typeforce`
$.checkArgument(Array.isArray(addresses), 'Must provide an array of addresses!');
$.checkArgument(Array.isArray(addresses), 'Must provide an array of addresses!')
var self = this;
var self = this
self.parent.node.services.address.getUnspentOutputs(addresses, /* queryMempool = */ false, function (err, result) {
if (!err) {
async.map(
result || [], function (unspent, reduce) {
reduce(err, {
address: unspent.address,
txId: unspent.txid,
confirmations: unspent.confirmations,
value: unspent.satoshis,
vout: unspent.outputIndex
})
},
callback
);
} else {
callback(err, result);
}
if (err) return callback(err)
result = (result || []).map(function (unspent) {
return {
address: unspent.address,
txId: unspent.txid,
confirmations: unspent.confirmations,
value: unspent.satoshis,
vout: unspent.outputIndex
}
})
callback(null, result)
})
};
}
function Transactions(options) {
function Transactions (options) {
CommonBlockchainMicroService.call(this, options)
}
inherits(Transactions, CommonBlockchainMicroService);
inherits(Transactions, CommonBlockchainMicroService)

@@ -237,7 +210,6 @@ /**

Transactions.prototype.get = function (txids, callback) {
// TODO: Replace with `typeforce`
$.checkArgument(Array.isArray(txids), 'Must provide an array of tx-ids!');
$.checkArgument(Array.isArray(txids), 'Must provide an array of tx-ids!')
var self = this;
var self = this

@@ -248,19 +220,14 @@ async.map(

self.parent.node.services.db.getTransactionWithBlockInfo(txid, /* queryMempool = */ false, function (err, tx) {
if (!err) {
reduce(err, {
txId: tx.hash,
blockId: tx.__blockHash,
blockHeight: tx.__height,
txHex: tx.serialize(/* unsafe= */ true)
});
} else {
reduce(err, tx);
}
reduce(err, !err && {
txId: tx.hash,
blockId: tx.__blockHash,
blockHeight: tx.__height,
txHex: tx.serialize( /* unsafe= */ true)
})
})
},
callback
);
};
)
}
/**

@@ -273,7 +240,6 @@ * Gets transactions' summaries

Transactions.prototype.summary = function (txids, callback) {
// TODO: Replace with `typeforce`
$.checkArgument(Array.isArray(txids), 'Must provide an array of tx-ids!');
$.checkArgument(Array.isArray(txids), 'Must provide an array of tx-ids!')
var self = this;
var self = this

@@ -284,23 +250,17 @@ async.map(

self.parent.node.services.db.getTransactionWithBlockInfo(txid, /* queryMempool = */ false, function (err, tx) {
if (!err) {
if (err) return reduce(err)
var tx0 = undefined;
try {
tx0 = {
txId: txid,
blockId: tx.__blockHash,
blockHeight: tx.__height,
// nInputs: tx.inputs.length,
// nOutputs: tx.outputs.length,
// totalInputValue: tx.inputAmount,
// totalOutputValue: tx.outputAmount
};
} catch (e) {
reduce(e)
}
if (tx0)
reduce(err, tx0);
} else {
reduce(err, tx);
try {
reduce(null, {
txId: txid,
blockId: tx.__blockHash,
blockHeight: tx.__height,
// TODO:
// nInputs: tx.inputs.length,
// nOutputs: tx.outputs.length,
// totalInputValue: tx.inputAmount,
// totalOutputValue: tx.outputAmount
})
} catch (e) {
return reduce(e)
}

@@ -310,6 +270,5 @@ })

callback
);
};
)
}
/**

@@ -320,7 +279,6 @@ * Returns the latest unconfirmed transactions (subjective to the node)

*/
Transactions.prototype.unconfirmed = function (callback) {
throw "NotImplementedException";
};
// Transactions.prototype.unconfirmed = function (callback) {
// throw new Error('NotImplementedException')
// }
/**

@@ -333,7 +291,6 @@ * Propagates supplied transactions (in bitcoin-protocol format) to the blockchain

Transactions.prototype.propagate = function (txs, callback) {
// TODO: Replace with `typeforce`
$.checkArgument(Array.isArray(txs), 'Must provide an object from where to extract data');
$.checkArgument(Array.isArray(txs), 'Must provide an object from where to extract data')
var self = this;
var self = this

@@ -346,7 +303,6 @@ async.map(

callback
);
};
)
}
function Blocks(options) {
function Blocks (options) {
CommonBlockchainMicroService.call(this, options)

@@ -364,7 +320,6 @@ }

Blocks.prototype.get = function (hashes, callback) {
// TODO: Replace with `typeforce`
$.checkArgument(Array.isArray(hashes), 'Must provide an array of block-hashes!');
$.checkArgument(Array.isArray(hashes), 'Must provide an array of block-hashes!')
var self = this;
var self = this

@@ -375,17 +330,12 @@ async.map(

self.parent.node.services.db.getBlock(hash, function (err, block) {
if (!err) {
reduce(err, {
blockId: block.id,
blockHex: block.toString()
});
} else {
reduce(err, block);
}
reduce(err, !err && {
blockId: block.id,
blockHex: block.toString()
})
})
},
callback
);
};
)
}
/**

@@ -398,7 +348,6 @@ * Gets blocks' summaries

Blocks.prototype.summary = function (hashes, callback) {
// TODO: Replace with `typeforce`
$.checkArgument(Array.isArray(hashes), 'Must provide an array of block-hashes!');
$.checkArgument(Array.isArray(hashes), 'Must provide an array of block-hashes!')
var self = this;
var self = this

@@ -409,27 +358,24 @@ async.map(

self.parent.node.services.db.getBlock(hash, function (err, block) {
if (!err) {
var blockIndex = self.parent.node.services.bitcoind.getBlockIndex(hash);
var blockSize = block.toString().length;
if (err) return reduce(err)
reduce(err, {
blockId: block.id,
prevBlockId: block.header.prevHash.toString('hex'),
merkleRootHash: block.header.merkleRoot.toString('hex'),
nonce: block.header.nonce,
version: block.header.version,
blockHeight: blockIndex.height,
blockSize: blockSize,
timestamp: block.header.timestamp,
txCount: block.transactions.length
});
} else {
reduce(err, block);
}
var blockIndex = self.parent.node.services.bitcoind.getBlockIndex(hash)
var blockSize = block.toString().length
reduce(null, {
blockId: block.id,
prevBlockId: block.header.prevHash.toString('hex'),
merkleRootHash: block.header.merkleRoot.toString('hex'),
nonce: block.header.nonce,
version: block.header.version,
blockHeight: blockIndex.height,
blockSize: blockSize,
timestamp: block.header.timestamp,
txCount: block.transactions.length
})
})
},
callback
);
};
)
}
/**

@@ -440,7 +386,6 @@ * Returns the latest unconfirmed transactions (subjective to the node)

*/
Blocks.prototype.latest = function (callback) {
throw "NotImplementedException";
};
// Blocks.prototype.latest = function (callback) {
// throw new Error('NotImplementedException')
// }
/**

@@ -452,13 +397,12 @@ * Propagates supplied transactions (in bitcoin-protocol format) to the blockchain

*/
Blocks.prototype.propagate = function (block, callback) {
throw "NotImplementedException";
};
// Blocks.prototype.propagate = function (block, callback) {
// throw new Error('NotImplementedException')
// }
/**
* Function which is called when module is first initialized
*/
CommonBlockchainService.prototype.start = function(done) {
setImmediate(done);
};
CommonBlockchainService.prototype.start = function (done) {
setImmediate(done)
}

@@ -468,6 +412,6 @@ /**

*/
CommonBlockchainService.prototype.stop = function(done) {
setImmediate(done);
};
CommonBlockchainService.prototype.stop = function (done) {
setImmediate(done)
}
module.exports = CommonBlockchainService;
module.exports = CommonBlockchainService
{
"name": "bitcore-common-blockchain",
"version": "1.0.1",
"version": "1.0.2",
"description": "common blockchain service for bitcore-node",

@@ -18,4 +18,5 @@ "main": "index.js",

"bitcore-lib": "^0.13.15",
"body-parser": "^1.15.0",
"cb-express-router": "common-blockchain/cb-express-router"
}
}

@@ -1,14 +0,14 @@

'use strict';
'use strict'
var util = require('util');
var EventEmitter = require('events').EventEmitter;
var util = require('util')
var EventEmitter = require('events').EventEmitter
var Service = function(options) {
EventEmitter.call(this);
var Service = function (options) {
EventEmitter.call(this)
this.node = options.node;
this.name = options.name;
};
this.node = options.node
this.name = options.name
}
util.inherits(Service, EventEmitter);
util.inherits(Service, EventEmitter)

@@ -18,3 +18,3 @@ /**

*/
Service.dependencies = [];
Service.dependencies = []

@@ -27,8 +27,8 @@ /**

*/
Service.prototype.blockHandler = function(block, add, callback) {
Service.prototype.blockHandler = function (block, add, callback) {
// implement in the child class
setImmediate(function() {
callback(null, []);
});
};
setImmediate(function () {
callback(null, [])
})
}

@@ -39,9 +39,9 @@ /**

*/
Service.prototype.getPublishEvents = function() {
Service.prototype.getPublishEvents = function () {
// Example:
// return [
// ['eventname', this, this.subscribeEvent, this.unsubscribeEvent],
// ];
return [];
};
// ]
return []
}

@@ -52,10 +52,10 @@ /**

*/
Service.prototype.getAPIMethods = function() {
Service.prototype.getAPIMethods = function () {
// Example:
// return [
// ['getData', this, this.getData, 1]
// ];
// ]
return [];
};
return []
}

@@ -65,3 +65,3 @@ // Example:

//
// };
// }

@@ -71,5 +71,5 @@ /**

*/
Service.prototype.start = function(done) {
setImmediate(done);
};
Service.prototype.start = function (done) {
setImmediate(done)
}

@@ -79,5 +79,5 @@ /**

*/
Service.prototype.stop = function(done) {
setImmediate(done);
};
Service.prototype.stop = function (done) {
setImmediate(done)
}

@@ -88,12 +88,10 @@ /**

*/
Service.prototype.setupRoutes = function(app) {
Service.prototype.setupRoutes = function (app) {
// Setup express routes here
};
}
Service.prototype.getRoutePrefix = function() {
return this.name;
};
Service.prototype.getRoutePrefix = function () {
return this.name
}
module.exports = Service;
module.exports = Service

@@ -13,9 +13,7 @@ 'use strict'

var Networks = bitcoreLib.Networks
var Block = bitcoreLib.Block
var Networks = bitcoreLib.Networks
var Block = bitcoreLib.Block
var Transaction = bitcoreLib.Transaction
describe('Common Blockchain Interface', function () {
var node = {

@@ -25,4 +23,4 @@ datadir: 'testdir',

services: {
address: {},
db: {},
address: {},
db: {},
bitcoind: {}

@@ -33,3 +31,2 @@ }

describe('@constructor', function () {
// TODO

@@ -41,7 +38,7 @@

var summary = {
totalReceived: 3487110,
totalSpent: 0,
balance: 3487110,
totalReceived: 3487110,
totalSpent: 0,
balance: 3487110,
unconfirmedBalance: 0,
appearances: 1,
appearances: 1,
unconfirmedAppearances: 1,

@@ -58,10 +55,10 @@ txids: [

it('should return summary for the address', function(done) {
cbs.addresses.summary([ 'mpkDdnLq26djg17s6cYknjnysAm3QwRzu2' ], function(err, summary) {
it('should return summary for the address', function (done) {
cbs.addresses.summary([ 'mpkDdnLq26djg17s6cYknjnysAm3QwRzu2' ], function (err, summary) {
should.not.exist(err)
summary[0].address .should.equal('mpkDdnLq26djg17s6cYknjnysAm3QwRzu2')
summary[0].balance .should.equal(3487110)
summary[0].totalReceived .should.equal(3487110)
summary[0].txCount .should.equal(1)
summary[0].address.should.equal('mpkDdnLq26djg17s6cYknjnysAm3QwRzu2')
summary[0].balance.should.equal(3487110)
summary[0].totalReceived.should.equal(3487110)
summary[0].txCount.should.equal(1)

@@ -71,6 +68,4 @@ done()

})
})
describe('#addresses.transactions', function () {

@@ -101,10 +96,10 @@ var history = {

it('should return history for all transactions for the addresses', function(done) {
cbs.addresses.transactions([ 'mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW' ], null, function(err, txs) {
it('should return history for all transactions for the addresses', function (done) {
cbs.addresses.transactions([ 'mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW' ], null, function (err, txs) {
should.not.exist(err)
txs[0].txId .should.equal('47a34f835395b7e01e2ee757a301476e2c3f5f6a9245e655a1842f6db2368a58')
txs[0].txHex .should.equal(transactionData[1].hex)
txs[0].blockHeight .should.equal(150)
//txs[0].blockId .should.equal(3487110)
txs[0].txId.should.equal('47a34f835395b7e01e2ee757a301476e2c3f5f6a9245e655a1842f6db2368a58')
txs[0].txHex.should.equal(transactionData[1].hex)
txs[0].blockHeight.should.equal(150)
// txs[0].blockId .should.equal(3487110)

@@ -114,6 +109,4 @@ done()

})
})
describe('#addresses.unspents', function () {

@@ -136,11 +129,11 @@ var unspentOuts = [

it('should return history for all transactions for the addresses', function(done) {
cbs.addresses.unspents([ 'mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW' ], function(err, txs) {
it('should return history for all transactions for the addresses', function (done) {
cbs.addresses.unspents([ 'mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW' ], function (err, txs) {
should.not.exist(err)
txs[0].txId .should.equal('9d956c5d324a1c2b12133f3242deff264a9b9f61be701311373998681b8c1769')
txs[0].address .should.equal('mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW')
txs[0].confirmations .should.equal(3)
txs[0].value .should.equal(1000000000)
txs[0].vout .should.equal(1)
txs[0].txId.should.equal('9d956c5d324a1c2b12133f3242deff264a9b9f61be701311373998681b8c1769')
txs[0].address.should.equal('mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW')
txs[0].confirmations.should.equal(3)
txs[0].value.should.equal(1000000000)
txs[0].vout.should.equal(1)

@@ -150,3 +143,2 @@ done()

})
})

@@ -169,11 +161,11 @@

it('should return history for all transactions for the addresses', function(done) {
it('should return history for all transactions for the addresses', function (done) {
node.services.db.getTransactionWithBlockInfo = sinon.stub().callsArgWith(2, null, tx)
cbs.transactions.get([ txId ], function(err, txs) {
cbs.transactions.get([ txId ], function (err, txs) {
should.not.exist(err)
txs[0].txId .should.equal(txId)
txs[0].txHex .should.equal(txHex)
txs[0].blockId .should.equal('00000000000000001bb82a7f5973618cfd3185ba1ded04dd852a653f92a27c45')
txs[0].blockHeight .should.equal(314159)
txs[0].txId.should.equal(txId)
txs[0].txHex.should.equal(txHex)
txs[0].blockId.should.equal('00000000000000001bb82a7f5973618cfd3185ba1ded04dd852a653f92a27c45')
txs[0].blockHeight.should.equal(314159)

@@ -183,7 +175,6 @@ done()

})
})
describe('#transactions.summary', function () {
var txBuffer = new Buffer('01000000016f95980911e01c2c664b3e78299527a47933aac61a515930a8fe0213d1ac9abe01000000da0047304402200e71cda1f71e087c018759ba3427eb968a9ea0b1decd24147f91544629b17b4f0220555ee111ed0fc0f751ffebf097bdf40da0154466eb044e72b6b3dcd5f06807fa01483045022100c86d6c8b417bff6cc3bbf4854c16bba0aaca957e8f73e19f37216e2b06bb7bf802205a37be2f57a83a1b5a8cc511dc61466c11e9ba053c363302e7b99674be6a49fc0147522102632178d046673c9729d828cfee388e121f497707f810c131e0d3fc0fe0bd66d62103a0951ec7d3a9da9de171617026442fcd30f34d66100fab539853b43f508787d452aeffffffff0240420f000000000017a9148a31d53a448c18996e81ce67811e5fb7da21e4468738c9d6f90000000017a9148ce5408cfeaddb7ccb2545ded41ef478109454848700000000', 'hex');
var txBuffer = new Buffer('01000000016f95980911e01c2c664b3e78299527a47933aac61a515930a8fe0213d1ac9abe01000000da0047304402200e71cda1f71e087c018759ba3427eb968a9ea0b1decd24147f91544629b17b4f0220555ee111ed0fc0f751ffebf097bdf40da0154466eb044e72b6b3dcd5f06807fa01483045022100c86d6c8b417bff6cc3bbf4854c16bba0aaca957e8f73e19f37216e2b06bb7bf802205a37be2f57a83a1b5a8cc511dc61466c11e9ba053c363302e7b99674be6a49fc0147522102632178d046673c9729d828cfee388e121f497707f810c131e0d3fc0fe0bd66d62103a0951ec7d3a9da9de171617026442fcd30f34d66100fab539853b43f508787d452aeffffffff0240420f000000000017a9148a31d53a448c18996e81ce67811e5fb7da21e4468738c9d6f90000000017a9148ce5408cfeaddb7ccb2545ded41ef478109454848700000000', 'hex')
var tx = new Transaction().fromBuffer(txBuffer)

@@ -197,10 +188,10 @@ tx.__blockHash = '00000000000ec715852ea2ecae4dc8563f62d603c820f81ac284cd5be0a944d6'

it('should return history for all transactions for the addresses', function(done) {
it('should return history for all transactions for the addresses', function (done) {
node.services.db.getTransactionWithBlockInfo = sinon.stub().callsArgWith(2, null, tx)
cbs.transactions.summary([ txId ], function(err, txs) {
cbs.transactions.summary([ txId ], function (err, txs) {
should.not.exist(err)
txs[0].txId .should.equal(txId)
txs[0].blockId .should.equal('00000000000ec715852ea2ecae4dc8563f62d603c820f81ac284cd5be0a944d6')
txs[0].blockHeight .should.equal(530482)
txs[0].txId.should.equal(txId)
txs[0].blockId.should.equal('00000000000ec715852ea2ecae4dc8563f62d603c820f81ac284cd5be0a944d6')
txs[0].blockHeight.should.equal(530482)
// txs[0].nInputs .should.equal(0)

@@ -214,6 +205,4 @@ // txs[0].nOutputs .should.equal(0)

})
})
describe('#blocks.get', function () {

@@ -226,9 +215,9 @@ var blockBuffer = new Buffer(blockData, 'hex')

it('should return history for all transactions for the addresses', function(done) {
it('should return history for all transactions for the addresses', function (done) {
node.services.db.getBlock = sinon.stub().callsArgWith(1, null, block)
cbs.blocks.get([ '00000000000000000593b60d8b4f40fd1ec080bdb0817d475dae47b5f5b1f735' ], function(err, blocks) {
cbs.blocks.get([ '00000000000000000593b60d8b4f40fd1ec080bdb0817d475dae47b5f5b1f735' ], function (err, blocks) {
should.not.exist(err)
blocks[0].blockId .should.equal('00000000000000000593b60d8b4f40fd1ec080bdb0817d475dae47b5f5b1f735')
blocks[0].blockHex .should.equal(blockData)
blocks[0].blockId.should.equal('00000000000000000593b60d8b4f40fd1ec080bdb0817d475dae47b5f5b1f735')
blocks[0].blockHex.should.equal(blockData)

@@ -238,6 +227,4 @@ done()

})
})
describe('#blocks.summary', function () {

@@ -252,18 +239,18 @@ var blockBuffer = new Buffer(blockData, 'hex')

it('should return history for all transactions for the addresses', function(done) {
node.services.db.getBlock = sinon.stub().callsArgWith(1, null, block)
node.services.bitcoind.getBlockIndex = sinon.stub().returns(blockIndex)
it('should return history for all transactions for the addresses', function (done) {
node.services.db.getBlock = sinon.stub().callsArgWith(1, null, block)
node.services.bitcoind.getBlockIndex = sinon.stub().returns(blockIndex)
cbs.blocks.summary([ '00000000000000000593b60d8b4f40fd1ec080bdb0817d475dae47b5f5b1f735' ], function(err, bs) {
cbs.blocks.summary([ '00000000000000000593b60d8b4f40fd1ec080bdb0817d475dae47b5f5b1f735' ], function (err, bs) {
should.not.exist(err)
bs[0].blockId .should.equal('00000000000000000593b60d8b4f40fd1ec080bdb0817d475dae47b5f5b1f735')
bs[0].prevBlockId .should.equal('25c31a5ecbbdc9509e1ddf3330d0e08619213fec75d040170000000000000000')
bs[0].merkleRootHash .should.equal('569070567854dd4cc9f6b82c6f5ba115e38b05f073575f983c471aab487f61dc')
bs[0].nonce .should.equal(1970979152)
bs[0].version .should.equal(2)
bs[0].blockHeight .should.equal(10)
bs[0].blockSize .should.equal(232714)
bs[0].timestamp .should.equal(1424818934)
bs[0].txCount .should.equal(182)
bs[0].blockId.should.equal('00000000000000000593b60d8b4f40fd1ec080bdb0817d475dae47b5f5b1f735')
bs[0].prevBlockId.should.equal('25c31a5ecbbdc9509e1ddf3330d0e08619213fec75d040170000000000000000')
bs[0].merkleRootHash.should.equal('569070567854dd4cc9f6b82c6f5ba115e38b05f073575f983c471aab487f61dc')
bs[0].nonce.should.equal(1970979152)
bs[0].version.should.equal(2)
bs[0].blockHeight.should.equal(10)
bs[0].blockSize.should.equal(232714)
bs[0].timestamp.should.equal(1424818934)
bs[0].txCount.should.equal(182)

@@ -273,5 +260,3 @@ done()

})
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc