Merge pull request #335 from matiu/feat/unconfirmed-inputs
add unconfirmed inputs banner
This commit is contained in:
commit
2709031ec3
@ -59,10 +59,15 @@ exports.transaction = function(req, res, next, txid) {
|
|||||||
tDb.fromIdWithInfo(txid, function(err, tx) {
|
tDb.fromIdWithInfo(txid, function(err, tx) {
|
||||||
if (err || ! tx)
|
if (err || ! tx)
|
||||||
return common.handleErrors(err, res);
|
return common.handleErrors(err, res);
|
||||||
else {
|
|
||||||
|
bdb.fillVinConfirmations(tx.info, function(err) {
|
||||||
|
if (err)
|
||||||
|
return common.handleErrors(err, res);
|
||||||
|
|
||||||
req.transaction = tx.info;
|
req.transaction = tx.info;
|
||||||
return next();
|
return next();
|
||||||
}
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,9 @@ var DFLT_REQUIRED_CONFIRMATIONS = 1;
|
|||||||
*/
|
*/
|
||||||
var levelup = require('levelup'),
|
var levelup = require('levelup'),
|
||||||
config = require('../config/config');
|
config = require('../config/config');
|
||||||
var db = imports.db || levelup(config.leveldb + '/blocks',{maxOpenFiles: MAX_OPEN_FILES} );
|
var db = imports.db || levelup(config.leveldb + '/blocks', {
|
||||||
|
maxOpenFiles: MAX_OPEN_FILES
|
||||||
|
});
|
||||||
var Rpc = imports.rpc || require('./Rpc');
|
var Rpc = imports.rpc || require('./Rpc');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
|
||||||
@ -42,7 +44,9 @@ BlockDb.prototype.drop = function(cb) {
|
|||||||
var path = config.leveldb + '/blocks';
|
var path = config.leveldb + '/blocks';
|
||||||
db.close(function() {
|
db.close(function() {
|
||||||
require('leveldown').destroy(path, function() {
|
require('leveldown').destroy(path, function() {
|
||||||
db = levelup(path,{maxOpenFiles: MAX_OPEN_FILES} );
|
db = levelup(path, {
|
||||||
|
maxOpenFiles: MAX_OPEN_FILES
|
||||||
|
});
|
||||||
return cb();
|
return cb();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -53,23 +57,19 @@ BlockDb.prototype._addBlockScript = function(b, height) {
|
|||||||
var time_key = TIMESTAMP_PREFIX +
|
var time_key = TIMESTAMP_PREFIX +
|
||||||
(b.time || Math.round(new Date().getTime() / 1000));
|
(b.time || Math.round(new Date().getTime() / 1000));
|
||||||
|
|
||||||
return [
|
return [{
|
||||||
{
|
|
||||||
type: 'put',
|
type: 'put',
|
||||||
key: time_key,
|
key: time_key,
|
||||||
value: b.hash,
|
value: b.hash,
|
||||||
},
|
}, {
|
||||||
{
|
|
||||||
type: 'put',
|
type: 'put',
|
||||||
key: MAIN_PREFIX + b.hash,
|
key: MAIN_PREFIX + b.hash,
|
||||||
value: height,
|
value: height,
|
||||||
},
|
}, {
|
||||||
{
|
|
||||||
type: 'put',
|
type: 'put',
|
||||||
key: PREV_PREFIX + b.hash,
|
key: PREV_PREFIX + b.hash,
|
||||||
value: b.previousblockhash,
|
value: b.previousblockhash,
|
||||||
},
|
}, ];
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
BlockDb.prototype._delTxsScript = function(txs) {
|
BlockDb.prototype._delTxsScript = function(txs) {
|
||||||
@ -141,7 +141,9 @@ BlockDb.prototype.setBlockNotMain = function(hash, cb) {
|
|||||||
// the block prev to the new block, nor TIP pointer
|
// the block prev to the new block, nor TIP pointer
|
||||||
//
|
//
|
||||||
BlockDb.prototype.add = function(b, height, cb) {
|
BlockDb.prototype.add = function(b, height, cb) {
|
||||||
var txs = typeof b.tx[0] === 'string' ? b.tx : b.tx.map( function(o){ return o.txid; });
|
var txs = typeof b.tx[0] === 'string' ? b.tx : b.tx.map(function(o) {
|
||||||
|
return o.txid;
|
||||||
|
});
|
||||||
|
|
||||||
var dbScript = this._addBlockScript(b, height);
|
var dbScript = this._addBlockScript(b, height);
|
||||||
dbScript = dbScript.concat(this._addTxsScript(txs, b.hash, height));
|
dbScript = dbScript.concat(this._addTxsScript(txs, b.hash, height));
|
||||||
@ -191,7 +193,10 @@ BlockDb.prototype.setPrev = function(hash, prevHash, cb) {
|
|||||||
|
|
||||||
BlockDb.prototype.getPrev = function(hash, cb) {
|
BlockDb.prototype.getPrev = function(hash, cb) {
|
||||||
db.get(PREV_PREFIX + hash, function(err, val) {
|
db.get(PREV_PREFIX + hash, function(err, val) {
|
||||||
if (err && err.notFound) { err = null; val = null;}
|
if (err && err.notFound) {
|
||||||
|
err = null;
|
||||||
|
val = null;
|
||||||
|
}
|
||||||
return cb(err, val);
|
return cb(err, val);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -209,21 +214,30 @@ BlockDb.prototype.setLastFileIndex = function(idx, cb) {
|
|||||||
|
|
||||||
BlockDb.prototype.getLastFileIndex = function(cb) {
|
BlockDb.prototype.getLastFileIndex = function(cb) {
|
||||||
db.get(LAST_FILE_INDEX, function(err, val) {
|
db.get(LAST_FILE_INDEX, function(err, val) {
|
||||||
if (err && err.notFound) { err = null; val = null;}
|
if (err && err.notFound) {
|
||||||
|
err = null;
|
||||||
|
val = null;
|
||||||
|
}
|
||||||
return cb(err, val);
|
return cb(err, val);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
BlockDb.prototype.getNext = function(hash, cb) {
|
BlockDb.prototype.getNext = function(hash, cb) {
|
||||||
db.get(NEXT_PREFIX + hash, function(err, val) {
|
db.get(NEXT_PREFIX + hash, function(err, val) {
|
||||||
if (err && err.notFound) { err = null; val = null;}
|
if (err && err.notFound) {
|
||||||
|
err = null;
|
||||||
|
val = null;
|
||||||
|
}
|
||||||
return cb(err, val);
|
return cb(err, val);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
BlockDb.prototype.getHeight = function(hash, cb) {
|
BlockDb.prototype.getHeight = function(hash, cb) {
|
||||||
db.get(MAIN_PREFIX + hash, function(err, val) {
|
db.get(MAIN_PREFIX + hash, function(err, val) {
|
||||||
if (err && err.notFound) { err = null; val = 0;}
|
if (err && err.notFound) {
|
||||||
|
err = null;
|
||||||
|
val = 0;
|
||||||
|
}
|
||||||
return cb(err, parseInt(val));
|
return cb(err, parseInt(val));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -247,7 +261,10 @@ BlockDb.prototype.setNext = function(hash, nextHash, cb) {
|
|||||||
BlockDb.prototype.countConnected = function(cb) {
|
BlockDb.prototype.countConnected = function(cb) {
|
||||||
var c = 0;
|
var c = 0;
|
||||||
console.log('Counting connected blocks. This could take some minutes');
|
console.log('Counting connected blocks. This could take some minutes');
|
||||||
db.createReadStream({start: MAIN_PREFIX, end: MAIN_PREFIX + '~' })
|
db.createReadStream({
|
||||||
|
start: MAIN_PREFIX,
|
||||||
|
end: MAIN_PREFIX + '~'
|
||||||
|
})
|
||||||
.on('data', function(data) {
|
.on('data', function(data) {
|
||||||
if (data.value !== 0) c++;
|
if (data.value !== 0) c++;
|
||||||
})
|
})
|
||||||
@ -352,6 +369,24 @@ BlockDb.prototype._fillConfirmationsOneSpent = function(o, chainHeight, cb) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
BlockDb.prototype._fillConfirmationsOneVin = function(o, chainHeight, cb) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
self.getBlockForTx(o.txid, function(err, hash, height) {
|
||||||
|
if (err) return cb(err);
|
||||||
|
o.isConfirmed = false;
|
||||||
|
o.confirmations = 0;
|
||||||
|
if (height >= 0) {
|
||||||
|
o.isConfirmed = chainHeight >= height;
|
||||||
|
o.confirmations = chainHeight - height + 1;
|
||||||
|
}
|
||||||
|
o.unconfirmedInput = ! o.isConfirmed;
|
||||||
|
return cb();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
BlockDb.prototype._fillConfirmationsOne = function(o, chainHeight, cb) {
|
BlockDb.prototype._fillConfirmationsOne = function(o, chainHeight, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.getBlockForTx(o.txid, function(err, hash, height) {
|
self.getBlockForTx(o.txid, function(err, hash, height) {
|
||||||
@ -360,8 +395,7 @@ BlockDb.prototype._fillConfirmationsOne = function(o, chainHeight, cb) {
|
|||||||
o.isConfirmed = chainHeight >= height;
|
o.isConfirmed = chainHeight >= height;
|
||||||
o.confirmations = chainHeight - height + 1;
|
o.confirmations = chainHeight - height + 1;
|
||||||
return self._fillConfirmationsOneSpent(o, chainHeight, cb);
|
return self._fillConfirmationsOneSpent(o, chainHeight, cb);
|
||||||
}
|
} else return cb();
|
||||||
else return cb();
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -385,6 +419,19 @@ BlockDb.prototype.fillConfirmations = function(txouts, cb) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BlockDb.prototype.fillVinConfirmations = function(tx, cb) {
|
||||||
|
var self = this;
|
||||||
|
this.getTip(function(err, hash, height) {
|
||||||
|
var vin = tx.vin;
|
||||||
|
if (!vin) return cb();
|
||||||
|
|
||||||
|
async.eachLimit(vin, CONCURRENCY, function(v, e_c) {
|
||||||
|
self._fillConfirmationsOneVin(v, height, e_c);
|
||||||
|
}, cb);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/* this is only for migration scripts */
|
/* this is only for migration scripts */
|
||||||
BlockDb.prototype._runScript = function(script, cb) {
|
BlockDb.prototype._runScript = function(script, cb) {
|
||||||
db.batch(script, cb);
|
db.batch(script, cb);
|
||||||
@ -436,7 +483,9 @@ BlockDb.prototype.migrateV02cleanup = function(cb) {
|
|||||||
start: k,
|
start: k,
|
||||||
end: k + '~'
|
end: k + '~'
|
||||||
})
|
})
|
||||||
.pipe(d.createWriteStream({type:'del'}))
|
.pipe(d.createWriteStream({
|
||||||
|
type: 'del'
|
||||||
|
}))
|
||||||
.on('close', function(err) {
|
.on('close', function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
console.log('## deleting tx- from txs db'); //todo
|
console.log('## deleting tx- from txs db'); //todo
|
||||||
@ -447,7 +496,9 @@ BlockDb.prototype.migrateV02cleanup = function(cb) {
|
|||||||
start: k,
|
start: k,
|
||||||
end: k + '~'
|
end: k + '~'
|
||||||
})
|
})
|
||||||
.pipe(d.createWriteStream({type:'del'}))
|
.pipe(d.createWriteStream({
|
||||||
|
type: 'del'
|
||||||
|
}))
|
||||||
.on('close', function(err) {
|
.on('close', function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
var k = 'txa-';
|
var k = 'txa-';
|
||||||
@ -456,7 +507,9 @@ BlockDb.prototype.migrateV02cleanup = function(cb) {
|
|||||||
start: k,
|
start: k,
|
||||||
end: k + '~'
|
end: k + '~'
|
||||||
})
|
})
|
||||||
.pipe(d.createWriteStream({type:'del'}))
|
.pipe(d.createWriteStream({
|
||||||
|
type: 'del'
|
||||||
|
}))
|
||||||
.on('close', cb);
|
.on('close', cb);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -198,7 +198,6 @@ TransactionDb.prototype._fillOutpoints = function(txInfo, cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
txInfo.firstSeenTs = ret.ts;
|
txInfo.firstSeenTs = ret.ts;
|
||||||
i.unconfirmedInput = i.unconfirmedInput;
|
|
||||||
i.addr = ret.addr;
|
i.addr = ret.addr;
|
||||||
i.valueSat = ret.valueSat;
|
i.valueSat = ret.valueSat;
|
||||||
i.value = ret.valueSat / util.COIN;
|
i.value = ret.valueSat / util.COIN;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "insight-bitcore-api",
|
"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.",
|
"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.13",
|
"version": "0.2.15",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Ryan X Charles",
|
"name": "Ryan X Charles",
|
||||||
"email": "ryan@bitpay.com"
|
"email": "ryan@bitpay.com"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user