From 5e5a58db19e4dab77f0f6fd39b8990655e33d825 Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Thu, 24 Aug 2017 09:38:07 -0400 Subject: [PATCH] Fixed tests. --- lib/addresses.js | 20 +- lib/blocks.js | 4 +- lib/transactions.js | 50 +-- package-lock.json | 999 ++++++++++++++++++++++++++++++++++++++++++- package.json | 1 + test/addresses.js | 310 ++++---------- test/blocks.js | 128 +----- test/transactions.js | 996 ++++++++---------------------------------- test/utils.js | 2 +- 9 files changed, 1338 insertions(+), 1172 deletions(-) diff --git a/lib/addresses.js b/lib/addresses.js index e7a0494..6b6d2ca 100644 --- a/lib/addresses.js +++ b/lib/addresses.js @@ -4,6 +4,7 @@ var bitcore = require('bitcore-lib'); var async = require('async'); var TxController = require('./transactions'); var Common = require('./common'); +var _ = require('lodash'); function AddressController(node) { this.node = node; @@ -26,10 +27,10 @@ AddressController.prototype.show = function(req, res) { } this._address.getAddressSummary(req.addr, options, function(err, data) { + if(err) { return self.common.handleErrors(err, res); } - res.jsonp(data); }); }; @@ -63,7 +64,7 @@ AddressController.prototype.addressSummarySubQuery = function(req, res, param) { AddressController.prototype.getAddressSummary = function(address, options, callback) { - this.node.getAddressSummary(address, options, function(err, summary) { + this._address.getAddressSummary(address, options, function(err, summary) { if(err) { return callback(err); } @@ -128,7 +129,7 @@ AddressController.prototype.check = function(req, res, next, addresses) { AddressController.prototype.utxo = function(req, res) { var self = this; - this.node.getAddressUnspentOutputs(req.addr, {}, function(err, utxos) { + this._address.getAddressUnspentOutputs(req.addr, {}, function(err, utxos) { if(err) { return self.common.handleErrors(err, res); } else if (!utxos.length) { @@ -143,9 +144,16 @@ AddressController.prototype.multiutxo = function(req, res) { var finalUtxos = []; - async.eachLimit(req.addrs, 4, function(addr, next) { + var addresses; + if (_.isArray(req.addrs)) { + addresses = req.addrs; + } else { + addresses = req.addrs.split(','); + } - self.node.getAddressUnspentOutputs(addr, {}, function(err, utxos) { + async.eachLimit(addresses, 4, function(addr, next) { + + self._address.getAddressUnspentOutputs(addr, {}, function(err, utxos) { if (err) { return next(err); @@ -204,7 +212,7 @@ AddressController.prototype.multitxs = function(req, res) { options.to = parseInt(req.query.to) || parseInt(req.body.to) || parseInt(options.from) + 10; - self.node.getAddressHistory(req.addrs, options, function(err, result) { + self._address.getAddressHistory(req.addrs, options, function(err, result) { if(err) { return self.common.handleErrors(err, res); diff --git a/lib/blocks.js b/lib/blocks.js index 2fb96fe..2e5c84f 100644 --- a/lib/blocks.js +++ b/lib/blocks.js @@ -3,7 +3,6 @@ var Stream = require('stream'); var util = require('util'); -var async = require('async'); var bitcore = require('bitcore-lib'); var _ = bitcore.deps._; var pools = require('../pools.json'); @@ -136,8 +135,7 @@ BlockController.prototype.transformBlock = function(block, info) { return { hash: block.rhash(), - size: block.size, - virtualSize: block.virtualSize, + size: block.getSize(), height: info.height, version: block.version, merkleroot: block.merkleRoot, diff --git a/lib/transactions.js b/lib/transactions.js index 054598f..42a2c04 100644 --- a/lib/transactions.js +++ b/lib/transactions.js @@ -12,6 +12,8 @@ function TxController(node) { this.node = node; this.common = new Common({log: this.node.log}); this._block = this.node.services.block; + this._transaction = this.node.services.transaction; + this._address = this.node.services.address; } TxController.prototype.show = function(req, res) { @@ -27,7 +29,7 @@ TxController.prototype.transaction = function(req, res, next) { var self = this; var txid = req.params.txid; - this.node.getDetailedTransaction(txid, function(err, transaction) { + this._transaction.getDetailedTransaction(txid, function(err, transaction) { if (err) { return self.common.handleErrors(err, res); } @@ -47,6 +49,7 @@ TxController.prototype.transaction = function(req, res, next) { }); }; +// transaction parameter is a bcoin transaction TxController.prototype.transformTransaction = function(transaction, options, callback) { if (_.isFunction(options)) { @@ -57,8 +60,9 @@ TxController.prototype.transformTransaction = function(transaction, options, cal $.checkArgument(_.isFunction(callback)); var confirmations = 0; - if(transaction.height >= 0) { - confirmations = this._block.getTip().height - transaction.height + 1; + + if(transaction.__height >= 0) { + confirmations = this._block.getTip().height - transaction.__height + 1; } var transformed = { @@ -68,6 +72,7 @@ TxController.prototype.transformTransaction = function(transaction, options, cal }; if(transaction.inputs[0].isCoinbase()) { + transformed.isCoinBase = true; transformed.vin = [ { coinbase: transaction.inputs[0].script.toJSON(), @@ -78,13 +83,15 @@ TxController.prototype.transformTransaction = function(transaction, options, cal } else { options.inputValues = transaction.__inputValues; transformed.vin = transaction.inputs.map(this.transformInput.bind(this, options)); + transformed.valueIn = transaction.inputSatoshis / 1e8; + transformed.fees = transaction.feeSatoshis / 1e8; } transformed.vout = transaction.outputs.map(this.transformOutput.bind(this, options)); - transformed.blockhash = transaction.blockHash; + transformed.blockhash = transaction.__blockhash; transformed.blockheight = transaction.__height; - transformed.confirmations = transaction.confirmations; + transformed.confirmations = confirmations; var time = transaction.__timestamp ? transaction.__timestamp : Math.round(Date.now() / 1000); transformed.time = time; @@ -92,16 +99,8 @@ TxController.prototype.transformTransaction = function(transaction, options, cal transformed.blocktime = transformed.time; } - if(transaction.inputs[0].isCoinbase()) { - transformed.isCoinBase = true; - } - transformed.valueOut = transaction.outputSatoshis / 1e8; transformed.size = transaction.getSize(); - if (!transaction.inputs[0].isCoinbase()) { - transformed.valueIn = transaction.inputSatoshis / 1e8; - transformed.fees = transaction.feeSatoshis / 1e8; - } callback(null, transformed); }; @@ -155,9 +154,10 @@ TxController.prototype.transformOutput = function(options, output, index) { } if (!options.noSpent) { - transformed.spentTxId = output.spentTxId || null; // we aren't tracking this with the bcoin implementation - transformed.spentIndex = _.isUndefined(output.spentIndex) ? null : output.spentIndex; - transformed.spentHeight = output.spentHeight || null; + // These aren't implemented in the new api + //transformed.spentTxId = output.spentTxId || null; // we aren't tracking this with the bcoin implementation + //transformed.spentIndex = _.isUndefined(output.spentIndex) ? null : output.spentIndex; + //transformed.spentHeight = output.spentHeight || null; } var address = output.getAddress(); @@ -206,7 +206,7 @@ TxController.prototype.rawTransaction = function(req, res, next) { var self = this; var txid = req.params.txid; - this.node.getTransaction(txid, function(err, transaction) { + this._transaction.getTransaction(txid, function(err, transaction) { if (err && err.code === -5) { return self.common.handleErrors(null, res); } else if(err) { @@ -238,7 +238,7 @@ TxController.prototype.list = function(req, res) { var pagesTotal = 1; if(blockHash) { - self.node.getBlockOverview(blockHash, function(err, block) { + self._block.getBlockOverview(blockHash, function(err, block) { if(err && err.code === -5) { return self.common.handleErrors(null, res); } else if(err) { @@ -257,7 +257,7 @@ TxController.prototype.list = function(req, res) { } async.mapSeries(txids, function(txid, next) { - self.node.getDetailedTransaction(txid, function(err, transaction) { + self._transaction.getDetailedTransaction(txid, {}, function(err, transaction) { if (err) { return next(err); } @@ -281,19 +281,13 @@ TxController.prototype.list = function(req, res) { to: (page + 1) * pageLength }; - self.node.getAddressHistory(address, options, function(err, result) { + self._address.getAddressHistory(address, options, function(err, result) { if(err) { return self.common.handleErrors(err, res); } - var txs = result.items.map(function(info) { - return info.tx; - }).filter(function(value, index, self) { - return self.indexOf(value) === index; - }); - async.map( - txs, + result.items, function(tx, next) { self.transformTransaction(tx, next); }, @@ -315,7 +309,7 @@ TxController.prototype.list = function(req, res) { TxController.prototype.send = function(req, res) { var self = this; - this.node.sendTransaction(req.body.rawtx, function(err, txid) { + this._transaction.sendTransaction(req.body.rawtx, function(err, txid) { if(err) { // TODO handle specific errors return self.common.handleErrors(err, res); diff --git a/package-lock.json b/package-lock.json index f9be5f2..6036300 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,14 +1,148 @@ { "name": "insight-api", - "version": "0.4.3", + "version": "5.0.0-beta.1", "lockfileVersion": 1, "requires": true, "dependencies": { + "abstract-leveldown": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/abstract-leveldown/-/abstract-leveldown-2.6.2.tgz", + "integrity": "sha512-6RmGuGZSsvwIYS9otANM+Rie7/6UNdE0IbxwUiXFjXmjHNCJZEjyX2Pltl5BvIYszLODlsnXtyA7A7Ujlca4Gw==", + "optional": true, + "requires": { + "xtend": "4.0.1" + } + }, + "accepts": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.3.tgz", + "integrity": "sha1-w8p0NJOGSMPg2cHjKN1otiLChMo=", + "optional": true, + "requires": { + "mime-types": "2.1.16", + "negotiator": "0.6.1" + } + }, + "after": { + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/after/-/after-0.8.2.tgz", + "integrity": "sha1-/ts5T58OAqqXaOcCvaI7UF+ufh8=" + }, + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + }, + "aproba": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.1.2.tgz", + "integrity": "sha512-ZpYajIfO0j2cOFTO955KUMIKNmj6zhX8kVztMAxFsDaMwz+9Z9SV0uou2pC9HJqcfpffOsjnbrDMvkNy+9RXPw==", + "optional": true + }, + "are-we-there-yet": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.4.tgz", + "integrity": "sha1-u13KOCu5TwXhUZQ3PRb9O6HKEQ0=", + "optional": true, + "requires": { + "delegates": "1.0.0", + "readable-stream": "2.3.3" + } + }, + "arraybuffer.slice": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/arraybuffer.slice/-/arraybuffer.slice-0.0.6.tgz", + "integrity": "sha1-8zshWfBTKj8xB6JywMz70a0peco=" + }, "async": { "version": "1.4.2", "resolved": "https://registry.npmjs.org/async/-/async-1.4.2.tgz", "integrity": "sha1-bJ7csRztTw3S8tQNsNSaEJwIiqs=" }, + "backo2": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz", + "integrity": "sha1-MasayLEpNjRj41s+u2n038+6eUc=", + "optional": true + }, + "base64-arraybuffer": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.1.5.tgz", + "integrity": "sha1-c5JncZI7Whl0etZmqlzUv5xunOg=" + }, + "base64id": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/base64id/-/base64id-1.0.0.tgz", + "integrity": "sha1-R2iMuZu2gE8OBtPnY7HDLlfY5rY=", + "optional": true + }, + "bcoin": { + "version": "github:bcoin-org/bcoin#886008a1822ce1da7fa8395ee7db4bcc1750a28a", + "requires": { + "bcoin-native": "0.0.20", + "bn.js": "4.11.7", + "elliptic": "6.4.0", + "leveldown": "1.7.0-0", + "n64": "0.0.11", + "secp256k1": "3.2.5", + "socket.io": "2.0.1", + "socket.io-client": "2.0.1" + }, + "dependencies": { + "bn.js": { + "version": "4.11.7", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.7.tgz", + "integrity": "sha512-LxFiV5mefv0ley0SzqkOPR1bC4EbpPx8LkOz5vMe/Yi15t5hzwgO/G+tc7wOtL4PZTYjwHu8JnEiSLumuSjSfA==" + }, + "elliptic": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.0.tgz", + "integrity": "sha1-ysmvh2LIWDYYcAPI3+GT5eLq5d8=", + "requires": { + "bn.js": "4.11.7", + "brorand": "1.1.0", + "hash.js": "1.1.3", + "hmac-drbg": "1.0.1", + "inherits": "2.0.1", + "minimalistic-assert": "1.0.0", + "minimalistic-crypto-utils": "1.0.1" + } + } + } + }, + "bcoin-native": { + "version": "0.0.20", + "resolved": "https://registry.npmjs.org/bcoin-native/-/bcoin-native-0.0.20.tgz", + "integrity": "sha1-zeKTpb1yrk+YXwcTRPDJoWunst0=", + "optional": true, + "requires": { + "bindings": "1.3.0", + "nan": "2.6.2" + } + }, + "better-assert": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/better-assert/-/better-assert-1.0.2.tgz", + "integrity": "sha1-QIZrnhueC1W0gYlDEeaPr/rrxSI=", + "requires": { + "callsite": "1.0.0" + } + }, + "bindings": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.3.0.tgz", + "integrity": "sha512-DpLh5EzMR2kzvX1KIlVC0VkC3iZtHKTgdtZ0a3pglBZdaQFjt5S9g9xd1lE+YvXyfd6mtCeRnrUfOLYiTMlNSw==", + "optional": true + }, + "bip66": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/bip66/-/bip66-1.1.5.tgz", + "integrity": "sha1-AfqHSHhcpwlV1QESF9GzE5lpyiI=", + "optional": true, + "requires": { + "safe-buffer": "5.1.1" + } + }, "bitcore-lib": { "version": "5.0.0-beta.1", "resolved": "https://registry.npmjs.org/bitcore-lib/-/bitcore-lib-5.0.0-beta.1.tgz", @@ -105,6 +239,20 @@ } } }, + "bl": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/bl/-/bl-1.2.1.tgz", + "integrity": "sha1-ysMo977kVzDUBLaSID/LWQ4XLV4=", + "optional": true, + "requires": { + "readable-stream": "2.3.3" + } + }, + "blob": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/blob/-/blob-0.0.4.tgz", + "integrity": "sha1-vPEwUspURj8w+fx+lbmkdjCpSSE=" + }, "bn.js": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-2.0.4.tgz", @@ -264,6 +412,19 @@ "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", "integrity": "sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8=" }, + "browserify-aes": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.0.6.tgz", + "integrity": "sha1-Xncl297x/Vkw1OurSFZ85FHEigo=", + "optional": true, + "requires": { + "buffer-xor": "1.0.3", + "cipher-base": "1.0.4", + "create-hash": "1.1.3", + "evp_bytestokey": "1.0.0", + "inherits": "2.0.1" + } + }, "bs58": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/bs58/-/bs58-2.0.0.tgz", @@ -274,6 +435,17 @@ "resolved": "https://registry.npmjs.org/buffer-compare/-/buffer-compare-1.0.0.tgz", "integrity": "sha1-rKp6lm6Y7un64Usxw5pfFY+zxKI=" }, + "buffer-xor": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", + "integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=", + "optional": true + }, + "callsite": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/callsite/-/callsite-1.0.0.tgz", + "integrity": "sha1-KAOY5dZkvXQDi28JBRU+borxvCA=" + }, "chai": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/chai/-/chai-3.5.0.tgz", @@ -316,6 +488,43 @@ } } }, + "chownr": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.0.1.tgz", + "integrity": "sha1-4qdQQqlVGQi+vSW4Uj1fl2nXkYE=", + "optional": true + }, + "cipher-base": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz", + "integrity": "sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q==", + "requires": { + "inherits": "2.0.1", + "safe-buffer": "5.1.1" + } + }, + "code-point-at": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", + "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=" + }, + "component-bind": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/component-bind/-/component-bind-1.0.0.tgz", + "integrity": "sha1-AMYIq33Nk4l8AAllGx06jh5zu9E=", + "optional": true + }, + "component-emitter": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.2.1.tgz", + "integrity": "sha1-E3kY1teCg/ffemt8WmPhQOaUJeY=" + }, + "component-inherit": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/component-inherit/-/component-inherit-0.0.3.tgz", + "integrity": "sha1-ZF/ErfWLcrZJ1crmUTVhnbJv8UM=", + "optional": true + }, "compression": { "version": "1.6.2", "resolved": "https://registry.npmjs.org/compression/-/compression-1.6.2.tgz", @@ -407,6 +616,78 @@ } } }, + "console-control-strings": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", + "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=" + }, + "cookie": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", + "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=", + "optional": true + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" + }, + "create-hash": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.1.3.tgz", + "integrity": "sha1-YGBCrIuSYnUPSDyt2rD1gZFy2P0=", + "requires": { + "cipher-base": "1.0.4", + "inherits": "2.0.1", + "ripemd160": "2.0.1", + "sha.js": "2.4.8" + } + }, + "create-hmac": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.6.tgz", + "integrity": "sha1-rLniIaThe9sHbpBlfEK5PjcmzwY=", + "optional": true, + "requires": { + "cipher-base": "1.0.4", + "create-hash": "1.1.3", + "inherits": "2.0.1", + "ripemd160": "2.0.1", + "safe-buffer": "5.1.1", + "sha.js": "2.4.8" + } + }, + "debug": { + "version": "2.6.8", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", + "integrity": "sha1-5zFTHKLt4n0YgiJCfaF4IdaP9Pw=", + "requires": { + "ms": "2.0.0" + } + }, + "deep-extend": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.4.2.tgz", + "integrity": "sha1-SLaZwn4zS/ifEIkr5DL25MfTSn8=", + "optional": true + }, + "delegates": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", + "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=", + "optional": true + }, + "drbg.js": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/drbg.js/-/drbg.js-1.0.1.tgz", + "integrity": "sha1-Pja2xCs3BDgjzbwzLVjzHiRFSAs=", + "optional": true, + "requires": { + "browserify-aes": "1.0.6", + "create-hash": "1.1.3", + "create-hmac": "1.1.6" + } + }, "elliptic": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-3.0.3.tgz", @@ -418,6 +699,138 @@ "inherits": "2.0.1" } }, + "end-of-stream": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.0.tgz", + "integrity": "sha1-epDYM+/abPpurA9JSduw+tOmMgY=", + "requires": { + "once": "1.4.0" + } + }, + "engine.io": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-3.1.0.tgz", + "integrity": "sha1-XKQ4486f28kVxKIcjdnhJmcG5X4=", + "optional": true, + "requires": { + "accepts": "1.3.3", + "base64id": "1.0.0", + "cookie": "0.3.1", + "debug": "2.6.8", + "engine.io-parser": "2.1.1", + "uws": "0.14.5", + "ws": "2.3.1" + } + }, + "engine.io-client": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-3.1.1.tgz", + "integrity": "sha1-QVqYUrrbFPoAj6PvHjFgjbZ2EyU=", + "optional": true, + "requires": { + "component-emitter": "1.2.1", + "component-inherit": "0.0.3", + "debug": "2.6.8", + "engine.io-parser": "2.1.1", + "has-cors": "1.1.0", + "indexof": "0.0.1", + "parsejson": "0.0.3", + "parseqs": "0.0.5", + "parseuri": "0.0.5", + "ws": "2.3.1", + "xmlhttprequest-ssl": "1.5.3", + "yeast": "0.1.2" + } + }, + "engine.io-parser": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-2.1.1.tgz", + "integrity": "sha1-4Ps/DgRi9/WLt3waUun1p+JuRmg=", + "requires": { + "after": "0.8.2", + "arraybuffer.slice": "0.0.6", + "base64-arraybuffer": "0.1.5", + "blob": "0.0.4", + "has-binary2": "1.0.2" + } + }, + "evp_bytestokey": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.0.tgz", + "integrity": "sha1-SXtmrZ/vZc18CKYYCCS6FHa2blM=", + "optional": true, + "requires": { + "create-hash": "1.1.3" + } + }, + "expand-template": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/expand-template/-/expand-template-1.0.3.tgz", + "integrity": "sha1-bDAzIxd6YrGyLAcCefeGEoe2mxo=", + "optional": true + }, + "fast-future": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/fast-future/-/fast-future-1.0.2.tgz", + "integrity": "sha1-hDWpqqAteSSNF9cE52JZMB2ZKAo=", + "optional": true + }, + "gauge": { + "version": "2.7.4", + "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", + "integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=", + "optional": true, + "requires": { + "aproba": "1.1.2", + "console-control-strings": "1.1.0", + "has-unicode": "2.0.1", + "object-assign": "4.1.1", + "signal-exit": "3.0.2", + "string-width": "1.0.2", + "strip-ansi": "3.0.1", + "wide-align": "1.1.2" + } + }, + "github-from-package": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz", + "integrity": "sha1-l/tdlr/eiXMxPyDoKI75oWf6ZM4=", + "optional": true + }, + "has-binary2": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-binary2/-/has-binary2-1.0.2.tgz", + "integrity": "sha1-6D26SfC5vk0CbSc2U1DZ8D9Uvpg=", + "requires": { + "isarray": "2.0.1" + }, + "dependencies": { + "isarray": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.1.tgz", + "integrity": "sha1-o32U7ZzaLVmGXJ92/llu4fM4dB4=" + } + } + }, + "has-cors": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-cors/-/has-cors-1.1.0.tgz", + "integrity": "sha1-XkdHk/fqmEPRu5nCPu9J/xJv/zk=" + }, + "has-unicode": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", + "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=", + "optional": true + }, + "hash-base": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-2.0.2.tgz", + "integrity": "sha1-ZuodhW206KVHDK32/OI65SRO8uE=", + "requires": { + "inherits": "2.0.1" + } + }, "hash.js": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.3.tgz", @@ -434,11 +847,80 @@ } } }, + "hmac-drbg": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", + "integrity": "sha1-0nRXAQJabHdabFRXk+1QL8DGSaE=", + "requires": { + "hash.js": "1.1.3", + "minimalistic-assert": "1.0.0", + "minimalistic-crypto-utils": "1.0.1" + } + }, + "indexof": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/indexof/-/indexof-0.0.1.tgz", + "integrity": "sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10=" + }, "inherits": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz", "integrity": "sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE=" }, + "ini": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.4.tgz", + "integrity": "sha1-BTfLedr1m1mhpRff9wbIbsA5Fi4=", + "optional": true + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", + "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", + "requires": { + "number-is-nan": "1.0.1" + } + }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" + }, + "jsonparse": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz", + "integrity": "sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=" + }, + "JSONStream": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.1.tgz", + "integrity": "sha1-cH92HgHa6eFvG8+TcDt4xwlmV5o=", + "requires": { + "jsonparse": "1.3.1", + "through": "2.3.8" + } + }, + "leveldown": { + "version": "1.7.0-0", + "resolved": "https://registry.npmjs.org/leveldown/-/leveldown-1.7.0-0.tgz", + "integrity": "sha1-orKVMhbsJzrmWkG6bNiNaXn98T8=", + "optional": true, + "requires": { + "abstract-leveldown": "2.6.2", + "bindings": "1.2.1", + "fast-future": "1.0.2", + "nan": "2.6.2", + "prebuild-install": "2.2.2" + }, + "dependencies": { + "bindings": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.2.1.tgz", + "integrity": "sha1-FK1hE4EtLTfXLme0ystLtyZQXxE=", + "optional": true + } + } + }, "lodash": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz", @@ -465,11 +947,51 @@ } } }, + "mime-db": { + "version": "1.29.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.29.0.tgz", + "integrity": "sha1-SNJtI1WJZRcErFkWygYAGRQmaHg=", + "optional": true + }, + "mime-types": { + "version": "2.1.16", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.16.tgz", + "integrity": "sha1-K4WKUuXs1RbbiXrCvodIeDBpjiM=", + "optional": true, + "requires": { + "mime-db": "1.29.0" + } + }, "minimalistic-assert": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.0.tgz", "integrity": "sha1-cCvi3aazf0g2vLP121ZkG2Sh09M=" }, + "minimalistic-crypto-utils": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz", + "integrity": "sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo=" + }, + "minimist": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "requires": { + "minimist": "0.0.8" + }, + "dependencies": { + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" + } + } + }, "mocha": { "version": "2.5.3", "resolved": "https://registry.npmjs.org/mocha/-/mocha-2.5.3.tgz", @@ -685,6 +1207,136 @@ } } }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "n64": { + "version": "0.0.11", + "resolved": "https://registry.npmjs.org/n64/-/n64-0.0.11.tgz", + "integrity": "sha1-NFG8by8g/okyxkfodoXFi+SjSJo=" + }, + "nan": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.6.2.tgz", + "integrity": "sha1-5P805slf37WuzAjeZZb0NgWn20U=", + "optional": true + }, + "negotiator": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", + "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=", + "optional": true + }, + "node-abi": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.1.0.tgz", + "integrity": "sha512-AbW35CPRE4vdieOse46V+16dKispLNv3PQwgqlcfg7GQeQHcLu3gvp3fbU2gTh7d8NfGjp5CJh+j4Hpyb0XzaA==", + "optional": true + }, + "noop-logger": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/noop-logger/-/noop-logger-0.1.1.tgz", + "integrity": "sha1-lKKxYzxPExdVMAfYlm/Q6EG2pMI=", + "optional": true + }, + "npmlog": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", + "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", + "optional": true, + "requires": { + "are-we-there-yet": "1.1.4", + "console-control-strings": "1.1.0", + "gauge": "2.7.4", + "set-blocking": "2.0.0" + } + }, + "number-is-nan": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", + "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", + "optional": true + }, + "object-component": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/object-component/-/object-component-0.0.3.tgz", + "integrity": "sha1-8MaapQ78lbhmwYb0AKM3acsvEpE=", + "optional": true + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1.0.2" + } + }, + "os-homedir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", + "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", + "optional": true + }, + "parsejson": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/parsejson/-/parsejson-0.0.3.tgz", + "integrity": "sha1-q343WfIJ7OmUN5c/fQ8fZK4OZKs=", + "optional": true, + "requires": { + "better-assert": "1.0.2" + } + }, + "parseqs": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/parseqs/-/parseqs-0.0.5.tgz", + "integrity": "sha1-1SCKNzjkZ2bikbouoXNoSSGouJ0=", + "optional": true, + "requires": { + "better-assert": "1.0.2" + } + }, + "parseuri": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/parseuri/-/parseuri-0.0.5.tgz", + "integrity": "sha1-gCBKUNTbt3m/3G6+J3jZDkvOMgo=", + "requires": { + "better-assert": "1.0.2" + } + }, + "prebuild-install": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-2.2.2.tgz", + "integrity": "sha512-F46pcvDxtQhbV3B+dm+exHuKxIyJK26fVNiJRmbTW/5D7o0Z2yzc8CKeu7UWbo9XxQZoVOC88aKgySAsza+cWw==", + "optional": true, + "requires": { + "expand-template": "1.0.3", + "github-from-package": "0.0.0", + "minimist": "1.2.0", + "mkdirp": "0.5.1", + "node-abi": "2.1.0", + "noop-logger": "0.1.1", + "npmlog": "4.1.2", + "os-homedir": "1.0.2", + "pump": "1.0.2", + "rc": "1.2.1", + "simple-get": "1.4.3", + "tar-fs": "1.15.3", + "tunnel-agent": "0.6.0", + "xtend": "4.0.1" + } + }, + "process-nextick-args": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", + "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=" + }, "proxyquire": { "version": "1.7.3", "resolved": "https://registry.npmjs.org/proxyquire/-/proxyquire-1.7.3.tgz", @@ -727,6 +1379,48 @@ } } }, + "pump": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/pump/-/pump-1.0.2.tgz", + "integrity": "sha1-Oz7mUS+U8OV1U4wXmV+fFpkKXVE=", + "requires": { + "end-of-stream": "1.4.0", + "once": "1.4.0" + } + }, + "rc": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.1.tgz", + "integrity": "sha1-LgPo5C7kULjLPc5lvhv4l04d/ZU=", + "optional": true, + "requires": { + "deep-extend": "0.4.2", + "ini": "1.3.4", + "minimist": "1.2.0", + "strip-json-comments": "2.0.1" + } + }, + "readable-stream": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz", + "integrity": "sha512-m+qzzcn7KUxEmd1gMbchF+Y2eIUbieUaxkWtptyHywrX0rE8QEYqPC07Vuy4Wm32/xE16NcdBctb8S0Xe/5IeQ==", + "requires": { + "core-util-is": "1.0.2", + "inherits": "2.0.3", + "isarray": "1.0.0", + "process-nextick-args": "1.0.7", + "safe-buffer": "5.1.1", + "string_decoder": "1.0.3", + "util-deprecate": "1.0.2" + }, + "dependencies": { + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + } + } + }, "request": { "version": "2.64.0", "resolved": "https://registry.npmjs.org/request/-/request-2.64.0.tgz", @@ -1114,6 +1808,72 @@ } } }, + "ripemd160": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.1.tgz", + "integrity": "sha1-D0WEKVxTo2KK9+bXmsohzlfRxuc=", + "requires": { + "hash-base": "2.0.2", + "inherits": "2.0.1" + } + }, + "safe-buffer": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", + "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" + }, + "secp256k1": { + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-3.2.5.tgz", + "integrity": "sha1-Dd5bJ+UCFmX23/ynssPgEMbBPJM=", + "optional": true, + "requires": { + "bindings": "1.3.0", + "bip66": "1.1.5", + "bn.js": "4.11.8", + "create-hash": "1.1.3", + "drbg.js": "1.0.1", + "elliptic": "6.4.0", + "nan": "2.6.2", + "prebuild-install": "2.2.2" + }, + "dependencies": { + "bn.js": { + "version": "4.11.8", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", + "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==" + }, + "elliptic": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.0.tgz", + "integrity": "sha1-ysmvh2LIWDYYcAPI3+GT5eLq5d8=", + "optional": true, + "requires": { + "bn.js": "4.11.8", + "brorand": "1.1.0", + "hash.js": "1.1.3", + "hmac-drbg": "1.0.1", + "inherits": "2.0.1", + "minimalistic-assert": "1.0.0", + "minimalistic-crypto-utils": "1.0.1" + } + } + } + }, + "set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", + "optional": true + }, + "sha.js": { + "version": "2.4.8", + "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.8.tgz", + "integrity": "sha1-NwaMLEdra69ALRSknGf1l5IfY08=", + "requires": { + "inherits": "2.0.1" + } + }, "should": { "version": "8.4.0", "resolved": "https://registry.npmjs.org/should/-/should-8.4.0.tgz", @@ -1151,6 +1911,23 @@ } } }, + "signal-exit": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", + "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", + "optional": true + }, + "simple-get": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-1.4.3.tgz", + "integrity": "sha1-6XVe2kB+ltpAxeUVjJ6jezO+y+s=", + "optional": true, + "requires": { + "once": "1.4.0", + "unzip-response": "1.0.2", + "xtend": "4.0.1" + } + }, "sinon": { "version": "1.17.0", "resolved": "https://registry.npmjs.org/sinon/-/sinon-1.17.0.tgz", @@ -1202,6 +1979,226 @@ } } } + }, + "socket.io": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-2.0.1.tgz", + "integrity": "sha1-BkwSUXhGLkd6bfI9L9rRjdHFkU8=", + "optional": true, + "requires": { + "debug": "2.6.8", + "engine.io": "3.1.0", + "object-assign": "4.1.1", + "socket.io-adapter": "1.1.1", + "socket.io-client": "2.0.1", + "socket.io-parser": "3.1.2" + } + }, + "socket.io-adapter": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-1.1.1.tgz", + "integrity": "sha1-KoBeihTWNyEk3ZFZrUUC+MsH8Gs=", + "optional": true + }, + "socket.io-client": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-2.0.1.tgz", + "integrity": "sha1-HVL4x0Zgxou2aVlT+hGZcRVfrZM=", + "optional": true, + "requires": { + "backo2": "1.0.2", + "base64-arraybuffer": "0.1.5", + "component-bind": "1.0.0", + "component-emitter": "1.2.1", + "debug": "2.6.4", + "engine.io-client": "3.1.1", + "has-cors": "1.1.0", + "indexof": "0.0.1", + "object-component": "0.0.3", + "parseuri": "0.0.5", + "socket.io-parser": "3.1.2", + "to-array": "0.1.4" + }, + "dependencies": { + "debug": { + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.4.tgz", + "integrity": "sha1-dYaps8OXQcAoKuM0RcTorHRzT+A=", + "optional": true, + "requires": { + "ms": "0.7.3" + } + }, + "ms": { + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-0.7.3.tgz", + "integrity": "sha1-cIFVpeROM/X9D8U+gdDUCpG+H/8=", + "optional": true + } + } + }, + "socket.io-parser": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-3.1.2.tgz", + "integrity": "sha1-28IoIVH8T6675Aru3Ady66YZ9/I=", + "requires": { + "component-emitter": "1.2.1", + "debug": "2.6.8", + "has-binary2": "1.0.2", + "isarray": "2.0.1" + }, + "dependencies": { + "isarray": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.1.tgz", + "integrity": "sha1-o32U7ZzaLVmGXJ92/llu4fM4dB4=" + } + } + }, + "string_decoder": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", + "requires": { + "safe-buffer": "5.1.1" + } + }, + "string-width": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", + "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", + "requires": { + "code-point-at": "1.1.0", + "is-fullwidth-code-point": "1.0.0", + "strip-ansi": "3.0.1" + } + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "requires": { + "ansi-regex": "2.1.1" + } + }, + "strip-json-comments": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", + "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", + "optional": true + }, + "tar-fs": { + "version": "1.15.3", + "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-1.15.3.tgz", + "integrity": "sha1-7M+TXpQUk9gVECjmNuUc5MPKfyA=", + "optional": true, + "requires": { + "chownr": "1.0.1", + "mkdirp": "0.5.1", + "pump": "1.0.2", + "tar-stream": "1.5.4" + } + }, + "tar-stream": { + "version": "1.5.4", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-1.5.4.tgz", + "integrity": "sha1-NlSc8E7RrumyowwBQyUiONr5QBY=", + "optional": true, + "requires": { + "bl": "1.2.1", + "end-of-stream": "1.4.0", + "readable-stream": "2.3.3", + "xtend": "4.0.1" + } + }, + "through": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", + "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=" + }, + "to-array": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/to-array/-/to-array-0.1.4.tgz", + "integrity": "sha1-F+bBH3PdTz10zaek/zI46a2b+JA=", + "optional": true + }, + "tunnel-agent": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", + "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", + "optional": true, + "requires": { + "safe-buffer": "5.1.1" + } + }, + "ultron": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.0.tgz", + "integrity": "sha1-sHoualQagV/Go0zNRTO67DB8qGQ=" + }, + "unzip-response": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/unzip-response/-/unzip-response-1.0.2.tgz", + "integrity": "sha1-uYTwh3/AqJwsdzzB73tbIytbBv4=", + "optional": true + }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + }, + "uws": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/uws/-/uws-0.14.5.tgz", + "integrity": "sha1-Z6rzPEaypYel9mZtAPdpEyjxSdw=", + "optional": true + }, + "wide-align": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.2.tgz", + "integrity": "sha512-ijDLlyQ7s6x1JgCLur53osjm/UXUYD9+0PbYKrBsYisYXzCxN+HC3mYDNy/dWdmf3AwqwU3CXwDCvsNgGK1S0w==", + "optional": true, + "requires": { + "string-width": "1.0.2" + } + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + }, + "ws": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-2.3.1.tgz", + "integrity": "sha1-a5Sz5EfLajY/eF6vlK9jWejoHIA=", + "requires": { + "safe-buffer": "5.0.1", + "ultron": "1.1.0" + }, + "dependencies": { + "safe-buffer": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.0.1.tgz", + "integrity": "sha1-0mPKVGls2KMGtcplUekt5XkY++c=" + } + } + }, + "xmlhttprequest-ssl": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.3.tgz", + "integrity": "sha1-GFqIjATspGw+QHDZn3tJ3jUomS0=", + "optional": true + }, + "xtend": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", + "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=" + }, + "yeast": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/yeast/-/yeast-0.1.2.tgz", + "integrity": "sha1-AI4G2AlDIMNy28L47XagymyKxBk=", + "optional": true } } } diff --git a/package.json b/package.json index 99e01f6..6d54480 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "dependencies": { "JSONStream": "^1.3.1", "async": "*", + "bcoin": "bcoin-org/bcoin#886008a1822ce1da7fa8395ee7db4bcc1750a28a", "bitcore-lib": "5.0.0-beta.1", "bitcore-message": "^1.0.1", "body-parser": "^1.13.3", diff --git a/test/addresses.js b/test/addresses.js index aba9790..e94fd95 100644 --- a/test/addresses.js +++ b/test/addresses.js @@ -4,6 +4,7 @@ var should = require('should'); var AddressController = require('../lib/addresses'); var _ = require('lodash'); var bitcore = require('bitcore-lib'); +var bcoin = require('bcoin'); var txinfos = { totalCount: 2, @@ -144,13 +145,17 @@ var tx = { locktime: 0 }; +var rawHex = "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d010bffffffff0100f2052a010000004341047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77ac00000000"; + +var bcoinTx = bcoin.tx.fromRaw(rawHex, 'hex'); +bcoinTx.__blockhash = '0000000000000041ddc94ecf4f86a456a83b2e320c36c6f0c13ff92c7e75f013'; +bcoinTx.__height = 534181; +bcoinTx.__timestamp = 1441116143; +bcoinTx.outputSatoshis = 53829829; + var txinfos2 = { totalCount: 1, - items: [ - { - tx: tx - } - ] + items: [ bcoinTx ] }; var utxos = [ @@ -191,8 +196,13 @@ describe('Addresses', function() { }; describe('/addr/:addr', function() { var node = { - services: { address: {} }, - getAddressSummary: sinon.stub().callsArgWith(2, null, summary) + + services: { + address: { + getAddressSummary: sinon.stub().callsArgWith(2, null, summary) + } + } + }; var addresses = new AddressController(node); @@ -201,40 +211,17 @@ describe('Addresses', function() { query: {} }; - it('should have correct data', function(done) { - var insight = { - 'addrStr': 'mkPvAKZ2rar6qeG3KjBtJHHMSP1wFZH7Er', - 'balance': 0, - 'balanceSat': 0, - 'totalReceived': 27.82729129, - 'totalReceivedSat': 2782729129, - 'totalSent': 27.82729129, - 'totalSentSat': 2782729129, - 'unconfirmedBalance': 0, - 'unconfirmedBalanceSat': 0, - 'unconfirmedTxApperances': 0, - 'txApperances': 2, - 'transactions': [ - 'bb0ec3b96209fac9529570ea6f83a86af2cceedde4aaf2bfcc4796680d23f1c7', - '01f700df84c466f2a389440e5eeacdc47d04f380c39e5d19dce2ce91a11ecba3' - ] - }; - - var res = { - jsonp: function(data) { - should(data).eql(insight); - done(); + it('handle error', function() { + var testnode = { + services: { + address: { + getAddressSummary: sinon.stub().callsArgWith(2, new Error('test')) + } } }; - addresses.show(req, res); - }); - - it('handle error', function() { - var testnode = { services: { address: { getTip: sinon.stub().returns({ height: 123 }) } } }; testnode.log = {}; testnode.log.error = sinon.stub(); var controller = new AddressController(testnode); - controller.getAddressSummary = sinon.stub().callsArgWith(2, new Error('test')); var req = { query: { noTxList: 1 @@ -329,8 +316,15 @@ describe('Addresses', function() { ]; var node = { - services: { address: {}, block: { getTip: sinon.stub().returns({ height: 534230 }) } }, - getAddressUnspentOutputs: sinon.stub().callsArgWith(2, null, utxos.slice(0, 1)) + services: { + block: { + getTip: sinon.stub().returns({ height: 534230 }) + }, + address: { + getAddressUnspentOutputs: sinon.stub().callsArgWith(2, null, utxos.slice(0, 1)) + } + }, + }; var addresses = new AddressController(node); @@ -352,7 +346,9 @@ describe('Addresses', function() { }); describe('/addrs/:addrs/utxo', function() { + it('should have the correct data', function(done) { + var insight = [ { 'address': 'mzkD4nmQ8ixqxySdBgsXTpgvAMK5iRZpNK', @@ -388,9 +384,20 @@ describe('Addresses', function() { } ]; + var utxoStub = sinon.stub(); + utxoStub.onCall(0).callsArgWith(2, null, [utxos[0]]); + utxoStub.onCall(1).callsArgWith(2, null, [utxos[1]]); + var node = { - services: { address: {}, block: { getTip: sinon.stub().returns({ height: 534230 }) } }, - getAddressUnspentOutputs: sinon.stub().callsArgWith(2, null, utxos) + services: { + address: { + getAddressUnspentOutputs: utxoStub + }, + block: { + getTip: sinon.stub().returns({ height: 534230 }) + } + }, + }; var addresses = new AddressController(node); @@ -412,94 +419,38 @@ describe('Addresses', function() { }); describe('/addrs/:addrs/txs', function() { + it('should have correct data', function(done) { + var insight = { 'totalItems': 1, 'from': 0, 'to': 1, 'items': [ { - 'txid': '63b68becb0e514b32317f4b29a5cf0627d4087e54ac17f686fcb1d9a27680f73', + 'txid': '9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5', 'version': 1, + 'isCoinBase': true, 'locktime': 0, 'vin': [ { - 'txid': 'ea97726ffc529808094ae5568342267931a058375a20147535a0d095837079f3', - 'vout': 1, - 'scriptSig': { - 'asm': '3044022054233934268b30be779fad874ef42e8db928ba27a1b612d5f111b3ee95eb271c022024272bbaf2dcc4050bd3b9dfa3c93884f6ba6ad7d257598b8245abb65b5ab1e401 040682fdb281a8533e21e13dfd1fcfa424912a85b6cdc4136b5842c85de05ac1f0e4a013f20702adeb53329de13b2ef388e5ed6244676f4f1ee4ee685ab607964d', - 'hex': '473044022054233934268b30be779fad874ef42e8db928ba27a1b612d5f111b3ee95eb271c022024272bbaf2dcc4050bd3b9dfa3c93884f6ba6ad7d257598b8245abb65b5ab1e40141040682fdb281a8533e21e13dfd1fcfa424912a85b6cdc4136b5842c85de05ac1f0e4a013f20702adeb53329de13b2ef388e5ed6244676f4f1ee4ee685ab607964d' - }, + 'coinbase': '04ffff001d010b', 'sequence': 4294967295, - 'n': 0, - 'addr': 'moFfnRwt77pApKnnU6m5uocFaa43aAYpt5', - 'valueSat': 53540000, - 'value': 0.5354, - 'doubleSpentTxID': null - }, - { - 'txid': '980a9cc2dbc2d3464eb9900ae6d579a03045408563320f62d99316c3d4ff58b7', - 'vout': 2, - 'scriptSig': { - 'asm': '3044022044938ac3f8fcb8da29011df6397ed28cc7e894cdc35d596d4f3623bd8c7e465f022014829c6e0bd7ee97a1bcfef6b85c5fd232653f289394fc6ce6ebb41c73403f1b01 04d9ccf88efc6e5be3151fae5e848efd94c91d75e7bf621f9f724a8caff51415338525d3239fae6b93826edf759dd562f77693e55dfa852ffd96a92d683db590f2', - 'hex': '473044022044938ac3f8fcb8da29011df6397ed28cc7e894cdc35d596d4f3623bd8c7e465f022014829c6e0bd7ee97a1bcfef6b85c5fd232653f289394fc6ce6ebb41c73403f1b014104d9ccf88efc6e5be3151fae5e848efd94c91d75e7bf621f9f724a8caff51415338525d3239fae6b93826edf759dd562f77693e55dfa852ffd96a92d683db590f2' - }, - 'sequence': 4294967295, - 'n': 1, - 'addr': 'n1XJBAyU4hNR4xRtY3UxnmAteoJX83p5qv', - 'valueSat': 299829, - 'value': 0.00299829, - 'doubleSpentTxID': null + 'n': 0 } ], 'vout': [ { - 'value': '0.00220000', + 'value': '50.00000000', 'n': 0, 'scriptPubKey': { - 'asm': 'OP_DUP OP_HASH160 b9bbd76588d9e4e09f0369a9aa0b2749a11c4e8d OP_EQUALVERIFY OP_CHECKSIG', - 'hex': '76a914b9bbd76588d9e4e09f0369a9aa0b2749a11c4e8d88ac', - 'reqSigs': 1, + 'asm': '047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77 OP_CHECKSIG', + 'hex': '41047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77ac', 'type': 'pubkeyhash', 'addresses': [ - 'mxT2KzTUQvsaYYothDtjcdvyAdaHA9ofMp' + '1HLoD9E4SDFFPDiYfNYnkBLQ85Y51J3Zb1' ] - }, - 'spentHeight': null, - 'spentIndex': null, - 'spentTxId': null - }, - { - 'value': '0.53320000', - 'n': 1, - 'scriptPubKey': { - 'asm': 'OP_DUP OP_HASH160 d2ec20bb8e5f25a52f730384b803d95683250e0b OP_EQUALVERIFY OP_CHECKSIG', - 'hex': '76a914d2ec20bb8e5f25a52f730384b803d95683250e0b88ac', - 'reqSigs': 1, - 'type': 'pubkeyhash', - 'addresses': [ - 'mzkD4nmQ8ixqxySdBgsXTpgvAMK5iRZpNK' - ], - }, - 'spentHeight': null, - 'spentIndex': null, - 'spentTxId': null - }, - { - 'value': '0.00289829', - 'n': 2, - 'scriptPubKey': { - 'asm': 'OP_DUP OP_HASH160 583df9fa56ad961051e00ca93e68dfaf1eab9ec5 OP_EQUALVERIFY OP_CHECKSIG', - 'hex': '76a914583df9fa56ad961051e00ca93e68dfaf1eab9ec588ac', - 'reqSigs': 1, - 'type': 'pubkeyhash', - 'addresses': [ - 'moZY18rGNmh4YCPeugtGW46AkkWMQttBUD' - ] - }, - 'spentHeight': null, - 'spentIndex': null, - 'spentTxId': null + } } ], 'blockhash': '0000000000000041ddc94ecf4f86a456a83b2e320c36c6f0c13ff92c7e75f013', @@ -508,43 +459,20 @@ describe('Addresses', function() { 'time': 1441116143, 'blocktime': 1441116143, 'valueOut': 0.53829829, - 'size': 470, - 'valueIn': 0.53839829, - 'fees': 0.0001, - 'firstSeenTs': 1441108193 - } - ] - }; - - var todos = { - 'items': [ - { - 'vout': [ - { - 'scriptPubKey': { - 'reqSigs': 1, - } - }, - { - 'scriptPubKey': { - 'reqSigs': 1, - } - }, - { - 'scriptPubKey': { - 'reqSigs': 1, - } - } - ], - 'firstSeenTs': 1441108193 + 'size': 134 } ] }; var node = { - getAddressHistory: sinon.stub().callsArgWith(2, null, txinfos2), - services: { address: {}, block: { getTip: sinon.stub().returns({ height: 534232 }) } }, - network: 'testnet' + services: { + address: { + getAddressHistory: sinon.stub().callsArgWith(2, null, txinfos2), + }, + block: { + getTip: sinon.stub().returns({ height: 534232 }) + } + } }; var addresses = new AddressController(node); @@ -557,14 +485,14 @@ describe('Addresses', function() { var res = { jsonp: function(data) { - var merged = _.merge(data, todos); - should(merged).eql(insight); + should(data).eql(insight); done(); } }; addresses.multitxs(req, res); }); + it('should have trimmed data', function(done) { var insight = { 'totalItems': 1, @@ -572,65 +500,26 @@ describe('Addresses', function() { 'to': 1, 'items': [ { - 'txid': '63b68becb0e514b32317f4b29a5cf0627d4087e54ac17f686fcb1d9a27680f73', + 'txid': '9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5', 'version': 1, 'locktime': 0, + 'isCoinBase': true, 'vin': [ { - 'txid': 'ea97726ffc529808094ae5568342267931a058375a20147535a0d095837079f3', - 'vout': 1, + 'coinbase': '04ffff001d010b', 'sequence': 4294967295, - 'n': 0, - 'addr': 'moFfnRwt77pApKnnU6m5uocFaa43aAYpt5', - 'valueSat': 53540000, - 'value': 0.5354, - 'doubleSpentTxID': null - }, - { - 'txid': '980a9cc2dbc2d3464eb9900ae6d579a03045408563320f62d99316c3d4ff58b7', - 'vout': 2, - 'sequence': 4294967295, - 'n': 1, - 'addr': 'n1XJBAyU4hNR4xRtY3UxnmAteoJX83p5qv', - 'valueSat': 299829, - 'value': 0.00299829, - 'doubleSpentTxID': null + 'n': 0 } ], 'vout': [ { - 'value': '0.00220000', + 'value': '50.00000000', 'n': 0, 'scriptPubKey': { - 'hex': '76a914b9bbd76588d9e4e09f0369a9aa0b2749a11c4e8d88ac', - 'reqSigs': 1, + 'hex': '41047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77ac', 'type': 'pubkeyhash', 'addresses': [ - 'mxT2KzTUQvsaYYothDtjcdvyAdaHA9ofMp' - ] - } - }, - { - 'value': '0.53320000', - 'n': 1, - 'scriptPubKey': { - 'hex': '76a914d2ec20bb8e5f25a52f730384b803d95683250e0b88ac', - 'reqSigs': 1, - 'type': 'pubkeyhash', - 'addresses': [ - 'mzkD4nmQ8ixqxySdBgsXTpgvAMK5iRZpNK' - ], - } - }, - { - 'value': '0.00289829', - 'n': 2, - 'scriptPubKey': { - 'hex': '76a914583df9fa56ad961051e00ca93e68dfaf1eab9ec588ac', - 'reqSigs': 1, - 'type': 'pubkeyhash', - 'addresses': [ - 'moZY18rGNmh4YCPeugtGW46AkkWMQttBUD' + '1HLoD9E4SDFFPDiYfNYnkBLQ85Y51J3Zb1' ] } } @@ -641,43 +530,20 @@ describe('Addresses', function() { 'time': 1441116143, 'blocktime': 1441116143, 'valueOut': 0.53829829, - 'size': 470, - 'valueIn': 0.53839829, - 'fees': 0.0001, - 'firstSeenTs': 1441108193 - } - ] - }; - - var todos = { - 'items': [ - { - 'vout': [ - { - 'scriptPubKey': { - 'reqSigs': 1, - } - }, - { - 'scriptPubKey': { - 'reqSigs': 1, - } - }, - { - 'scriptPubKey': { - 'reqSigs': 1, - } - } - ], - 'firstSeenTs': 1441108193 + 'size': 134 } ] }; var node = { - getAddressHistory: sinon.stub().callsArgWith(2, null, txinfos2), - services: { block: { getTip: sinon.stub().returns({ height: 534232 }) }, address: {} }, - network: 'testnet' + services: { + address: { + getAddressHistory: sinon.stub().callsArgWith(2, null, txinfos2), + }, + block: { + getTip: sinon.stub().returns({ height: 534232 }) + } + } }; var addresses = new AddressController(node); @@ -690,8 +556,7 @@ describe('Addresses', function() { var res = { jsonp: function(data) { - var merged = _.merge(data, todos); - should(merged).eql(insight); + should(data).eql(insight); done(); } }; @@ -700,6 +565,7 @@ describe('Addresses', function() { }); }); describe('#_getTransformOptions', function() { + it('will return false with value of string "0"', function() { var node = { services: { address: {}, block: {} } }; var addresses = new AddressController(node); @@ -717,6 +583,7 @@ describe('Addresses', function() { noSpent: false }); }); + it('will return true with value of string "1"', function() { var node = { services: { address: {}, block: {} } }; var addresses = new AddressController(node); @@ -734,6 +601,7 @@ describe('Addresses', function() { noSpent: true }); }); + it('will return true with value of number "1"', function() { var node = { services: { address: {}, block: {} } }; var addresses = new AddressController(node); diff --git a/test/blocks.js b/test/blocks.js index f88cdec..a52eb8d 100644 --- a/test/blocks.js +++ b/test/blocks.js @@ -3,15 +3,14 @@ var should = require('should'); var sinon = require('sinon'); var BlockController = require('../lib/blocks'); -var bitcore = require('bitcore-lib'); -var _ = require('lodash'); +var bcoin = require('bcoin'); var blocks = require('./data/blocks.json'); var blockIndexes = { '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7': { hash: '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7', - chainWork: '0000000000000000000000000000000000000000000000054626b1839ade284a', + chainwork: '0000000000000000000000000000000000000000000000054626b1839ade284a', prevHash: '00000000000001a55f3214e9172eb34b20e0bc5bd6b8007f3f149fca2c8991a4', nextHash: '000000000001e866a8057cde0c650796cb8a59e0e6038dc31c69d7ca6649627d', confirmations: 119, @@ -51,7 +50,7 @@ describe('Blocks', function() { 'size': 1011, 'height': 533974, 'version': 536870919, - 'merkleroot': 'b06437355844b8178173f3e18ca141472e4b0861daa81ef0f701cf9e51f0283e', + 'merkleroot': '3e28f0519ecf01f7f01ea8da61084b2e4741a18ce1f3738117b84458353764b0', 'tx': [ '25a988e54b02e0e5df146a0f8fa7b9db56210533a9f04bdfda5f4ceb6f77aadd', 'b85334bf2df35c6dd5b294efe92ffc793a78edff75a2ca666fc296ffb04bbba0', @@ -59,26 +58,28 @@ describe('Blocks', function() { ], 'time': 1440987503, 'nonce': 1868753784, - 'bits': '1a0cf267', + 'bits': 437056103, 'difficulty': 1295829.93087696, 'chainwork': '0000000000000000000000000000000000000000000000054626b1839ade284a', 'previousblockhash': '00000000000001a55f3214e9172eb34b20e0bc5bd6b8007f3f149fca2c8991a4', - 'nextblockhash': '000000000001e866a8057cde0c650796cb8a59e0e6038dc31c69d7ca6649627d', - 'reward': 12.5, + 'nextblockhash': null, + 'reward': null, 'isMainChain': true, 'poolInfo': {} }; - var bitcoreBlock = bitcore.Block.fromBuffer(new Buffer(blocks['0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7'], 'hex')); + var bcoinBlock = bcoin.block.fromRaw(blocks['0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7'], 'hex'); var node = { log: sinon.stub(), - getBlock: sinon.stub().callsArgWith(1, null, bitcoreBlock), services: { - bitcoind: { + header: { getBlockHeader: sinon.stub().callsArgWith(1, null, blockIndexes['0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7']), - isMainChain: sinon.stub().returns(true), - height: 534092 + getCurrentDifficulty: sinon.stub().returns(1295829.93087696) + }, + block: { + getBlock: sinon.stub().callsArgWith(1, null, bcoinBlock), + getTip: sinon.stub().returns({ height: 533974+118 }) } } }; @@ -102,19 +103,24 @@ describe('Blocks', function() { }); it('block pool info should be correct', function(done) { - var block = bitcore.Block.fromString(blocks['000000000000000004a118407a4e3556ae2d5e882017e7ce526659d8073f13a4']); + var block = bcoin.block.fromRaw(blocks['000000000000000004a118407a4e3556ae2d5e882017e7ce526659d8073f13a4'], 'hex'); var node = { log: sinon.stub(), - getBlock: sinon.stub().callsArgWith(1, null, block), services: { - bitcoind: { + header: { getBlockHeader: sinon.stub().callsArgWith(1, null, blockIndexes['000000000000000004a118407a4e3556ae2d5e882017e7ce526659d8073f13a4']), isMainChain: sinon.stub().returns(true), + getCurrentDifficulty: sinon.stub().returns('aa'), height: 534092 + }, + block: { + getBlock: sinon.stub().callsArgWith(1, null, block), + getTip: sinon.stub().returns({ height: 123 }) } } }; var controller = new BlockController({node: node}); + var hash = '000000000000000004a118407a4e3556ae2d5e882017e7ce526659d8073f13a4'; var req = { params: { blockHash: hash @@ -123,109 +129,20 @@ describe('Blocks', function() { var res = {}; var next = function() { should.exist(req.block); - var block = req.block; req.block.poolInfo.poolName.should.equal('Discus Fish'); req.block.poolInfo.url.should.equal('http://f2pool.com/'); done(); }; - var hash = '000000000000000004a118407a4e3556ae2d5e882017e7ce526659d8073f13a4'; - controller.block(req, res, next); }); }); - describe('/blocks route', function() { - - var insight = { - 'blocks': [ - { - 'height': 533951, - 'size': 206, - 'hash': '000000000008fbb2e358e382a6f6948b2da24563bba183af447e6e2542e8efc7', - 'time': 1440978683, - 'txlength': 1, - 'poolInfo': { - 'poolName': 'AntMiner', - 'url': 'https://bitmaintech.com/' - } - }, - { - 'height': 533950, - 'size': 206, - 'hash': '00000000000006bd8fe9e53780323c0e85719eca771022e1eb6d10c62195c441', - 'time': 1440977479, - 'txlength': 1, - 'poolInfo': { - 'poolName': 'AntMiner', - 'url': 'https://bitmaintech.com/' - } - } - ], - 'length': 2, - 'pagination': { - 'current': '2015-08-30', - 'currentTs': 1440979199, - 'isToday': false, - 'more': false, - 'next': '2015-08-31', - 'prev': '2015-08-29' - } - }; - - var stub = sinon.stub(); - stub.onFirstCall().callsArgWith(1, null, new Buffer(blocks['000000000008fbb2e358e382a6f6948b2da24563bba183af447e6e2542e8efc7'], 'hex')); - stub.onSecondCall().callsArgWith(1, null, new Buffer(blocks['00000000000006bd8fe9e53780323c0e85719eca771022e1eb6d10c62195c441'], 'hex')); - - var hashes = [ - '00000000000006bd8fe9e53780323c0e85719eca771022e1eb6d10c62195c441', - '000000000008fbb2e358e382a6f6948b2da24563bba183af447e6e2542e8efc7' - ]; - var node = { - log: sinon.stub(), - services: { - bitcoind: { - getRawBlock: stub, - getBlockHeader: function(hash, callback) { - callback(null, blockIndexes[hash]); - }, - getBlockHashesByTimestamp: sinon.stub().callsArgWith(2, null, hashes) - } - } - }; - - it('should have correct data', function(done) { - var blocks = new BlockController({node: node}); - - var req = { - query: { - limit: 2, - blockDate: '2015-08-30' - } - }; - - var res = { - jsonp: function(data) { - should(data).eql(insight); - done(); - } - }; - - blocks.list(req, res); - }); - }); - describe('/block-index/:height route', function() { var node = { log: sinon.stub(), - services: { - bitcoind: { - getBlockHeader: function(height, callback) { - callback(null, blockIndexes[height]); - } - } - } + services: { header: { getBlockHeader: sinon.stub().callsArgWith(1, null, { hash: '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7' }) }, block: {}, timestamp: {} }, }; it('should have correct data', function(done) { @@ -255,6 +172,7 @@ describe('Blocks', function() { describe('#getBlockReward', function() { var node = { + services: { header: {}, block: {}, timestamp: {} }, log: sinon.stub() }; var blocks = new BlockController({node: node}); diff --git a/test/transactions.js b/test/transactions.js index dfbe09a..d0553e6 100644 --- a/test/transactions.js +++ b/test/transactions.js @@ -3,194 +3,104 @@ var should = require('should'); var sinon = require('sinon'); var bitcore = require('bitcore-lib'); var TxController = require('../lib/transactions'); +var bcoin = require('bcoin'); var _ = require('lodash'); describe('Transactions', function() { + describe('/tx/:txid', function() { + it('should have correct data', function(done) { + var insight = { - 'txid': 'b85334bf2df35c6dd5b294efe92ffc793a78edff75a2ca666fc296ffb04bbba0', - 'version': 1, - 'locktime': 0, - 'vin': [ + "txid": "eac9723230b8b632117ac3d75288d6f8eb81cf1ea553eb9fd42562d5f767d54a", + "version": 1, + "locktime": 0, + "vin": [ { - 'txid': '87c9b0f27571fff14b8c2d69e55614eacedd0f59fcc490b721320f9dae145aad', - 'vout': 0, - 'scriptSig': { - 'asm': '30450221008e5df62719cd92d7b137d00bbd27f153f2909bcad3a300960bc1020ec6d5e961022039df51600ff4fb5da5a794d1648c6b47c1f7d277fd5877fb5e52a730a3595f8c01 04eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307', - 'hex': '4830450221008e5df62719cd92d7b137d00bbd27f153f2909bcad3a300960bc1020ec6d5e961022039df51600ff4fb5da5a794d1648c6b47c1f7d277fd5877fb5e52a730a3595f8c014104eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307' + "txid": "46e58a68bb9ec9b458a9599dc2bac1e1fa09ad15c29c7f923c8f6f0aa33d6456", + "vout": 1, + "sequence": 4294967295, + "n": 0, + "scriptSig": { + "hex": "47304402203ddb49db43074b421ec6d5604ae91aac37f4715139e0c83ea1145379e8cbf02702207fbc92c4038ad501989b097844ae4e337c9388f0713110620b40e582b85fdff3012102cd90aa18ec8e3b35c0447ffc713c945cb837429d33d075d1b0f050c72ea838d2", + "asm": "304402203ddb49db43074b421ec6d5604ae91aac37f4715139e0c83ea1145379e8cbf02702207fbc92c4038ad501989b097844ae4e337c9388f0713110620b40e582b85fdff301 02cd90aa18ec8e3b35c0447ffc713c945cb837429d33d075d1b0f050c72ea838d2" }, - 'sequence': 4294967295, - 'n': 0, - 'addr': 'mqdofsXHpePPGBFXuwwypAqCcXi48Xhb2f', - 'valueSat': 18535505, - 'value': 0.18535505, - 'doubleSpentTxID': null, - 'isConfirmed': true, - 'confirmations': 242, - 'unconfirmedInput': false - }, - { - 'txid': 'd8a10aaedf3dd33b5ddf8979273f3dbf61e4638d1aa6a93c59ea22bc65ac2196', - 'vout': 0, - 'scriptSig': { - 'asm': '30440220761464d7bab9515d92260762a97af82a9b25d202d8f7197b1aaec81b6fed541f022059f99606de6b06e17b2cd102dceb3807ebdd9e777a5b77c9a0b3672f5eabcb3101 04eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307', - 'hex': '4730440220761464d7bab9515d92260762a97af82a9b25d202d8f7197b1aaec81b6fed541f022059f99606de6b06e17b2cd102dceb3807ebdd9e777a5b77c9a0b3672f5eabcb31014104eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307' - }, - 'sequence': 4294967295, - 'n': 1, - 'addr': 'mqdofsXHpePPGBFXuwwypAqCcXi48Xhb2f', - 'valueSat': 16419885, - 'value': 0.16419885, - 'doubleSpentTxID': null, - 'isConfirmed': true, - 'confirmations': 242, - 'unconfirmedInput': false + "addr": "1NqgMfGUeELP2BfxD4hQuJSRq2d3DVJcCi", + "valueSat": 1546063700, + "value": 15.460637, + "doubleSpentTxID": null } ], - 'vout': [ + "vout": [ { - 'value': '0.21247964', - 'n': 0, - 'scriptPubKey': { - 'asm': 'OP_DUP OP_HASH160 4b7b335f978f130269fe661423258ae9642df8a1 OP_EQUALVERIFY OP_CHECKSIG', - 'hex': '76a9144b7b335f978f130269fe661423258ae9642df8a188ac', - 'reqSigs': 1, - 'type': 'pubkeyhash', - 'addresses': [ - 'mnQ4ZaGessNgdxmWPxbTHcfx4b8R6eUr1X' - ] - }, - 'spentTxId': null, - 'spentIndex': null, - 'spentHeight': null - }, - { - 'value': '0.13677426', - 'n': 1, - 'scriptPubKey': { - 'asm': 'OP_DUP OP_HASH160 6efcf883b4b6f9997be9a0600f6c095fe2bd2d92 OP_EQUALVERIFY OP_CHECKSIG', - 'hex': '76a9146efcf883b4b6f9997be9a0600f6c095fe2bd2d9288ac', - 'reqSigs': 1, - 'type': 'pubkeyhash', - 'addresses': [ - 'mqdofsXHpePPGBFXuwwypAqCcXi48Xhb2f' - ] - }, - 'spentTxId': '614fe1708825f9c21732394e4784cc6808ac1d8b939736bfdead970567561eec', - 'spentIndex': 1, - 'spentHeight': 10, - 'spentTs': 1440997099 - } - ], - 'blockhash': '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7', - 'blockheight': 533974, - 'confirmations': 230, - 'time': 1440987503, - 'blocktime': 1440987503, - 'valueOut': 0.3492539, - 'size': 437, - 'valueIn': 0.3495539, - 'fees': 0.0003 - }; - - var spentTxId = '614fe1708825f9c21732394e4784cc6808ac1d8b939736bfdead970567561eec'; - var spentIndex = 1; - var detailedTransaction = { - hex: '7b5485d3628922f004f470f497f6a83f6df4df347e1bce15831a964623f8072b565f7c7bc5dcbc717c6e2a2301a2f6b4a19e65042ad88c9f5d037628de38603c4f137f625e135691e2bd0169cab74e1368abe858f3c3d116e9d13c4c85ead129d9edf0245a3fb1b35561bd230607dca0dcaf3cffc735a3982d8384a1ecc5d622a7bb4db8b5d47d061701978b1f45e2e39946d66c3394f8a20b8ac8c931a6786f761da2d0f3fa2c7c93edee9f2a94de7c47510498767c3d87afe68815bd6058710bf5d8c850a5d20fc217943d9c00da58a4908d92a0912578247746f2086e54cb7b81b6a9e3cc1741457e956d41bdeaae06c441db96ec39a2d17147dd8f468eeaeaaa78dc2e53d66188a791c46b2a4965639ad72a2b90ee52786e36db1a8cf924346b105a40b41a3027dae657782ef7e8b56d6da86062184cb5366d4886cd2ce27471d9d62d1df447f2e5a9641e1f8d1f2b628054d3bd915bf7932bcec6f2dd4965e2406b1dba445b5493ee475757de332618220318dd806b880a7364370c5c0c3b736a653f97b2901fdb5cf4b5b2230b09b2d7bd324a392633d51c598765f9bd286421239a1f25db34a9a61f645eb601e59f10fc1b', - hash: 'b85334bf2df35c6dd5b294efe92ffc793a78edff75a2ca666fc296ffb04bbba0', - version: 1, - blockHash: '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7', - height: 533974, - blockTimestamp: 1440987503, - inputSatoshis: 34955390, - outputSatoshis: 34925390, - feeSatoshis: 30000, - inputs: [ - { - address: 'mqdofsXHpePPGBFXuwwypAqCcXi48Xhb2f', - prevTxId: '87c9b0f27571fff14b8c2d69e55614eacedd0f59fcc490b721320f9dae145aad', - outputIndex: 0, - sequence: 4294967295, - script: '4830450221008e5df62719cd92d7b137d00bbd27f153f2909bcad3a300960bc1020ec6d5e961022039df51600ff4fb5da5a794d1648c6b47c1f7d277fd5877fb5e52a730a3595f8c014104eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307', - scriptAsm: '30450221008e5df62719cd92d7b137d00bbd27f153f2909bcad3a300960bc1020ec6d5e961022039df51600ff4fb5da5a794d1648c6b47c1f7d277fd5877fb5e52a730a3595f8c01 04eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307', - satoshis: 18535505, - }, - { - address: 'mqdofsXHpePPGBFXuwwypAqCcXi48Xhb2f', - prevTxId: 'd8a10aaedf3dd33b5ddf8979273f3dbf61e4638d1aa6a93c59ea22bc65ac2196', - outputIndex: 0, - sequence: 4294967295, - script: '4730440220761464d7bab9515d92260762a97af82a9b25d202d8f7197b1aaec81b6fed541f022059f99606de6b06e17b2cd102dceb3807ebdd9e777a5b77c9a0b3672f5eabcb31014104eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307', - scriptAsm: '30440220761464d7bab9515d92260762a97af82a9b25d202d8f7197b1aaec81b6fed541f022059f99606de6b06e17b2cd102dceb3807ebdd9e777a5b77c9a0b3672f5eabcb3101 04eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307', - satoshis: 16419885, - } - ], - outputs: [ - { - satoshis: 21247964, - script: '76a9144b7b335f978f130269fe661423258ae9642df8a188ac', - scriptAsm: 'OP_DUP OP_HASH160 4b7b335f978f130269fe661423258ae9642df8a1 OP_EQUALVERIFY OP_CHECKSIG', - address: 'mnQ4ZaGessNgdxmWPxbTHcfx4b8R6eUr1X' - }, - { - address: 'mqdofsXHpePPGBFXuwwypAqCcXi48Xhb2f', - satoshis: 13677426, - scriptAsm: 'OP_DUP OP_HASH160 6efcf883b4b6f9997be9a0600f6c095fe2bd2d92 OP_EQUALVERIFY OP_CHECKSIG', - script: '76a9146efcf883b4b6f9997be9a0600f6c095fe2bd2d9288ac', - spentTxId: spentTxId, - spentIndex: spentIndex, - spentHeight: 10 - } - ], - locktime: 0 - }; - - var todos = { - vin: [ - { - isConfirmed: true, - confirmations: 242, - unconfirmedInput: false - }, - { - isConfirmed: true, - confirmations: 242, - unconfirmedInput: false - } - ], - vout: [ - { - scriptPubKey: { - reqSigs: 1 + "value": "0.37100000", + "n": 0, + "scriptPubKey": { + "hex": "76a914bc345e0e0e5b0dbddb7b35ef3430fedd528dd1b788ac", + "asm": "OP_DUP OP_HASH160 bc345e0e0e5b0dbddb7b35ef3430fedd528dd1b7 OP_EQUALVERIFY OP_CHECKSIG", + "addresses": [ + "1JA8mcfrBv1YYsASAp9jtohm8x2q7LnUhs" + ], + "type": "pubkeyhash" } }, { - scriptPubKey: { - reqSigs: 1 - }, - spentTs: 1440997099 + "value": "15.08763700", + "n": 1, + "scriptPubKey": { + "hex": "76a914c2c74d7519d4425fc1a253f066d980164341554a88ac", + "asm": "OP_DUP OP_HASH160 c2c74d7519d4425fc1a253f066d980164341554a OP_EQUALVERIFY OP_CHECKSIG", + "addresses": [ + "1Jktr121Hm63qtWBMV8dCNJNW2KtWXy4fp" + ], + "type": "pubkeyhash" + } } - ] + ], + "blockhash": "0000000000000000009d2e9b7a984d55c6c99ba62f98e9bc7dad8b1e779045a3", + "blockheight": 481763, + "confirmations": 4, + "time": 1503507151, + "blocktime": 1503507151, + "valueOut": 15.458637, + "size": 225, + "valueIn": 15.460637, + "fees": 0.002 }; + var bcoinTx = bcoin.tx.fromRaw('010000000156643da30a6f8f3c927f9cc215ad09fae1c1bac29d59a958b4c99ebb688ae546010000006a47304402203ddb49db43074b421ec6d5604ae91aac37f4715139e0c83ea1145379e8cbf02702207fbc92c4038ad501989b097844ae4e337c9388f0713110620b40e582b85fdff3012102cd90aa18ec8e3b35c0447ffc713c945cb837429d33d075d1b0f050c72ea838d2ffffffff02e0193602000000001976a914bc345e0e0e5b0dbddb7b35ef3430fedd528dd1b788ac34e8ed59000000001976a914c2c74d7519d4425fc1a253f066d980164341554a88ac00000000', 'hex'); + + bcoinTx.__blockhash = '0000000000000000009d2e9b7a984d55c6c99ba62f98e9bc7dad8b1e779045a3'; + bcoinTx.__height = 481763; + bcoinTx.__inputValues = [ 1546063700 ]; + bcoinTx.__timestamp = 1503507151; + bcoinTx.inputSatoshis = [ 1546063700 ]; + bcoinTx.feeSatoshis = 200000; + bcoinTx.outputSatoshis = 1545863700; + var node = { - services: { block: { getTip: sinon.stub().returns({ height: 534203 }) } }, - getDetailedTransaction: sinon.stub().callsArgWith(1, null, detailedTransaction), - network: 'testnet' + services: { + block: { + getTip: sinon.stub().returns({ height: 481766 }) + }, + transaction: { + getDetailedTransaction: sinon.stub().callsArgWith(1, null, bcoinTx) + } + } }; var transactions = new TxController(node); - var txid = 'b85334bf2df35c6dd5b294efe92ffc793a78edff75a2ca666fc296ffb04bbba0'; + var txid = 'eac9723230b8b632117ac3d75288d6f8eb81cf1ea553eb9fd42562d5f767d54a'; var req = { params: { txid: txid } }; + var res = {}; var next = function() { - var merged = _.merge(req.transaction, todos); - should(merged).eql(insight); + should(req.transaction).eql(insight); done(); }; @@ -199,413 +109,88 @@ describe('Transactions', function() { }); describe('/txs', function() { + var sandbox = sinon.sandbox.create(); + afterEach(function() { sandbox.restore(); }); + it('by block hash', function(done) { + var blockOverview = { hash: '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7', height: 533974, chainWork: '0000000000000000000000000000000000000000000000054626b1839ade284a', prevHash: '00000000000001a55f3214e9172eb34b20e0bc5bd6b8007f3f149fca2c8991a4', txids: [ - '25a988e54b02e0e5df146a0f8fa7b9db56210533a9f04bdfda5f4ceb6f77aadd', - 'b85334bf2df35c6dd5b294efe92ffc793a78edff75a2ca666fc296ffb04bbba0', - '2e01c7a4a0e335112236b711c4aaddd02e8dc59ba2cda416e8f80ff06dddd7e1' + '9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5' ] }; - var transactionDetails = { - '25a988e54b02e0e5df146a0f8fa7b9db56210533a9f04bdfda5f4ceb6f77aadd': { - hex: '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff2303d6250800feb0aae355fe263600000963676d696e6572343208ae5800000000000000ffffffff01c018824a000000001976a91468bedce8982d25c3b6b03f6238cbad00378b8ead88ac00000000', - coinbase: true, - version: 1, - blockTimestamp: 1440987503, - blockHash: '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7', - height: 533974, - inputSatoshis: 0, - outputSatoshis: 1250040000, - feeSatoshis: 0, - locktime: 0, - hash: '25a988e54b02e0e5df146a0f8fa7b9db56210533a9f04bdfda5f4ceb6f77aadd', - inputs: [ - { - script: '03d6250800feb0aae355fe263600000963676d696e6572343208ae5800000000000000', - sequence: 4294967295 - } - ], - outputs: [ - { - address: 'mq4oDPjmNWnBxbzx7qouzhpCSTMePUtYDF', - script: '76a91468bedce8982d25c3b6b03f6238cbad00378b8ead88ac', - scriptAsm: 'OP_DUP OP_HASH160 68bedce8982d25c3b6b03f6238cbad00378b8ead OP_EQUALVERIFY OP_CHECKSIG', - satoshis: 1250040000 - } - ] - }, - 'b85334bf2df35c6dd5b294efe92ffc793a78edff75a2ca666fc296ffb04bbba0': { - hex: '0100000002ad5a14ae9d0f3221b790c4fc590fddceea1456e5692d8c4bf1ff7175f2b0c987000000008b4830450221008e5df62719cd92d7b137d00bbd27f153f2909bcad3a300960bc1020ec6d5e961022039df51600ff4fb5da5a794d1648c6b47c1f7d277fd5877fb5e52a730a3595f8c014104eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307ffffffff9621ac65bc22ea593ca9a61a8d63e461bf3d3f277989df5d3bd33ddfae0aa1d8000000008a4730440220761464d7bab9515d92260762a97af82a9b25d202d8f7197b1aaec81b6fed541f022059f99606de6b06e17b2cd102dceb3807ebdd9e777a5b77c9a0b3672f5eabcb31014104eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307ffffffff02dc374401000000001976a9144b7b335f978f130269fe661423258ae9642df8a188ac72b3d000000000001976a9146efcf883b4b6f9997be9a0600f6c095fe2bd2d9288ac00000000', - inputSatoshis: 34955390, - outputSatoshis: 34925390, - feeSatoshis: 30000, - version: 1, - hash: 'b85334bf2df35c6dd5b294efe92ffc793a78edff75a2ca666fc296ffb04bbba0', - blockTimestamp: 1440987503, - height: 533974, - blockHash: '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7', - locktime: 0, - inputs: [ - { - satoshis: 18535505, - address: 'mqdofsXHpePPGBFXuwwypAqCcXi48Xhb2f', - script: '4830450221008e5df62719cd92d7b137d00bbd27f153f2909bcad3a300960bc1020ec6d5e961022039df51600ff4fb5da5a794d1648c6b47c1f7d277fd5877fb5e52a730a3595f8c014104eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307', - scriptAsm: '30450221008e5df62719cd92d7b137d00bbd27f153f2909bcad3a300960bc1020ec6d5e961022039df51600ff4fb5da5a794d1648c6b47c1f7d277fd5877fb5e52a730a3595f8c01 04eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307', - prevTxId: '87c9b0f27571fff14b8c2d69e55614eacedd0f59fcc490b721320f9dae145aad', - outputIndex: 0, - sequence: 4294967295 - }, - { - address: 'mqdofsXHpePPGBFXuwwypAqCcXi48Xhb2f', - script: '4730440220761464d7bab9515d92260762a97af82a9b25d202d8f7197b1aaec81b6fed541f022059f99606de6b06e17b2cd102dceb3807ebdd9e777a5b77c9a0b3672f5eabcb31014104eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307', - scriptAsm: '30440220761464d7bab9515d92260762a97af82a9b25d202d8f7197b1aaec81b6fed541f022059f99606de6b06e17b2cd102dceb3807ebdd9e777a5b77c9a0b3672f5eabcb3101 04eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307', - satoshis: 16419885, - sequence: 4294967295, - prevTxId: 'd8a10aaedf3dd33b5ddf8979273f3dbf61e4638d1aa6a93c59ea22bc65ac2196', - outputIndex: 0 - } - ], - outputs: [ - { - address: 'mnQ4ZaGessNgdxmWPxbTHcfx4b8R6eUr1X', - script: '76a9144b7b335f978f130269fe661423258ae9642df8a188ac', - scriptAsm: 'OP_DUP OP_HASH160 4b7b335f978f130269fe661423258ae9642df8a1 OP_EQUALVERIFY OP_CHECKSIG', - satoshis: 21247964 - }, - { - script: '76a9146efcf883b4b6f9997be9a0600f6c095fe2bd2d9288ac', - scriptAsm: 'OP_DUP OP_HASH160 6efcf883b4b6f9997be9a0600f6c095fe2bd2d92 OP_EQUALVERIFY OP_CHECKSIG', - address: 'mqdofsXHpePPGBFXuwwypAqCcXi48Xhb2f', - satoshis: 13677426, - spentTxId: '614fe1708825f9c21732394e4784cc6808ac1d8b939736bfdead970567561eec', - spentIndex: 1, - spentHeight: 200 - } - ] - }, - '2e01c7a4a0e335112236b711c4aaddd02e8dc59ba2cda416e8f80ff06dddd7e1': { - hex: '0100000002060d3cb6dfb7ffe85e2908010fea63190c9707e96fc7448128eb895b5e222771030000006b483045022100f67cffc0ae23adb236ff3edb4a9736e277605db30cc7708dfab8cf1e1483bbce022052396aa5d664ec1cb65992c423fd9a17e94dc7af328d2d559e90746dd195ca5901210346134da14907581d8190d3980caaf46d95e4eb9c1ca8e70f1fc6007fefb1909dfeffffff7b2d8a8263cffbdb722e2a5c74166e6f2258634e277c0b08f51b578b667e2fba000000006a473044022077222a91cda23af69179377c62d84a176fb12caff6c5cbf6ae9e5957ff3b1afe0220768edead76819228dcba18cca3c9a5a5d4c32919720f21df21a297ba375bbe5c012103371ea5a4dfe356b3ea4042a537d7ab7ee0faabd43e21b6cc076fda2240629eeefeffffff02209a1d00000000001976a9148e451eec7ca0a1764b4ab119274efdd2727b3c8588ac40420f00000000001976a914d0fce8f064cd1059a6a11501dd66fe42368572b088accb250800', - blockHash: '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7', - blockTimestamp: 1440987503, - height: 533974, - locktime: 533963, - inputSatoshis: 2950000, - outputSatoshis: 2940000, - feeSatoshis: 10000, - version: 1, - hash: '2e01c7a4a0e335112236b711c4aaddd02e8dc59ba2cda416e8f80ff06dddd7e1', - inputs: [ - { - address: 'mgZK8zpudWoAaAwpLQSgc9t9PJJyEBpBdJ', - satoshis: 990000, - script: '483045022100f67cffc0ae23adb236ff3edb4a9736e277605db30cc7708dfab8cf1e1483bbce022052396aa5d664ec1cb65992c423fd9a17e94dc7af328d2d559e90746dd195ca5901210346134da14907581d8190d3980caaf46d95e4eb9c1ca8e70f1fc6007fefb1909d', - scriptAsm: '3045022100f67cffc0ae23adb236ff3edb4a9736e277605db30cc7708dfab8cf1e1483bbce022052396aa5d664ec1cb65992c423fd9a17e94dc7af328d2d559e90746dd195ca5901 0346134da14907581d8190d3980caaf46d95e4eb9c1ca8e70f1fc6007fefb1909d', - sequence: 4294967294, - outputIndex: 3, - prevTxId: '7127225e5b89eb288144c76fe907970c1963ea0f0108295ee8ffb7dfb63c0d06' - }, - { - address: 'n4oM7bPuC4ZPdCEDvtw9xGYQC7jmi5S6F4', - satoshis: 1960000, - script: '473044022077222a91cda23af69179377c62d84a176fb12caff6c5cbf6ae9e5957ff3b1afe0220768edead76819228dcba18cca3c9a5a5d4c32919720f21df21a297ba375bbe5c012103371ea5a4dfe356b3ea4042a537d7ab7ee0faabd43e21b6cc076fda2240629eee', - scriptAsm: '3044022077222a91cda23af69179377c62d84a176fb12caff6c5cbf6ae9e5957ff3b1afe0220768edead76819228dcba18cca3c9a5a5d4c32919720f21df21a297ba375bbe5c01 03371ea5a4dfe356b3ea4042a537d7ab7ee0faabd43e21b6cc076fda2240629eee', - prevTxId: 'ba2f7e668b571bf5080b7c274e6358226f6e16745c2a2e72dbfbcf63828a2d7b', - sequence: 4294967294, - outputIndex : 0 - } - ], - outputs: [ - { - spentTxId: '9a213b879da9073a9a30606f9046f35f36f268cbf03f6242993a97c4c07c00b9', - spentIndex: 1, - spentHeight: 200, - satoshis: 1940000, - script: '76a9148e451eec7ca0a1764b4ab119274efdd2727b3c8588ac', - scriptAsm: 'OP_DUP OP_HASH160 8e451eec7ca0a1764b4ab119274efdd2727b3c85 OP_EQUALVERIFY OP_CHECKSIG', - address: 'mtVD3tdifBNujYzZ5N7PgXfKk4Bc85tDKA' - }, - { - spentTxId: '418d3eb60275957b3456b96902e908abf962e71be4c4f09486564254664951bc', - spentIndex: 34, - spentHeight: 200, - script: '76a914d0fce8f064cd1059a6a11501dd66fe42368572b088ac', - scriptAsm: 'OP_DUP OP_HASH160 d0fce8f064cd1059a6a11501dd66fe42368572b0 OP_EQUALVERIFY OP_CHECKSIG', - address: 'mzZypShcs1B35udnkqeYeJy8rUdgHDDvKG', - satoshis: 1000000 - } - ] - } - }; + var bcoinTx = bcoin.tx.fromRaw('01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d010bffffffff0100f2052a010000004341047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77ac00000000', 'hex'); + + bcoinTx.__blockhash = '000000006a625f06636b8bb6ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd'; + bcoinTx.__height = 2; + bcoinTx.__inputValues = [ 1546063700 ]; + bcoinTx.__timestamp = 1231469744; + bcoinTx.inputSatoshis = [ 1546063700 ]; + bcoinTx.feeSatoshis = 0; + bcoinTx.outputSatoshis = 5000000000; var node = { - services: { block: { getTip: sinon.stub().returns({ height: 534209 }) } }, - getBlockOverview: sinon.stub().callsArgWith(1, null, blockOverview), - getDetailedTransaction: function(txid, callback) { - callback(null, transactionDetails[txid]); - }, - network: 'testnet' + + services: { + block: { + getTip: sinon.stub().returns({ height: 481773 }), + getBlockOverview: sinon.stub().callsArgWith(1, null, blockOverview), + }, + + transaction: { + getDetailedTransaction: sinon.stub().callsArgWith(2, null, bcoinTx) + } + } + }; var transactions = new TxController(node); var insight = { - 'pagesTotal': 1, - 'txs': [ + "pagesTotal": 1, + "txs": [ { - 'txid': '25a988e54b02e0e5df146a0f8fa7b9db56210533a9f04bdfda5f4ceb6f77aadd', - 'version': 1, - 'locktime': 0, - 'vin': [ + "txid": "9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5", + "version": 1, + "locktime": 0, + "vin": [ { - 'coinbase': '03d6250800feb0aae355fe263600000963676d696e6572343208ae5800000000000000', - 'sequence': 4294967295, - 'n': 0 + "coinbase": "04ffff001d010b", + "sequence": 4294967295, + "n": 0 } ], - 'vout': [ + "vout": [ { - 'value': '12.50040000', - 'n': 0, - 'scriptPubKey': { - 'asm': 'OP_DUP OP_HASH160 68bedce8982d25c3b6b03f6238cbad00378b8ead OP_EQUALVERIFY OP_CHECKSIG', - 'hex': '76a91468bedce8982d25c3b6b03f6238cbad00378b8ead88ac', - 'reqSigs': 1, - 'type': 'pubkeyhash', - 'addresses': [ - 'mq4oDPjmNWnBxbzx7qouzhpCSTMePUtYDF' - ] - }, - 'spentTxId': null, - 'spentIndex': null, - 'spentHeight': null - } - ], - 'blockhash': '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7', - 'blockheight': 533974, - 'confirmations': 236, - 'time': 1440987503, - 'blocktime': 1440987503, - 'isCoinBase': true, - 'valueOut': 12.5004, - 'size': 120 - }, - { - 'txid': 'b85334bf2df35c6dd5b294efe92ffc793a78edff75a2ca666fc296ffb04bbba0', - 'version': 1, - 'locktime': 0, - 'vin': [ - { - 'txid': '87c9b0f27571fff14b8c2d69e55614eacedd0f59fcc490b721320f9dae145aad', - 'vout': 0, - 'scriptSig': { - 'asm': '30450221008e5df62719cd92d7b137d00bbd27f153f2909bcad3a300960bc1020ec6d5e961022039df51600ff4fb5da5a794d1648c6b47c1f7d277fd5877fb5e52a730a3595f8c01 04eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307', - 'hex': '4830450221008e5df62719cd92d7b137d00bbd27f153f2909bcad3a300960bc1020ec6d5e961022039df51600ff4fb5da5a794d1648c6b47c1f7d277fd5877fb5e52a730a3595f8c014104eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307' - }, - 'sequence': 4294967295, - 'n': 0, - 'addr': 'mqdofsXHpePPGBFXuwwypAqCcXi48Xhb2f', - 'valueSat': 18535505, - 'value': 0.18535505, - 'doubleSpentTxID': null - }, - { - 'txid': 'd8a10aaedf3dd33b5ddf8979273f3dbf61e4638d1aa6a93c59ea22bc65ac2196', - 'vout': 0, - 'scriptSig': { - 'asm': '30440220761464d7bab9515d92260762a97af82a9b25d202d8f7197b1aaec81b6fed541f022059f99606de6b06e17b2cd102dceb3807ebdd9e777a5b77c9a0b3672f5eabcb3101 04eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307', - 'hex': '4730440220761464d7bab9515d92260762a97af82a9b25d202d8f7197b1aaec81b6fed541f022059f99606de6b06e17b2cd102dceb3807ebdd9e777a5b77c9a0b3672f5eabcb31014104eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307' - }, - 'sequence': 4294967295, - 'n': 1, - 'addr': 'mqdofsXHpePPGBFXuwwypAqCcXi48Xhb2f', - 'valueSat': 16419885, - 'value': 0.16419885, - 'doubleSpentTxID': null - } - ], - 'vout': [ - { - 'value': '0.21247964', - 'n': 0, - 'scriptPubKey': { - 'asm': 'OP_DUP OP_HASH160 4b7b335f978f130269fe661423258ae9642df8a1 OP_EQUALVERIFY OP_CHECKSIG', - 'hex': '76a9144b7b335f978f130269fe661423258ae9642df8a188ac', - 'reqSigs': 1, - 'type': 'pubkeyhash', - 'addresses': [ - 'mnQ4ZaGessNgdxmWPxbTHcfx4b8R6eUr1X' - ] - }, - 'spentTxId': null, - 'spentIndex': null, - 'spentHeight': null - }, - { - 'value': '0.13677426', - 'n': 1, - 'scriptPubKey': { - 'asm': 'OP_DUP OP_HASH160 6efcf883b4b6f9997be9a0600f6c095fe2bd2d92 OP_EQUALVERIFY OP_CHECKSIG', - 'hex': '76a9146efcf883b4b6f9997be9a0600f6c095fe2bd2d9288ac', - 'reqSigs': 1, - 'type': 'pubkeyhash', - 'addresses': [ - 'mqdofsXHpePPGBFXuwwypAqCcXi48Xhb2f' - ] - }, - 'spentTxId': '614fe1708825f9c21732394e4784cc6808ac1d8b939736bfdead970567561eec', - 'spentIndex': 1, - 'spentHeight': 200, - 'spentTs': 1440997099 - } - ], - 'blockhash': '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7', - 'blockheight': 533974, - 'confirmations': 236, - 'time': 1440987503, - 'blocktime': 1440987503, - 'valueOut': 0.3492539, - 'size': 437, - 'valueIn': 0.3495539, - 'fees': 0.0003 - }, - { - 'txid': '2e01c7a4a0e335112236b711c4aaddd02e8dc59ba2cda416e8f80ff06dddd7e1', - 'version': 1, - 'locktime': 533963, - 'vin': [ - { - 'txid': '7127225e5b89eb288144c76fe907970c1963ea0f0108295ee8ffb7dfb63c0d06', - 'vout': 3, - 'scriptSig': { - 'asm': '3045022100f67cffc0ae23adb236ff3edb4a9736e277605db30cc7708dfab8cf1e1483bbce022052396aa5d664ec1cb65992c423fd9a17e94dc7af328d2d559e90746dd195ca5901 0346134da14907581d8190d3980caaf46d95e4eb9c1ca8e70f1fc6007fefb1909d', - 'hex': '483045022100f67cffc0ae23adb236ff3edb4a9736e277605db30cc7708dfab8cf1e1483bbce022052396aa5d664ec1cb65992c423fd9a17e94dc7af328d2d559e90746dd195ca5901210346134da14907581d8190d3980caaf46d95e4eb9c1ca8e70f1fc6007fefb1909d' - }, - 'sequence': 4294967294, - 'n': 0, - 'addr': 'mgZK8zpudWoAaAwpLQSgc9t9PJJyEBpBdJ', - 'valueSat': 990000, - 'value': 0.0099, - 'doubleSpentTxID': null - }, - { - 'txid': 'ba2f7e668b571bf5080b7c274e6358226f6e16745c2a2e72dbfbcf63828a2d7b', - 'vout': 0, - 'scriptSig': { - 'asm': '3044022077222a91cda23af69179377c62d84a176fb12caff6c5cbf6ae9e5957ff3b1afe0220768edead76819228dcba18cca3c9a5a5d4c32919720f21df21a297ba375bbe5c01 03371ea5a4dfe356b3ea4042a537d7ab7ee0faabd43e21b6cc076fda2240629eee', - 'hex': '473044022077222a91cda23af69179377c62d84a176fb12caff6c5cbf6ae9e5957ff3b1afe0220768edead76819228dcba18cca3c9a5a5d4c32919720f21df21a297ba375bbe5c012103371ea5a4dfe356b3ea4042a537d7ab7ee0faabd43e21b6cc076fda2240629eee' - }, - 'sequence': 4294967294, - 'n': 1, - 'addr': 'n4oM7bPuC4ZPdCEDvtw9xGYQC7jmi5S6F4', - 'valueSat': 1960000, - 'value': 0.0196, - 'doubleSpentTxID': null - } - ], - 'vout': [ - { - 'value': '0.01940000', - 'n': 0, - 'scriptPubKey': { - 'asm': 'OP_DUP OP_HASH160 8e451eec7ca0a1764b4ab119274efdd2727b3c85 OP_EQUALVERIFY OP_CHECKSIG', - 'hex': '76a9148e451eec7ca0a1764b4ab119274efdd2727b3c8588ac', - 'reqSigs': 1, - 'type': 'pubkeyhash', - 'addresses': [ - 'mtVD3tdifBNujYzZ5N7PgXfKk4Bc85tDKA' - ] - }, - 'spentTxId': '9a213b879da9073a9a30606f9046f35f36f268cbf03f6242993a97c4c07c00b9', - 'spentIndex': 1, - 'spentHeight': 200, - 'spentTs': 1440992946 - }, - { - 'value': '0.01000000', - 'n': 1, - 'scriptPubKey': { - 'asm': 'OP_DUP OP_HASH160 d0fce8f064cd1059a6a11501dd66fe42368572b0 OP_EQUALVERIFY OP_CHECKSIG', - 'hex': '76a914d0fce8f064cd1059a6a11501dd66fe42368572b088ac', - 'reqSigs': 1, - 'type': 'pubkeyhash', - 'addresses': [ - 'mzZypShcs1B35udnkqeYeJy8rUdgHDDvKG' - ] - }, - 'spentTxId': '418d3eb60275957b3456b96902e908abf962e71be4c4f09486564254664951bc', - 'spentIndex': 34, - 'spentHeight': 200, - 'spentTs': 1440999118 - } - ], - 'blockhash': '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7', - 'blockheight': 533974, - 'confirmations': 236, - 'time': 1440987503, - 'blocktime': 1440987503, - 'valueOut': 0.0294, - 'size': 373, - 'valueIn': 0.0295, - 'fees': 0.0001 - } - ] - }; - - var todos = { - txs: [ - { - vout: [ - { - scriptPubKey: { - reqSigs: 1 + "value": "50.00000000", + "n": 0, + "scriptPubKey": { + "hex": "41047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77ac", + "asm": "047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77 OP_CHECKSIG", + "addresses": [ + "1HLoD9E4SDFFPDiYfNYnkBLQ85Y51J3Zb1" + ], + "type": "pubkeyhash" } } - ] - }, - { - vin: [ ], - vout: [ - { - scriptPubKey: { - reqSigs: 1 - } - }, - { - scriptPubKey: { - reqSigs: 1 - }, - spentTs: 1440997099 - } - ] - }, - { - vin: [ - ], - vout: [ - { - scriptPubKey: { - reqSigs: 1 - }, - spentTs: 1440992946 - }, - { - scriptPubKey: { - reqSigs: 1 - }, - spentTs: 1440999118 - } - ] + "blockhash": "000000006a625f06636b8bb6ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd", + "blockheight": 2, + "confirmations": 481772, + "time": 1231469744, + "blocktime": 1231469744, + "isCoinBase": true, + "valueOut": 50, + "size": 134 } ] }; @@ -618,7 +203,6 @@ describe('Transactions', function() { var res = { jsonp: function(data) { - _.merge(data, todos); should(data).eql(insight); done(); } @@ -626,288 +210,77 @@ describe('Transactions', function() { transactions.list(req, res); }); - it('by address', function(done) { - var txinfos = [ - { - tx: { - hex: '010000000125c46caa6d839435b43c20d6d48978e677841244b37a09f6f6cd29bfaf5b5eea010000006b483045022100f4d169783bef70e3943d2a617cce55d9fe4e33fc6f9880b8277265e2f619a97002201238648abcdf52960500664e969046d41755f7fc371971ebc78002fc418465a6012103acdcd31d51272403ce0829447e59e2ac9e08ed0bf92011cbf7420addf24534e6feffffff02a913dda5000000001976a9143583efb5e64a4668c6c54bb5fcc30af4417b4f2d88ac809fd500000000001976a9149713201957f42379e574d7c70d506ee49c2c8ad688ac49260800', - hash: 'bb0ec3b96209fac9529570ea6f83a86af2cceedde4aaf2bfcc4796680d23f1c7', - version: 1, - inputs: [ - { - prevTxId: 'ea5e5bafbf29cdf6f6097ab344128477e67889d4d6203cb43594836daa6cc425', - outputIndex: 1, - sequence: 4294967294, - script: '483045022100f4d169783bef70e3943d2a617cce55d9fe4e33fc6f9880b8277265e2f619a97002201238648abcdf52960500664e969046d41755f7fc371971ebc78002fc418465a6012103acdcd31d51272403ce0829447e59e2ac9e08ed0bf92011cbf7420addf24534e6', - scriptAsm: '3045022100f4d169783bef70e3943d2a617cce55d9fe4e33fc6f9880b8277265e2f619a97002201238648abcdf52960500664e969046d41755f7fc371971ebc78002fc418465a601 03acdcd31d51272403ce0829447e59e2ac9e08ed0bf92011cbf7420addf24534e6', - satoshis: 2796764565, - address: 'msyjRQQ88MabQmyafpKCjBHUwuJ49tVjcb' - } - ], - outputs: [ - { - satoshis: 2782729129, - address: 'mkPvAKZ2rar6qeG3KjBtJHHMSP1wFZH7Er', - script: '76a9143583efb5e64a4668c6c54bb5fcc30af4417b4f2d88ac', - scriptAsm: 'OP_DUP OP_HASH160 3583efb5e64a4668c6c54bb5fcc30af4417b4f2d OP_EQUALVERIFY OP_CHECKSIG' - }, - { - satoshis: 14000000, - address: 'muHmEsjhjmATf9i3T9gHyeQoce9LXe2dWz', - script: '76a9149713201957f42379e574d7c70d506ee49c2c8ad688ac', - scriptAsm: 'OP_DUP OP_HASH160 9713201957f42379e574d7c70d506ee49c2c8ad6 OP_EQUALVERIFY OP_CHECKSIG' - } - ], - inputSatoshis: 2796764565, - outputSatoshis: 2796729129, - feeSatoshis: 35436, - locktime: 534089 - } - }, - { - tx: { - hex: '0100000001c7f1230d689647ccbff2aae4ddeeccf26aa8836fea709552c9fa0962b9c30ebb000000006a47304402201ee69281db6b95bb1aa3074059b67581635b719e8f64e4c2694db6ec56ad9447022011e91528996ea459b1fb2c0b59363fecbefe4bc2ca90f7b2382bdaa358f2d5640121034cc057b12a68ee79df998004b9a1341bbb18b17ea4939bebaa3bac001e940f24feffffff02bce0c9a4000000001976a91456e446bc3489543d8324c6d0271524c0bd0506dd88ac80a81201000000001976a914011d2963b619186a318f768dddfd98cd553912a088ac53260800', - hash: '01f700df84c466f2a389440e5eeacdc47d04f380c39e5d19dce2ce91a11ecba3', - version: 1, - inputs: [ - { - prevTxId: 'bb0ec3b96209fac9529570ea6f83a86af2cceedde4aaf2bfcc4796680d23f1c7', - outputIndex: 0, - sequence: 4294967294, - script: '47304402201ee69281db6b95bb1aa3074059b67581635b719e8f64e4c2694db6ec56ad9447022011e91528996ea459b1fb2c0b59363fecbefe4bc2ca90f7b2382bdaa358f2d5640121034cc057b12a68ee79df998004b9a1341bbb18b17ea4939bebaa3bac001e940f24', - scriptAsm: '304402201ee69281db6b95bb1aa3074059b67581635b719e8f64e4c2694db6ec56ad9447022011e91528996ea459b1fb2c0b59363fecbefe4bc2ca90f7b2382bdaa358f2d56401 034cc057b12a68ee79df998004b9a1341bbb18b17ea4939bebaa3bac001e940f24', - satoshis: 2782729129, - address: 'mkPvAKZ2rar6qeG3KjBtJHHMSP1wFZH7Er' - } - ], - outputs: [ - { - satoshis: 2764693692, - address: 'moSPsU4p2C2gssiniJ1JNH4fB9xs633tLv', - script: '76a91456e446bc3489543d8324c6d0271524c0bd0506dd88ac', - scriptAsm: 'OP_DUP OP_HASH160 56e446bc3489543d8324c6d0271524c0bd0506dd OP_EQUALVERIFY OP_CHECKSIG' - }, - { - satoshis: 18000000, - scriptAsm: 'OP_DUP OP_HASH160 011d2963b619186a318f768dddfd98cd553912a0 OP_EQUALVERIFY OP_CHECKSIG', - script: '76a914011d2963b619186a318f768dddfd98cd553912a088ac', - address: 'mfcquSAitCkUKXaYRZTRZQDfUegnL3kDew', - spentTxId: '71a9e60c0341c9c258367f1a6d4253276f16e207bf84f41ff7412d8958a81bed' - } - ], - inputSatoshis: 2782729129, - outputSatoshis: 2782693692, - feeSatoshis: 35437, - locktime: 534099 - } - } - ]; + it('by address, single/coinbase', function(done) { - var historyResult = { - totalCount: txinfos.length, - items: txinfos - }; + var hex = '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff3103835807244d696e656420627920416e74506f6f6c6a2f4542312f4144362f4e59412f1d205999aaa02b1200001fff0200ffffffff026fb2a54c000000001976a914ad7309dfc032d7f6b652e0c29ee353e63fffec6688ac0000000000000000266a24aa21a9ed55882e9fed16c5d3b6d77e4160a56f58c70d354d02888a99486125b638231c8100000000'; - txinfos[0].tx.blockHash = '00000000000001001aba15de213648f370607fb048288dd27b96f7e833a73520'; - txinfos[0].tx.blockTimestamp = 1441068774; - txinfos[0].tx.height = 534105; - - txinfos[1].tx.blockHash = '0000000000000a3acc1f7fe72917eb48bb319ed96c125a6dfcc0ba6acab3c4d0'; - txinfos[1].tx.blockTimestamp = 1441072817; - txinfos[1].tx.height = 534110; - - txinfos[0].tx.outputs[0].spentTxId = '01f700df84c466f2a389440e5eeacdc47d04f380c39e5d19dce2ce91a11ecba3'; - txinfos[0].tx.outputs[0].spentIndex = 0; - txinfos[0].tx.outputs[0].spentHeight = 199; - - txinfos[1].tx.outputs[0].spentTxId = '661194e5533a395ce9076f292b7e0fb28fe94cd8832a81b4aa0517ff58c1ddd2'; - txinfos[1].tx.outputs[0].spentIndex = 0; - txinfos[1].tx.outputs[0].spentHeight = 134; - - txinfos[1].tx.outputs[1].spentTxId = '71a9e60c0341c9c258367f1a6d4253276f16e207bf84f41ff7412d8958a81bed'; - txinfos[1].tx.outputs[1].spentIndex = 0; - txinfos[1].tx.outputs[1].spentHeight = 112; + var bcoinTx = bcoin.tx.fromRaw(hex, 'hex'); + bcoinTx.__height = 481411; + bcoinTx.outputSatoshis = 1285927535; + bcoinTx.__timestamp = 1503242912; + bcoinTx.__blockhash = '000000000000000000926a0cd4a05ef116514cbf1852edc306d13eb951ec0b54'; var node = { - services: { block: { getTip: sinon.stub().returns({ height: 534223 }) } }, - getAddressHistory: sinon.stub().callsArgWith(2, null, historyResult), - network: 'testnet' + services: { + block: { + getTip: sinon.stub().returns({ height: 534223 }) + }, + address: { + getAddressHistory: sinon.stub().callsArgWith(2, null, { + totalCount: 1, + from: 0, + to: 0xffffffff, + items: [bcoinTx] + }) + } + } }; var insight = { - 'pagesTotal': 1, - 'txs': [ + "pagesTotal": 1, + "txs": [ { - 'txid': 'bb0ec3b96209fac9529570ea6f83a86af2cceedde4aaf2bfcc4796680d23f1c7', - 'version': 1, - 'locktime': 534089, - 'vin': [ + "txid": "1c01a2090db0850e1f1049bea02e4bbf44b6790dfeb8e054f2beb69339ef52d4", + "version": 1, + "locktime": 0, + "vin": [ { - 'txid': 'ea5e5bafbf29cdf6f6097ab344128477e67889d4d6203cb43594836daa6cc425', - 'vout': 1, - 'scriptSig': { - 'asm': '3045022100f4d169783bef70e3943d2a617cce55d9fe4e33fc6f9880b8277265e2f619a97002201238648abcdf52960500664e969046d41755f7fc371971ebc78002fc418465a601 03acdcd31d51272403ce0829447e59e2ac9e08ed0bf92011cbf7420addf24534e6', - 'hex': '483045022100f4d169783bef70e3943d2a617cce55d9fe4e33fc6f9880b8277265e2f619a97002201238648abcdf52960500664e969046d41755f7fc371971ebc78002fc418465a6012103acdcd31d51272403ce0829447e59e2ac9e08ed0bf92011cbf7420addf24534e6' - }, - 'sequence': 4294967294, - 'n': 0, - 'addr': 'msyjRQQ88MabQmyafpKCjBHUwuJ49tVjcb', - 'valueSat': 2796764565, - 'value': 27.96764565, - 'doubleSpentTxID': null + "coinbase": "03835807244d696e656420627920416e74506f6f6c6a2f4542312f4144362f4e59412f1d205999aaa02b1200001fff0200", + "sequence": 4294967295, + "n": 0 } ], - 'vout': [ + "vout": [ { - 'value': '27.82729129', - 'n': 0, - 'scriptPubKey': { - 'asm': 'OP_DUP OP_HASH160 3583efb5e64a4668c6c54bb5fcc30af4417b4f2d OP_EQUALVERIFY OP_CHECKSIG', - 'hex': '76a9143583efb5e64a4668c6c54bb5fcc30af4417b4f2d88ac', - 'reqSigs': 1, - 'type': 'pubkeyhash', - 'addresses': [ - 'mkPvAKZ2rar6qeG3KjBtJHHMSP1wFZH7Er' - ] - }, - 'spentTxId': '01f700df84c466f2a389440e5eeacdc47d04f380c39e5d19dce2ce91a11ecba3', - 'spentIndex': 0, - 'spentHeight': 199, - 'spentTs': 1441072817 + "value": "12.85927535", + "n": 0, + "scriptPubKey": { + "hex": "76a914ad7309dfc032d7f6b652e0c29ee353e63fffec6688ac", + "asm": "OP_DUP OP_HASH160 ad7309dfc032d7f6b652e0c29ee353e63fffec66 OP_EQUALVERIFY OP_CHECKSIG", + "addresses": [ + "1Gp7iCzDGMZiV55Kt8uKsux6VyoHe1aJaN" + ], + "type": "pubkeyhash" + } }, { - 'value': '0.14000000', - 'n': 1, - 'scriptPubKey': { - 'asm': 'OP_DUP OP_HASH160 9713201957f42379e574d7c70d506ee49c2c8ad6 OP_EQUALVERIFY OP_CHECKSIG', - 'hex': '76a9149713201957f42379e574d7c70d506ee49c2c8ad688ac', - 'reqSigs': 1, - 'type': 'pubkeyhash', - 'addresses': [ - 'muHmEsjhjmATf9i3T9gHyeQoce9LXe2dWz' - ] - }, - 'spentTxId': null, - 'spentIndex': null, - 'spentHeight': null - } - ], - 'blockhash': '00000000000001001aba15de213648f370607fb048288dd27b96f7e833a73520', - 'blockheight': 534105, - 'confirmations': 119, - 'time': 1441068774, - 'blocktime': 1441068774, - 'valueOut': 27.96729129, - 'size': 226, - 'valueIn': 27.96764565, - 'fees': 0.00035436 - }, - { - 'txid': '01f700df84c466f2a389440e5eeacdc47d04f380c39e5d19dce2ce91a11ecba3', - 'version': 1, - 'locktime': 534099, - 'vin': [ - { - 'txid': 'bb0ec3b96209fac9529570ea6f83a86af2cceedde4aaf2bfcc4796680d23f1c7', - 'vout': 0, - 'scriptSig': { - 'asm': '304402201ee69281db6b95bb1aa3074059b67581635b719e8f64e4c2694db6ec56ad9447022011e91528996ea459b1fb2c0b59363fecbefe4bc2ca90f7b2382bdaa358f2d56401 034cc057b12a68ee79df998004b9a1341bbb18b17ea4939bebaa3bac001e940f24', - 'hex': '47304402201ee69281db6b95bb1aa3074059b67581635b719e8f64e4c2694db6ec56ad9447022011e91528996ea459b1fb2c0b59363fecbefe4bc2ca90f7b2382bdaa358f2d5640121034cc057b12a68ee79df998004b9a1341bbb18b17ea4939bebaa3bac001e940f24' - }, - 'sequence': 4294967294, - 'n': 0, - 'addr': 'mkPvAKZ2rar6qeG3KjBtJHHMSP1wFZH7Er', - 'valueSat': 2782729129, - 'value': 27.82729129, - 'doubleSpentTxID': null - } - ], - 'vout': [ - { - 'value': '27.64693692', - 'n': 0, - 'scriptPubKey': { - 'asm': 'OP_DUP OP_HASH160 56e446bc3489543d8324c6d0271524c0bd0506dd OP_EQUALVERIFY OP_CHECKSIG', - 'hex': '76a91456e446bc3489543d8324c6d0271524c0bd0506dd88ac', - 'reqSigs': 1, - 'type': 'pubkeyhash', - 'addresses': [ - 'moSPsU4p2C2gssiniJ1JNH4fB9xs633tLv' - ] - }, - 'spentTxId': '661194e5533a395ce9076f292b7e0fb28fe94cd8832a81b4aa0517ff58c1ddd2', - 'spentIndex': 0, - 'spentHeight': 134, - 'spentTs': 1441077236 - }, - { - 'value': '0.18000000', - 'n': 1, - 'scriptPubKey': { - 'asm': 'OP_DUP OP_HASH160 011d2963b619186a318f768dddfd98cd553912a0 OP_EQUALVERIFY OP_CHECKSIG', - 'hex': '76a914011d2963b619186a318f768dddfd98cd553912a088ac', - 'reqSigs': 1, - 'type': 'pubkeyhash', - 'addresses': [ - 'mfcquSAitCkUKXaYRZTRZQDfUegnL3kDew' - ] - }, - 'spentTxId': '71a9e60c0341c9c258367f1a6d4253276f16e207bf84f41ff7412d8958a81bed', - 'spentIndex': 0, - 'spentHeight': 112, - 'spentTs': 1441069523 - } - ], - 'blockhash': '0000000000000a3acc1f7fe72917eb48bb319ed96c125a6dfcc0ba6acab3c4d0', - 'blockheight': 534110, - 'confirmations': 114, - 'time': 1441072817, - 'blocktime': 1441072817, - 'valueOut': 27.82693692, - 'size': 225, - 'valueIn': 27.82729129, - 'fees': 0.00035437 - } - ] - }; - - var todos = { - 'txs': [ - { - 'vin': [ - ], - 'vout': [ - { - 'scriptPubKey': { - 'reqSigs': 1 - }, - 'spentTs': 1441072817 - }, - { - 'scriptPubKey': { - 'reqSigs': 1 + "value": "0.00000000", + "n": 1, + "scriptPubKey": { + "hex": "6a24aa21a9ed55882e9fed16c5d3b6d77e4160a56f58c70d354d02888a99486125b638231c81", + "asm": "OP_RETURN aa21a9ed55882e9fed16c5d3b6d77e4160a56f58c70d354d02888a99486125b638231c81" } } - ] - }, - { - 'vin': [ ], - 'vout': [ - { - 'scriptPubKey': { - 'reqSigs': 1 - }, - 'spentTs': 1441077236 - }, - { - 'scriptPubKey': { - 'reqSigs': 1 - }, - 'spentTs': 1441069523 - } - ] + "blockhash": "000000000000000000926a0cd4a05ef116514cbf1852edc306d13eb951ec0b54", + "blockheight": 481411, + "confirmations": 52813, + "time": 1503242912, + "blocktime": 1503242912, + "isCoinBase": true, + "valueOut": 12.85927535, + "size": 181 } ] }; @@ -920,8 +293,7 @@ describe('Transactions', function() { var res = { jsonp: function(data) { - var merged = _.merge(data, todos); - should(merged).eql(insight); + should(data).eql(insight); done(); } }; @@ -932,12 +304,19 @@ describe('Transactions', function() { }); describe('/rawtx/:txid', function() { + it('should give the correct data', function(done) { var hex = '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff2303d6250800feb0aae355fe263600000963676d696e6572343208ae5800000000000000ffffffff01c018824a000000001976a91468bedce8982d25c3b6b03f6238cbad00378b8ead88ac00000000'; var node = { - services: { block: { getTip: sinon.stub().returns({ height: 534233 }) } }, - getTransaction: sinon.stub().callsArgWith(1, null, bitcore.Transaction().fromBuffer(new Buffer(hex, 'hex'))) + services: { + block: { + getTip: sinon.stub().returns({ height: 534233 }) + }, + transaction: { + getTransaction: sinon.stub().callsArgWith(1, null, bcoin.tx.fromRaw(new Buffer(hex, 'hex'))) + } + } }; var transactions = new TxController(node); @@ -958,6 +337,7 @@ describe('Transactions', function() { }); describe('#transformInvTransaction', function() { + it('should give the correct data', function() { var insight = { 'txid': 'a15a7c257af596704390d345ff3ea2eed4cd02ce8bfb8afb700bff82257e49fb', @@ -986,6 +366,7 @@ describe('Transactions', function() { var result = transactions.transformInvTransaction(tx); should(result).eql(insight); }); + it('will not include null values in vout array', function() { var insight = { 'txid': '716d54157c31e52c820494c6c2b8af1b64352049f4dcc80632aa15742a7f82c4', @@ -1011,6 +392,7 @@ describe('Transactions', function() { var result = transactions.transformInvTransaction(tx); should(result).eql(insight); }); + it('should detect RBF txs', function() { var testCases = [ { diff --git a/test/utils.js b/test/utils.js index 41c84a9..13aa0de 100644 --- a/test/utils.js +++ b/test/utils.js @@ -9,7 +9,7 @@ describe('Utils', function() { it('should give the correct fee', function(done) { var node = { services: { - bitcoind: { + fee: { estimateFee: function(blocks, callback) { switch(blocks) { case 1: