Merge pull request #1877 from isocolsky/bug/getActivity
Fixed bug when trying to import wallet
This commit is contained in:
commit
6656a7cd36
2 changed files with 18 additions and 13 deletions
|
|
@ -44,9 +44,9 @@ var Insight = function(opts) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
if (opts.transports) {
|
if (opts.transports) {
|
||||||
this.opts['transports'] = opts.transports;
|
this.opts['transports'] = opts.transports;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.socket = this.getSocket();
|
this.socket = this.getSocket();
|
||||||
}
|
}
|
||||||
|
|
@ -224,7 +224,7 @@ Insight.prototype.subscribe = function(addresses) {
|
||||||
|
|
||||||
s.emit('subscribe', address);
|
s.emit('subscribe', address);
|
||||||
s.on(address, handler);
|
s.on(address, handler);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -267,16 +267,21 @@ Insight.prototype.getTransaction = function(txid, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Insight.prototype.getTransactions = function (addresses, from, to, cb) {
|
Insight.prototype.getTransactions = function(addresses, from, to, cb) {
|
||||||
preconditions.shouldBeArray(addresses);
|
preconditions.shouldBeArray(addresses);
|
||||||
preconditions.shouldBeFunction(cb);
|
preconditions.shouldBeFunction(cb);
|
||||||
|
|
||||||
var qs = '?from=' + (from || 0);
|
var qs = '';
|
||||||
if (to) qs += '&to=' + to;
|
if (_.isNumber(from)) {
|
||||||
|
qs += '?from=' + from;
|
||||||
|
if (_.isNumber(to)) {
|
||||||
|
qs += '&to=' + to;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.requestPost('/api/addrs/txs' + qs, {
|
this.requestPost('/api/addrs/txs' + qs, {
|
||||||
addrs: addresses.join(',')
|
addrs: addresses.join(',')
|
||||||
}, function (err, res, txs) {
|
}, function(err, res, txs) {
|
||||||
if (err || res.statusCode != 200) return cb(err || res);
|
if (err || res.statusCode != 200) return cb(err || res);
|
||||||
cb(null, txs);
|
cb(null, txs);
|
||||||
});
|
});
|
||||||
|
|
@ -294,7 +299,7 @@ Insight.prototype.getUnspent = function(addresses, cb) {
|
||||||
// This filter out possible broken unspent, as reported on
|
// This filter out possible broken unspent, as reported on
|
||||||
// https://github.com/bitpay/copay/issues/1585
|
// https://github.com/bitpay/copay/issues/1585
|
||||||
// and later gitter conversation.
|
// and later gitter conversation.
|
||||||
|
|
||||||
var unspent = _.filter(unspentRaw, 'scriptPubKey');
|
var unspent = _.filter(unspentRaw, 'scriptPubKey');
|
||||||
cb(null, unspent);
|
cb(null, unspent);
|
||||||
});
|
});
|
||||||
|
|
@ -303,7 +308,7 @@ Insight.prototype.getUnspent = function(addresses, cb) {
|
||||||
Insight.prototype.getActivity = function(addresses, cb) {
|
Insight.prototype.getActivity = function(addresses, cb) {
|
||||||
preconditions.shouldBeArray(addresses);
|
preconditions.shouldBeArray(addresses);
|
||||||
|
|
||||||
this.getTransactions(addresses, function then(err, txs) {
|
this.getTransactions(addresses, null, null, function then(err, txs) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
var flatArray = function(xss) {
|
var flatArray = function(xss) {
|
||||||
|
|
|
||||||
|
|
@ -240,7 +240,7 @@ describe('Insight model', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
var addresses = ['2NATQJnaQe2CUKLyhL1zdNkttJM1dUH9HaM', '2NE9hTCffeugo5gQtfB4owq98gyTeWC56yb'];
|
var addresses = ['2NATQJnaQe2CUKLyhL1zdNkttJM1dUH9HaM', '2NE9hTCffeugo5gQtfB4owq98gyTeWC56yb'];
|
||||||
blockchain.getTransactions(addresses, null, null, function(err, res) {
|
blockchain.getTransactions(addresses, 0, null, function(err, res) {
|
||||||
chai.expect(err).to.be.null;
|
chai.expect(err).to.be.null;
|
||||||
res.items.length.should.be.equal(3);
|
res.items.length.should.be.equal(3);
|
||||||
done();
|
done();
|
||||||
|
|
@ -273,7 +273,7 @@ describe('Insight model', function() {
|
||||||
it('should get activity for an innactive address', function(done) {
|
it('should get activity for an innactive address', function(done) {
|
||||||
var blockchain = new Insight(FAKE_OPTS);
|
var blockchain = new Insight(FAKE_OPTS);
|
||||||
|
|
||||||
sinon.stub(blockchain, "getTransactions", function(addresses, cb) {
|
sinon.stub(blockchain, "getTransactions", function(addresses, from, to, cb) {
|
||||||
cb(null, []);
|
cb(null, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -290,7 +290,7 @@ describe('Insight model', function() {
|
||||||
it('should get activity for active addresses', function(done) {
|
it('should get activity for active addresses', function(done) {
|
||||||
var blockchain = new Insight(FAKE_OPTS);
|
var blockchain = new Insight(FAKE_OPTS);
|
||||||
|
|
||||||
sinon.stub(blockchain, "getTransactions", function(addresses, cb) {
|
sinon.stub(blockchain, "getTransactions", function(addresses, from, to, cb) {
|
||||||
cb(null, [{
|
cb(null, [{
|
||||||
vin: [{
|
vin: [{
|
||||||
addr: '2NATQJnaQe2CUKLyhL1zdNkttJM1dUH9HaM'
|
addr: '2NATQJnaQe2CUKLyhL1zdNkttJM1dUH9HaM'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue