Merge pull request #123 from matiu/feature/unspent-interfase-change
Feature/unspent interfase change
This commit is contained in:
commit
c5f0625fbd
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -406,13 +406,12 @@ 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 = {
|
||||
key: data.key,
|
||||
ts: parseInt(k[2]),
|
||||
ts: END_OF_WORLD_TS - parseInt(k[2]),
|
||||
txid: k[3],
|
||||
index: parseInt(k[4]),
|
||||
value_sat: parseInt(v[0]),
|
||||
|
@ -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() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "insight-bitcore-api",
|
||||
"description": "An open-source bitcoin blockchain API. The Insight API provides you with a convenient, powerful and simple way to query and broadcast data on the bitcoin network and build your own services with it.",
|
||||
"version": "0.2.4",
|
||||
"version": "0.2.6",
|
||||
"author": {
|
||||
"name": "Ryan X Charles",
|
||||
"email": "ryan@bitpay.com"
|
||||
|
|
|
@ -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,29 +54,55 @@ describe('Address cache ', function() {
|
|||
|
||||
|
||||
|
||||
it('cache case unspent w/o cache', function(done) {
|
||||
var a = new Address('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk', txDb);
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
a.balance.should.equal(0.23, 'balance');
|
||||
a.totalReceived.should.equal(0.23, 'totalReceived');
|
||||
a.txApperances.should.equal(1, 'txApperances');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('cache case unspent w cache', function(done) {
|
||||
var a = new Address('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk', txDb);
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
a.balance.should.equal(0.23, 'balance');
|
||||
a.totalReceived.should.equal(0.23, 'totalReceived');
|
||||
a.txApperances.should.equal(1, 'txApperances');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
it('cache case 2 w/o cache', function(done) {
|
||||
var a = new Address('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk', txDb);
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
a.balance.should.equal(0.23, 'balance');
|
||||
a.totalReceived.should.equal(0.23, 'totalReceived');
|
||||
a.txApperances.should.equal(1, 'txApperances');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cache case 2 w cache', function(done) {
|
||||
var a = new Address('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk', txDb);
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
a.balance.should.equal(0.23, 'balance');
|
||||
a.totalReceived.should.equal(0.23, 'totalReceived');
|
||||
a.txApperances.should.equal(1, 'txApperances');
|
||||
return 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});
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue