modifies unspent interfase to be more clear

This commit is contained in:
Matias Alejo Garcia 2014-06-05 17:07:54 -03:00
parent 9eaa88a298
commit 3dbfae11a3
5 changed files with 66 additions and 17 deletions

View File

@ -193,12 +193,13 @@ Sample return:
ts: 1401226410,
scriptPubKey: "76a914e50575162795cd77366fb80d728e3216bd52deac88ac",
amount: 0.001,
confirmations: "6+"
confirmation: 6
confirmationsFromCache: true,
}
]
```
Please not that in case confirmations are cached and are more that INSIGHT_SAFE_CONFIRMATIONS setting, the
return can be a string of the form `SAFE_CONFIRMATIONS+`, e.g.: the string `6+`
Please note that in case confirmations are cached (because the number of confirmations if bigger that INSIGHT_SAFE_CONFIRMATIONS) the return will include the pair confirmationsFromCache:true, and confirmations will equal INSIGHT_SAFE_CONFIRMATIONS. See noCache and INSIGHT_IGNORE_CACHE options for details.
### Unspent Outputs for multiple addresses

View File

@ -179,7 +179,8 @@ Address.prototype.update = function(next, opts) {
ts: x.ts,
scriptPubKey: x.scriptPubKey,
amount: x.value_sat / BitcoreUtil.COIN,
confirmations: x.isConfirmedCached ? (config.safeConfirmations+'+') : x.confirmations,
confirmations: x.isConfirmedCached ? (config.safeConfirmations) : x.confirmations,
confirmationsFromCache: !!x.isConfirmedCached,
};
});
return next();

View File

@ -406,8 +406,7 @@ TransactionDb.prototype.cacheScriptPubKey = function(txouts,cb) {
TransactionDb.prototype._parseAddrData = function(data, ignoreCache) {
var k = data.key.split('-');
TransactionDb.prototype._parseAddrData = function(k, data, ignoreCache) {
var v = data.value.split(':');
// console.log('[TransactionDb.js.375]',data.key,data.value); //TODO
var item = {
@ -450,6 +449,7 @@ TransactionDb.prototype.fromAddr = function(addr, opts, cb) {
var self = this;
var k = ADDR_PREFIX + addr + '-';
var ret = [];
var unique={};
db.createReadStream({
start: k,
@ -457,7 +457,12 @@ TransactionDb.prototype.fromAddr = function(addr, opts, cb) {
limit: opts.txLimit>0 ? opts.txLimit: -1, // -1 means not limit
})
.on('data', function(data) {
ret.push(self._parseAddrData(data, opts.ignoreCache));
var k = data.key.split('-');
var index = k[3]+k[4];
if (!unique[index]) {
unique[index]=1;
ret.push(self._parseAddrData(k, data, opts.ignoreCache));
}
})
.on('error', cb)
.on('end', function() {

View File

@ -22,7 +22,10 @@ describe('Address cache ', function() {
before(function(c) {
txDb = TransactionDb;
txDb.deleteCacheForAddress('muAt5RRqDarPFCe6qDXGZc54xJjXYUyepG',function(){
txDb.deleteCacheForAddress('mt2AzeCorSf7yFckj19HFiXJgh9aNyc4h3',c);
txDb.deleteCacheForAddress('mt2AzeCorSf7yFckj19HFiXJgh9aNyc4h3',function(){
txDb.deleteCacheForAddress('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk',c);
});
});
});
@ -51,7 +54,7 @@ describe('Address cache ', function() {
it('cache case unspent w/o cache', function(done) {
it('cache case 2 w/o cache', function(done) {
var a = new Address('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk', txDb);
a.update(function(err) {
if (err) done(err);
@ -62,8 +65,7 @@ describe('Address cache ', function() {
});
});
it('cache case unspent w cache', function(done) {
it('cache case 2 w cache', function(done) {
var a = new Address('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk', txDb);
a.update(function(err) {
if (err) done(err);
@ -73,7 +75,34 @@ describe('Address cache ', function() {
return done();
});
});
it('cache case 2 w/o cache', function(done) {
it('cache case 2 unspent wo cache', function(done) {
txDb.deleteCacheForAddress('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk',function() {
var a = new Address('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk', txDb);
a.update(function(err) {
if (err) done(err);
a.unspent.length.should.equal(1);
a.unspent[0].confirmations.should.be.above(15000);
a.unspent[0].confirmationsFromCache.should.equal(false);
return done();
}, {onlyUnspent:1});
});
});
it('cache case 2 unspent w cache', function(done) {
var a = new Address('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk', txDb);
a.update(function(err) {
if (err) done(err);
a.unspent.length.should.equal(1);
a.unspent[0].confirmationsFromCache.should.equal(true);
a.unspent[0].confirmations.should.equal(6);
return done();
}, {onlyUnspent:1});
});
it('cache case 3 w/o cache', function(done) {
var a = new Address('mt2AzeCorSf7yFckj19HFiXJgh9aNyc4h3', txDb);
a.update(function(err) {
if (err) done(err);
@ -83,7 +112,7 @@ describe('Address cache ', function() {
return done();
});
},1);
it('cache case 2 w cache', function(done) {
it('cache case 4 w cache', function(done) {
var a = new Address('mt2AzeCorSf7yFckj19HFiXJgh9aNyc4h3', txDb);
a.update(function(err) {
if (err) done(err);
@ -93,7 +122,7 @@ describe('Address cache ', function() {
return done();
},{txLimit:0});
});
it('cache case 2 w ignore cache', function(done) {
it('cache case 4 w ignore cache', function(done) {
var a = new Address('mt2AzeCorSf7yFckj19HFiXJgh9aNyc4h3', txDb);
a.update(function(err) {
if (err) done(err);
@ -104,6 +133,19 @@ describe('Address cache ', function() {
},{txLimit:0, ignoreCache:1});
});
it('cache case 5 unspent w cache', function(done) {
var a = new Address('2NBuTjjZrURxLaMyPUu2sJwNrtpt7GtPX2p', txDb);
a.update(function(err) {
if (err) done(err);
a.unspent.length.should.equal(1);
a.unspent[0].confirmationsFromCache.should.equal(true);
a.unspent[0].confirmations.should.equal(6);
return done();
}, {onlyUnspent:1});
});
});

View File

@ -23,12 +23,12 @@ describe('BlockDb getBlocksByDate', function(){
it('Get Hash by Date', function(done) {
bDb.getBlocksByDate(START_TS, END_TS, 1000, function(err, list) {
bDb.getBlocksByDate(START_TS, END_TS, 2, function(err, list) {
if (err) done(err);
assert(list, 'returns list');
assert.equal(list.length,2, 'list has 2 items');
assert.equal(list[0].hash, TESTING_BLOCK0);
assert.equal(list[1].hash, TESTING_BLOCK1);
assert.equal(list[1].hash, TESTING_BLOCK0);
assert.equal(list[0].hash, TESTING_BLOCK1);
done();
});
});