bitcoind: add address utxos
This commit is contained in:
parent
7d7dfe329d
commit
ab70aa666e
@ -36,6 +36,7 @@ function Bitcoin(options) {
|
||||
Service.call(this, options);
|
||||
|
||||
// caches valid until there is a new block
|
||||
this.utxosCache = LRU(50000);
|
||||
this.txidsCache = LRU(50000);
|
||||
this.balanceCache = LRU(50000);
|
||||
this.summaryCache = LRU(50000);
|
||||
@ -146,6 +147,7 @@ Bitcoin.prototype._loadConfiguration = function() {
|
||||
};
|
||||
|
||||
Bitcoin.prototype._resetCaches = function() {
|
||||
this.utxosCache.reset();
|
||||
this.txidsCache.reset();
|
||||
this.balanceCache.reset();
|
||||
this.summaryCache.reset();
|
||||
@ -369,8 +371,27 @@ Bitcoin.prototype.getAddressBalance = function(addressArg, options, callback) {
|
||||
}
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getAddressUnspentOutputs = function() {
|
||||
// TODO add this rpc method to bitcoind
|
||||
Bitcoin.prototype.getAddressUnspentOutputs = function(addressArg, options, callback) {
|
||||
var self = this;
|
||||
var addresses = [addressArg];
|
||||
if (Array.isArray(addressArg)) {
|
||||
addresses = addressArg;
|
||||
}
|
||||
var cacheKey = addresses.join('');
|
||||
var utxos = self.utxosCache.get(cacheKey);
|
||||
if (utxos) {
|
||||
return setImmediate(function() {
|
||||
callback(null, utxos);
|
||||
});
|
||||
} else {
|
||||
self.client.getAddressUtxos({addresses: addresses}, function(err, response) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
self.utxosCache.set(cacheKey, response.result);
|
||||
callback(null, response.result);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Bitcoin.prototype.getAddressTxids = function(addressArg, options, callback) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user