Removed utxo cache and removed max addresses limiting.
This commit is contained in:
parent
41b304c5a5
commit
d2ae088d8e
@ -6,7 +6,6 @@ var async = require('async');
|
|||||||
var TxController = require('./transactions');
|
var TxController = require('./transactions');
|
||||||
var Common = require('./common');
|
var Common = require('./common');
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var LRU = require('lru-cache');
|
|
||||||
|
|
||||||
function AddressController(node) {
|
function AddressController(node) {
|
||||||
this.node = node;
|
this.node = node;
|
||||||
@ -15,14 +14,6 @@ function AddressController(node) {
|
|||||||
this.txController = new TxController(node);
|
this.txController = new TxController(node);
|
||||||
this.common = new Common({log: this.node.log});
|
this.common = new Common({log: this.node.log});
|
||||||
this._block = this.node.services.block;
|
this._block = this.node.services.block;
|
||||||
this._utxoCache = new LRU({
|
|
||||||
max: 250,
|
|
||||||
maxAge: 1000 * 10
|
|
||||||
});
|
|
||||||
// limit the size of the request to about 100,000 bytes
|
|
||||||
// we'll use 34 bytes as the size of each address.
|
|
||||||
this._maxAddresses = Math.floor(100000/34);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AddressController.prototype.show = function(req, res) {
|
AddressController.prototype.show = function(req, res) {
|
||||||
@ -151,12 +142,6 @@ AddressController.prototype.check = function(addresses) {
|
|||||||
AddressController.prototype.utxo = function(req, res) {
|
AddressController.prototype.utxo = function(req, res) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var cachedUtxos = this._utxoCache.get(req.addr);
|
|
||||||
|
|
||||||
if (cachedUtxos) {
|
|
||||||
return res.jsonp(cachedUtxos);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._address.getAddressUnspentOutputs(req.addr, {}, function(err, utxos) {
|
this._address.getAddressUnspentOutputs(req.addr, {}, function(err, utxos) {
|
||||||
var results;
|
var results;
|
||||||
if(err) {
|
if(err) {
|
||||||
@ -165,7 +150,6 @@ AddressController.prototype.utxo = function(req, res) {
|
|||||||
results = [];
|
results = [];
|
||||||
}
|
}
|
||||||
results = utxos.map(self.transformUtxo.bind(self));
|
results = utxos.map(self.transformUtxo.bind(self));
|
||||||
self._utxoCache.set(req.addr, results);
|
|
||||||
res.jsonp(results);
|
res.jsonp(results);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -214,18 +198,6 @@ AddressController.prototype.multiutxo = function(req, res) {
|
|||||||
addresses = _.compact(req.addrs.split(','));
|
addresses = _.compact(req.addrs.split(','));
|
||||||
}
|
}
|
||||||
|
|
||||||
var cacheKey = addresses.join('');
|
|
||||||
|
|
||||||
if (addresses.length > this._maxAddresses) {
|
|
||||||
return self.common.handleErrors(new Error('Too many addresses.'), res);
|
|
||||||
}
|
|
||||||
|
|
||||||
var cachedUtxos = this._utxoCache.get(cacheKey);
|
|
||||||
|
|
||||||
if (cachedUtxos) {
|
|
||||||
return res.jsonp(cachedUtxos);
|
|
||||||
}
|
|
||||||
|
|
||||||
var addressesLeft = addresses.length;
|
var addressesLeft = addresses.length;
|
||||||
var startedWriting = false;
|
var startedWriting = false;
|
||||||
var cache = [];
|
var cache = [];
|
||||||
@ -266,8 +238,6 @@ AddressController.prototype.multiutxo = function(req, res) {
|
|||||||
return self.common.handleErrors(err, res);
|
return self.common.handleErrors(err, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
self._utxoCache.set(cacheKey, cache);
|
|
||||||
|
|
||||||
res.write(']');
|
res.write(']');
|
||||||
res.end();
|
res.end();
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user