Merge pull request #457 from matiu/opt/scriptPubKeyCache
Opt/script pub key cache
This commit is contained in:
commit
0fccc1c915
@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var imports = require('soop').imports();
|
||||
var _ = require('lodash');
|
||||
|
||||
|
||||
|
||||
@ -248,7 +249,7 @@ TransactionDb.prototype._getInfo = function(txid, next, opts) {
|
||||
self._fillOutpoints(txInfo, function() {
|
||||
|
||||
if (opts.noExtraInfo)
|
||||
return next(null,txInfo);
|
||||
return next(null, txInfo);
|
||||
|
||||
self._fillSpent(txInfo, function() {
|
||||
return next(null, txInfo);
|
||||
@ -394,22 +395,25 @@ TransactionDb.prototype.cacheScriptPubKey = function(txouts, cb) {
|
||||
// console.log('[TransactionDb.js.381:cacheScriptPubKey:]'); //TODO
|
||||
var self = this;
|
||||
var dbScript = [];
|
||||
for (var ii in txouts) {
|
||||
var txout = txouts[ii];
|
||||
_.each(txouts, function(txout) {
|
||||
|
||||
//everything already cached?
|
||||
if (txout.scriptPubKeyCached || txout.spentTxId) {
|
||||
continue;
|
||||
}
|
||||
if (txout.scriptPubKeyCached || txout.spentTxId)
|
||||
return;
|
||||
|
||||
// not hard confirmed ?
|
||||
if (!txout.isConfirmedCached && !txout.confirmedWillBeCached)
|
||||
return;
|
||||
|
||||
if (txout.scriptPubKey) {
|
||||
var infoToCache = [txout.value_sat, (txout.isConfirmedCached || txout.confirmedWillBeCached) ? 1 : 0, txout.scriptPubKey];
|
||||
var infoToCache = [txout.value_sat, 1, txout.scriptPubKey];
|
||||
dbScript.push({
|
||||
type: 'put',
|
||||
key: txout.key,
|
||||
value: infoToCache.join(':'),
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
db.batch(dbScript, cb);
|
||||
};
|
||||
|
||||
@ -560,8 +564,12 @@ TransactionDb.prototype.getStandardizedTx = function(tx, time, isCoinBase) {
|
||||
|
||||
TransactionDb.prototype.fillScriptPubKey = function(txouts, cb) {
|
||||
var self = this;
|
||||
var allCached = true;
|
||||
// Complete utxo info
|
||||
async.eachLimit(txouts, CONCURRENCY, function(txout, a_c) {
|
||||
if (txout.scriptPubKeyCached) return a_c();
|
||||
allCached = false;
|
||||
|
||||
self.fromIdInfoSimple(txout.txid, function(err, info) {
|
||||
if (!info || !info.vout) return a_c(err);
|
||||
|
||||
@ -569,6 +577,8 @@ TransactionDb.prototype.fillScriptPubKey = function(txouts, cb) {
|
||||
return a_c();
|
||||
});
|
||||
}, function() {
|
||||
if (allCached)
|
||||
return cb();
|
||||
self.cacheScriptPubKey(txouts, cb);
|
||||
});
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user