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.1.0 to 2.0.0

test/data/livenet-301321.json

148

index.js

@@ -27,2 +27,3 @@ 'use strict'

self.bitcoind = this.node.services.bitcoind
self.addresses = new Addresses({ parent: self })

@@ -35,3 +36,3 @@ self.transactions = new Transactions({ parent: self })

CommonBlockchainService.dependencies = [ 'address', 'db', 'bitcoind' ]
CommonBlockchainService.dependencies = [ 'bitcoind' ]

@@ -51,3 +52,3 @@ CommonBlockchainService.prototype.getAPIMethods = function () {

[ 'blocks#summary', this, this.blocks.summary, 1 ],
// [ 'blocks#latest', this, this.blocks.latest, 1 ],
[ 'blocks#latest', this, this.blocks.latest, 1 ],
// [ 'blocks#propagate', this, this.blocks.propagate, 1 ]

@@ -71,3 +72,3 @@ ]

app.use(cbRouter(this))
app.use(cbRouter(this, { validateResponse: false }))

@@ -98,2 +99,3 @@ function extractAddresses (addrs) {

this.parent = options.parent
this.bitcoind = this.parent.bitcoind
}

@@ -116,3 +118,2 @@

Addresses.prototype.summary = function (addresses, callback) {
// TODO: Replace with `typeforce`
$.checkArgument(Array.isArray(addresses), 'Must provide an array of addresses!')

@@ -125,3 +126,3 @@

function (addr, reduce) {
self.parent.node.services.address.getAddressSummary(addr, { noTxList: true }, function (err, result) {
self.bitcoind.getAddressSummary(addr, { noTxList: true }, function (err, result) {
reduce(err, !err && {

@@ -147,3 +148,2 @@ address: addr,

Addresses.prototype.transactions = function (addresses, blockHeight, callback) {
// TODO: Replace with `typeforce`
$.checkArgument(Array.isArray(addresses), 'Must provide an array of addresses!')

@@ -154,3 +154,3 @@

var options = {
start: Transaction.NLOCKTIME_MAX_VALUE,
start: Transaction.NLOCKTIME_BLOCKHEIGHT_LIMIT,
end: blockHeight || 0,

@@ -160,3 +160,3 @@ queryMempool: true

self.parent.node.services.address.getAddressHistory(addresses, options, function (err, result) {
self.bitcoind.getAddressHistory(addresses, options, function (err, result) {
if (err) return callback(err)

@@ -167,6 +167,7 @@

return {
blockHeight: item.height,
blockId: tx.blockHash,
txId: tx.id,
txHex: tx.serialize( /* unsafe = */ true)
blockHeight: tx.height || item.height,
blockId: tx.blockHash || item.blockHash,
txId: tx.hash,
// txId: reverseHex(tx.hash),
txHex: tx.hex || tx.serialize(true /* unsafe */)
}

@@ -186,3 +187,2 @@ })

Addresses.prototype.unspents = function (addresses, callback) {
// TODO: Replace with `typeforce`
$.checkArgument(Array.isArray(addresses), 'Must provide an array of addresses!')

@@ -192,5 +192,6 @@

self.parent.node.services.address.getUnspentOutputs(addresses, /* queryMempool = */ true, function (err, result) {
self.bitcoind.getAddressUnspentOutputs(addresses, /* queryMempool = */ true, function (err, result) {
if (err) return callback(err)
var chainHeight = self.bitcoind.height
result = (result || []).map(function (unspent) {

@@ -200,3 +201,3 @@ return {

txId: unspent.txid,
confirmations: unspent.confirmations,
confirmations: chainHeight - (unspent.height || chainHeight),
value: unspent.satoshis,

@@ -224,3 +225,2 @@ vout: unspent.outputIndex

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

@@ -233,3 +233,3 @@

function (txid, reduce) {
self.parent.node.services.db.getTransactionWithBlockInfo(txid, /* queryMempool = */ true, function (err, tx) {
self.bitcoind.getDetailedTransaction(txid, /* queryMempool = */ true, function (err, tx) {
if (!err && tx) {

@@ -260,3 +260,2 @@ // getTransactionWithBlockInfo sometimes returns a bogus transaction

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

@@ -269,3 +268,3 @@

function (txid, reduce) {
self.parent.node.services.db.getTransactionWithBlockInfo(txid, /* queryMempool = */ true, function (err, tx) {
self.bitcoind.getDetailedTransaction(txid, /* queryMempool = */ true, function (err, tx) {
if (err) return reduce(err)

@@ -309,3 +308,2 @@

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

@@ -318,3 +316,3 @@

function (tx, reduce) {
self.parent.node.services.db.sendTransaction(tx, reduce)
self.bitcoind.sendTransaction(tx, reduce)
},

@@ -329,31 +327,27 @@ callback

this.height = null
this.tip = null
this.once('tip', function () {
self.emit('ready')
})
self.tip = null
var height = self.bitcoind.height
if (height) {
loadTip(height)
} else {
this.once('tip', function () {
self.emit('ready')
})
}
this.parent.node.services.bitcoind.on('tip', function (height) {
this.bitcoind.on('tip', loadTip)
// lazy calc tip summary
function loadTip (height) {
self.height = height
self.parent.node.services.bitcoind.getBlock(height, function (err, buf) {
if (err || !buf) return
self.bitcoind.getBlockHeader(height, function (err, header) {
if (err || !header) return
self.tip = Block.fromBuffer(buf)
tipSummary = null
header.height = height
self.tip = header
self.tipSummary = self._getBlockSummary(self.tip)
self.emit('tip', self.tip)
})
})
// lazy calc tip summary
var tipSummary
Object.defineProperty(this, 'tipSummary', {
get: function () {
if (!self.tip) return
if (!tipSummary) {
tipSummary = self._getBlockSummary(self.tip)
}
return tipSummary
}
})
}
}

@@ -370,3 +364,2 @@

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

@@ -379,3 +372,3 @@

function (hash, reduce) {
self.parent.node.services.db.getBlock(hash, function (err, block) {
self.bitcoind.getBlock(hash, function (err, block) {
reduce(err, !err && {

@@ -400,3 +393,2 @@ blockId: block.id,

// TODO: Replace with `typeforce`
$.checkArgument(Array.isArray(hashes), 'Must provide an array of block-hashes!')

@@ -409,4 +401,4 @@

function (hash, reduce) {
self.parent.node.services.db.getBlock(hash, function (err, block) {
reduce(err, !err && self._getBlockSummary(block, hash))
self.bitcoind.getBlockHeader(hash, function (err, header) {
reduce(err, !err && self._getBlockSummary(header, hash))
})

@@ -418,17 +410,29 @@ },

Blocks.prototype._getBlockSummary = function (block, hash) {
hash = hash || block.hash
var blockIndex = this.parent.node.services.bitcoind.getBlockIndex(hash)
var blockSize = block.toString().length
Blocks.prototype._getBlockSummary = function (header) {
// header looks like:
// {
// hash: result.hash,
// version: result.version,
// confirmations: result.confirmations,
// height: result.height,
// chainWork: result.chainwork,
// prevHash: result.previousblockhash,
// nextHash: result.nextblockhash,
// merkleRoot: result.merkleroot,
// time: result.time,
// medianTime: result.mediantime,
// nonce: result.nonce,
// bits: result.bits,
// difficulty: result.difficulty
// };
return {
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
blockId: header.hash,
prevBlockId: getId(header, 'prevHash'),
merkleRootHash: getId(header, 'merkleRoot'),
nonce: header.nonce,
version: header.version,
blockHeight: header.height,
timestamp: header.time,
// txCount: block.transactions.length
}

@@ -477,2 +481,20 @@ }

function reverseHex (str) {
if (Buffer.isBuffer(str)) return Array.prototype.reverse.call(str).toString('hex')
if (str.length % 2) str = '0' + str
var arr = []
while (str.length) {
arr.push(str.slice(-2))
str = str.slice(0, -2)
}
return arr.join('')
}
function getId (header, prop) {
return header.toJSON ? reverseHex(header[prop]) : header[prop].toString('hex')
}
module.exports = CommonBlockchainService
{
"name": "bitcore-common-blockchain",
"version": "1.1.0",
"version": "2.0.0",
"description": "common blockchain service for bitcore-node",

@@ -9,3 +9,7 @@ "main": "index.js",

},
"author": "Alexey Kudinkin <alexey.kudinkin@gmail.com> (http://github.com/alexeykudinkin)",
"author": {
"name": "Alexey Kudinkin",
"email": "alexey.kudinkin@gmail.com",
"url": "http://github.com/alexeykudinkin"
},
"license": "MIT",

@@ -21,3 +25,10 @@ "devDependencies": {

"cb-express-router": "mvayngrib/cb-express-router"
}
},
"readme": "# bitcore-common-blockchain\n\n[common-blockchain](https://github.com/common-blockchain/common-blockchain) service for [bitcore-node](https://github.com/bitpay/bitcore-node)\n\n# Install\n\n```bash\nbitcore-node install bitcore-common-blockchain\n```\n\n# Usage\n\nUse [cb-http-client](https://github.com/common-blockchain/cb-http-client) with the [common-blockchain](https://github.com/common-blockchain/common-blockchain) API against a bitcore node running this service.\n\n```js\n// assuming you have a local bitcore-node with its web server running on port 3001 (the default bitcore-node port):\nvar Blockchain = require('cb-http-client')\nvar blockchain = new Blockchain('http://127.0.0.1:3001/cb')\nblockchain.addresses.transactions(['mpNDUWcDcZw1Teo3LFHvr8usNdwDLKdTaY'], function (err, txs) {\n // i want to do bad things to txs \n})\n```\n",
"readmeFilename": "README.md",
"gitHead": "6d9f8a9e813483ca35c0e977e322e8f976874ac9",
"_id": "bitcore-common-blockchain@1.1.0",
"_shasum": "9e8a581fd03957990cfc8b3ddd4aec4bfa845890",
"_from": "../bitcore-common-blockchain",
"_resolved": "file:../bitcore-common-blockchain"
}

@@ -10,3 +10,4 @@ 'use strict'

var transactionData = require('./data/bitcoin-transactions.json')
var blockData = require('./data/livenet-345003.json')
// var blockData = require('./data/livenet-345003.json')
var blockData = require('./data/livenet-301321')

@@ -24,4 +25,2 @@ var CommonBlockchain = require('../')

services: {
address: {},
db: {},
bitcoind: new EventEmitter()

@@ -33,171 +32,171 @@ }

describe('Common Blockchain Interface', function () {
describe('@constructor', function () {
// TODO
// describe('@constructor', function () {
// // TODO
})
// })
describe('#addresses.summary', function () {
var node = newNode()
var summary = {
totalReceived: 3487110,
totalSpent: 0,
balance: 3487110,
unconfirmedBalance: 0,
appearances: 1,
unconfirmedAppearances: 1,
txids: [
'9f183412de12a6c1943fc86c390174c1cde38d709217fdb59dcf540230fa58a6',
'689e9f543fa4aa5b2daa3b5bb65f9a00ad5aa1a2e9e1fc4e11061d85f2aa9bc5'
]
}
// describe('#addresses.summary', function () {
// var node = newNode()
// var summary = {
// totalReceived: 3487110,
// totalSpent: 0,
// balance: 3487110,
// unconfirmedBalance: 0,
// appearances: 1,
// unconfirmedAppearances: 1,
// txids: [
// '9f183412de12a6c1943fc86c390174c1cde38d709217fdb59dcf540230fa58a6',
// '689e9f543fa4aa5b2daa3b5bb65f9a00ad5aa1a2e9e1fc4e11061d85f2aa9bc5'
// ]
// }
var cbs = new CommonBlockchain({ node: node })
node.services.address.getAddressSummary = sinon.stub().callsArgWith(2, null, summary)
// var cbs = new CommonBlockchain({ node: node })
// node.services.bitcoind.getAddressSummary = sinon.stub().callsArgWith(2, null, summary)
it('should return address summaries', function (done) {
cbs.addresses.summary([ 'mpkDdnLq26djg17s6cYknjnysAm3QwRzu2' ], function (err, summary) {
should.not.exist(err)
// it('should return address summaries', 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)
done()
})
})
})
// done()
// })
// })
// })
describe('#addresses.transactions', function () {
var node = newNode()
var history = {
totalCount: 1, // The total number of items within "start" and "end"
items: [
{
addresses: {
'mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW': {
inputIndexes: [],
outputIndexes: [0]
}
},
satoshis: 1000000000,
height: 150, // the block height of the transaction
confirmations: 3,
timestamp: 1442948127, // in seconds
fees: 191,
tx: new Transaction(new Buffer(transactionData[1].hex, 'hex'))
}
]
}
// describe('#addresses.transactions', function () {
// var node = newNode()
// var history = {
// totalCount: 1, // The total number of items within "start" and "end"
// items: [
// {
// addresses: {
// 'mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW': {
// inputIndexes: [],
// outputIndexes: [0]
// }
// },
// satoshis: 1000000000,
// height: 150, // the block height of the transaction
// confirmations: 3,
// timestamp: 1442948127, // in seconds
// fees: 191,
// tx: new Transaction(new Buffer(transactionData[1].hex, 'hex'))
// }
// ]
// }
var cbs = new CommonBlockchain({ node: node })
// var cbs = new CommonBlockchain({ node: node })
node.services.address.getAddressHistory = sinon.stub().callsArgWith(2, null, history)
// node.services.bitcoind.getAddressHistory = sinon.stub().callsArgWith(2, null, history)
it('should return the transaction history for the specified addresses', function (done) {
cbs.addresses.transactions([ 'mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW' ], null, function (err, txs) {
should.not.exist(err)
// it('should return the transaction history for the specified 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)
done()
})
})
})
// done()
// })
// })
// })
describe('#addresses.unspents', function () {
var node = newNode()
var unspentOuts = [
{
address: 'mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW',
txid: '9d956c5d324a1c2b12133f3242deff264a9b9f61be701311373998681b8c1769',
outputIndex: 1,
height: 150,
satoshis: 1000000000,
script: '76a9140b2f0a0c31bfe0406b0ccc1381fdbe311946dadc88ac',
confirmations: 3
}
]
// describe('#addresses.unspents', function () {
// var node = newNode()
// var unspentOuts = [
// {
// address: 'mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW',
// txid: '9d956c5d324a1c2b12133f3242deff264a9b9f61be701311373998681b8c1769',
// outputIndex: 1,
// height: 150,
// satoshis: 1000000000,
// script: '76a9140b2f0a0c31bfe0406b0ccc1381fdbe311946dadc88ac',
// confirmations: 3
// }
// ]
var cbs = new CommonBlockchain({ node: node })
// var cbs = new CommonBlockchain({ node: node })
node.services.address.getUnspentOutputs = sinon.stub().callsArgWith(2, null, unspentOuts)
// node.services.bitcoind.getAddressUnspentOutputs = sinon.stub().callsArgWith(2, null, unspentOuts)
it('should return unspents for specified addresses', function (done) {
cbs.addresses.unspents([ 'mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW' ], function (err, txs) {
should.not.exist(err)
// it('should return unspents for specified 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)
done()
})
})
})
// done()
// })
// })
// })
describe('#transactions.get', function () {
var node = newNode()
var tx = new Transaction()
// describe('#transactions.get', function () {
// var node = newNode()
// var tx = new Transaction()
var txHex = '0100000001a08ee59fcd5d86fa170abb6d925d62d5c5c476359681b70877c04f270c4ef246000000008a47304402203fb9b476bb0c37c9b9ed5784ebd67ae589492be11d4ae1612be29887e3e4ce750220741ef83781d1b3a5df8c66fa1957ad0398c733005310d7d9b1d8c2310ef4f74c0141046516ad02713e51ecf23ac9378f1069f9ae98e7de2f2edbf46b7836096e5dce95a05455cc87eaa1db64f39b0c63c0a23a3b8df1453dbd1c8317f967c65223cdf8ffffffff02b0a75fac000000001976a91484b45b9bf3add8f7a0f3daad305fdaf6b73441ea88ac20badc02000000001976a914809dc14496f99b6deb722cf46d89d22f4beb8efd88ac00000000'
// var txHex = '0100000001a08ee59fcd5d86fa170abb6d925d62d5c5c476359681b70877c04f270c4ef246000000008a47304402203fb9b476bb0c37c9b9ed5784ebd67ae589492be11d4ae1612be29887e3e4ce750220741ef83781d1b3a5df8c66fa1957ad0398c733005310d7d9b1d8c2310ef4f74c0141046516ad02713e51ecf23ac9378f1069f9ae98e7de2f2edbf46b7836096e5dce95a05455cc87eaa1db64f39b0c63c0a23a3b8df1453dbd1c8317f967c65223cdf8ffffffff02b0a75fac000000001976a91484b45b9bf3add8f7a0f3daad305fdaf6b73441ea88ac20badc02000000001976a914809dc14496f99b6deb722cf46d89d22f4beb8efd88ac00000000'
tx.fromString(txHex)
// tx.fromString(txHex)
var txId = tx.hash
// var txId = tx.hash
tx.__blockHash = '00000000000000001bb82a7f5973618cfd3185ba1ded04dd852a653f92a27c45'
tx.__height = 314159
tx.__timestamp = 1407292005
// tx.__blockHash = '00000000000000001bb82a7f5973618cfd3185ba1ded04dd852a653f92a27c45'
// tx.__height = 314159
// tx.__timestamp = 1407292005
var cbs = new CommonBlockchain({ node: node })
// var cbs = new CommonBlockchain({ node: node })
it('should return transaction bodies', function (done) {
node.services.db.getTransactionWithBlockInfo = sinon.stub().callsArgWith(2, null, tx)
cbs.transactions.get([ txId ], function (err, txs) {
should.not.exist(err)
// it('should return transaction bodies', function (done) {
// node.services.bitcoind.getDetailedTransaction = sinon.stub().callsArgWith(2, null, tx)
// 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)
done()
})
})
})
// done()
// })
// })
// })
describe('#transactions.summary', function () {
var node = newNode()
var txBuffer = new Buffer('01000000016f95980911e01c2c664b3e78299527a47933aac61a515930a8fe0213d1ac9abe01000000da0047304402200e71cda1f71e087c018759ba3427eb968a9ea0b1decd24147f91544629b17b4f0220555ee111ed0fc0f751ffebf097bdf40da0154466eb044e72b6b3dcd5f06807fa01483045022100c86d6c8b417bff6cc3bbf4854c16bba0aaca957e8f73e19f37216e2b06bb7bf802205a37be2f57a83a1b5a8cc511dc61466c11e9ba053c363302e7b99674be6a49fc0147522102632178d046673c9729d828cfee388e121f497707f810c131e0d3fc0fe0bd66d62103a0951ec7d3a9da9de171617026442fcd30f34d66100fab539853b43f508787d452aeffffffff0240420f000000000017a9148a31d53a448c18996e81ce67811e5fb7da21e4468738c9d6f90000000017a9148ce5408cfeaddb7ccb2545ded41ef478109454848700000000', 'hex')
var tx = new Transaction().fromBuffer(txBuffer)
tx.__blockHash = '00000000000ec715852ea2ecae4dc8563f62d603c820f81ac284cd5be0a944d6'
tx.__height = 530482
tx.__timestamp = 1439559434000
// describe('#transactions.summary', function () {
// var node = newNode()
// var txBuffer = new Buffer('01000000016f95980911e01c2c664b3e78299527a47933aac61a515930a8fe0213d1ac9abe01000000da0047304402200e71cda1f71e087c018759ba3427eb968a9ea0b1decd24147f91544629b17b4f0220555ee111ed0fc0f751ffebf097bdf40da0154466eb044e72b6b3dcd5f06807fa01483045022100c86d6c8b417bff6cc3bbf4854c16bba0aaca957e8f73e19f37216e2b06bb7bf802205a37be2f57a83a1b5a8cc511dc61466c11e9ba053c363302e7b99674be6a49fc0147522102632178d046673c9729d828cfee388e121f497707f810c131e0d3fc0fe0bd66d62103a0951ec7d3a9da9de171617026442fcd30f34d66100fab539853b43f508787d452aeffffffff0240420f000000000017a9148a31d53a448c18996e81ce67811e5fb7da21e4468738c9d6f90000000017a9148ce5408cfeaddb7ccb2545ded41ef478109454848700000000', 'hex')
// var tx = new Transaction().fromBuffer(txBuffer)
// tx.__blockHash = '00000000000ec715852ea2ecae4dc8563f62d603c820f81ac284cd5be0a944d6'
// tx.__height = 530482
// tx.__timestamp = 1439559434000
var txId = tx.hash
var cbs = new CommonBlockchain({ node: node })
// var txId = tx.hash
// var cbs = new CommonBlockchain({ node: node })
it('should return transaction summaries', function (done) {
node.services.db.getTransactionWithBlockInfo = sinon.stub().callsArgWith(2, null, tx)
cbs.transactions.summary([ txId ], function (err, txs) {
should.not.exist(err)
// it('should return transaction summaries', function (done) {
// node.services.bitcoind.getDetailedTransaction = sinon.stub().callsArgWith(2, null, tx)
// 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].nInputs .should.equal(0)
// txs[0].nOutputs .should.equal(0)
// txs[0].totalInputValue .should.equal(0)
// txs[0].totalOutputValue .should.equal(0)
// txs[0].txId.should.equal(txId)
// txs[0].blockId.should.equal('00000000000ec715852ea2ecae4dc8563f62d603c820f81ac284cd5be0a944d6')
// txs[0].blockHeight.should.equal(530482)
// // txs[0].nInputs .should.equal(0)
// // txs[0].nOutputs .should.equal(0)
// // txs[0].totalInputValue .should.equal(0)
// // txs[0].totalOutputValue .should.equal(0)
done()
})
})
})
// done()
// })
// })
// })

@@ -213,7 +212,7 @@ describe('#blocks.get', function () {

it('should return block bodies', function (done) {
node.services.db.getBlock = sinon.stub().callsArgWith(1, null, block)
cbs.blocks.get([ '00000000000000000593b60d8b4f40fd1ec080bdb0817d475dae47b5f5b1f735' ], function (err, blocks) {
node.services.bitcoind.getBlock = sinon.stub().callsArgWith(1, null, block)
cbs.blocks.get([ '000000000c9f25eb2565f81cdbe98aa692ccda81a3532cea1301a284b8f0cc0c' ], function (err, blocks) {
should.not.exist(err)
blocks[0].blockId.should.equal('00000000000000000593b60d8b4f40fd1ec080bdb0817d475dae47b5f5b1f735')
blocks[0].blockId.should.equal('000000000c9f25eb2565f81cdbe98aa692ccda81a3532cea1301a284b8f0cc0c')
blocks[0].blockHex.should.equal(blockData)

@@ -230,24 +229,22 @@

var block = Block.fromBuffer(blockBuffer)
var header = Block.fromBuffer(blockBuffer).header
header.height = 10
var blockIndex = { height: 10 }
var cbs = new CommonBlockchain({ node: node })
it('should return block summaries', function (done) {
node.services.db.getBlock = sinon.stub().callsArgWith(1, null, block)
node.services.bitcoind.getBlockIndex = sinon.stub().returns(blockIndex)
node.services.bitcoind.getBlockHeader = sinon.stub().callsArgWith(1, null, header)
cbs.blocks.summary([ '00000000000000000593b60d8b4f40fd1ec080bdb0817d475dae47b5f5b1f735' ], function (err, bs) {
cbs.blocks.summary([ '000000000c9f25eb2565f81cdbe98aa692ccda81a3532cea1301a284b8f0cc0c' ], 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].blockId.should.equal('000000000c9f25eb2565f81cdbe98aa692ccda81a3532cea1301a284b8f0cc0c')
bs[0].prevBlockId.should.equal('000000006c840ca5ff4dadcfeb4fe14b3d90c144be0fe5b8d06b329b8f8f3855')
bs[0].merkleRootHash.should.equal('70f719e112deef26cc9c955606e3c07e09441885d69ddd947ae66f4697f4400c')
bs[0].nonce.should.equal(1810450624)
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].blockSize.should.equal(232714)
bs[0].timestamp.should.equal(1413392796)
// bs[0].txCount.should.equal(182)

@@ -264,24 +261,23 @@ done()

var block = Block.fromBuffer(blockBuffer)
var header = block.header.toJSON()
header.height = 10
var blockIndex = { height: 10 }
var cbs = new CommonBlockchain({ node: node })
it('should return block summaries', function (done) {
node.services.bitcoind.getBlock = sinon.stub().callsArgWith(1, null, blockBuffer)
node.services.bitcoind.getBlockIndex = sinon.stub().returns(blockIndex)
node.services.bitcoind.emit('tip', block)
node.services.bitcoind.getBlockHeader = sinon.stub().callsArgWith(1, null, header)
node.services.bitcoind.emit('tip', header.height)
cbs.blocks.latest(function (err, b) {
cbs.blocks.latest(function (err, header) {
should.not.exist(err)
b.blockId.should.equal('00000000000000000593b60d8b4f40fd1ec080bdb0817d475dae47b5f5b1f735')
b.prevBlockId.should.equal('25c31a5ecbbdc9509e1ddf3330d0e08619213fec75d040170000000000000000')
b.merkleRootHash.should.equal('569070567854dd4cc9f6b82c6f5ba115e38b05f073575f983c471aab487f61dc')
b.nonce.should.equal(1970979152)
b.version.should.equal(2)
b.blockHeight.should.equal(10)
b.blockSize.should.equal(232714)
b.timestamp.should.equal(1424818934)
b.txCount.should.equal(182)
header.blockId.should.equal('000000000c9f25eb2565f81cdbe98aa692ccda81a3532cea1301a284b8f0cc0c')
header.prevBlockId.should.equal('000000006c840ca5ff4dadcfeb4fe14b3d90c144be0fe5b8d06b329b8f8f3855')
header.merkleRootHash.should.equal('70f719e112deef26cc9c955606e3c07e09441885d69ddd947ae66f4697f4400c')
header.nonce.should.equal(1810450624)
header.version.should.equal(2)
header.blockHeight.should.equal(10)
// header.blockSize.should.equal(232714)
header.timestamp.should.equal(1413392796)
// b.txCount.should.equal(182)

@@ -288,0 +284,0 @@ 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