Drop duplicated code on addressService
This commit is contained in:
parent
a2a6f03c50
commit
61f99d94b5
@ -53,41 +53,37 @@ AddressService.processOutput = function(data) {
|
|||||||
return output;
|
return output;
|
||||||
};
|
};
|
||||||
|
|
||||||
AddressService.prototype.getAllOutputs = function(address) {
|
var retrieveOutputs = function(indexFunction, processElement) {
|
||||||
var results = [];
|
return function(address) {
|
||||||
var self = this;
|
var results = [];
|
||||||
|
var self = this;
|
||||||
|
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
self.database.createReadStream({
|
self.database.createReadStream({
|
||||||
gte: TransactionService.Index.getOutputsForAddress(address, NULLTXHASH, 0),
|
gte: indexFunction(address, NULLTXHASH, 0),
|
||||||
lte: TransactionService.Index.getOutputsForAddress(address, LASTTXHASH, MAXOUTPUT)
|
lte: indexFunction(address, LASTTXHASH, MAXOUTPUT)
|
||||||
}).on('data', function(element) {
|
}).on('data', function(element) {
|
||||||
results.push(AddressService.processOutput(element));
|
results.push(processElement(element));
|
||||||
}).on('error', function() {
|
}).on('error', reject).on('end', function() {
|
||||||
return reject();
|
return resolve(results);
|
||||||
}).on('end', function() {
|
});
|
||||||
return resolve(results);
|
|
||||||
});
|
});
|
||||||
});
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
AddressService.prototype.getSpent = function(address) {
|
AddressService.prototype.getAllOutputs = retrieveOutputs(
|
||||||
var results = [];
|
TransactionService.Index.getOutputsForAddress,
|
||||||
var self = this;
|
function(e) {
|
||||||
|
return AddressService.processOutput(e);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return new Promise(function(resolve, reject) {
|
AddressService.prototype.getSpent = retrieveOutputs(
|
||||||
self.database.createReadStream({
|
TransactionService.Index.getSpentOutputsForAddress,
|
||||||
gte: TransactionService.Index.getSpentOutputsForAddress(address, NULLTXHASH, 0),
|
function(element) {
|
||||||
lte: TransactionService.Index.getSpentOutputsForAddress(address, LASTTXHASH, MAXOUTPUT)
|
return JSON.parse(element.value);
|
||||||
}).on('data', function(element) {
|
}
|
||||||
results.push(JSON.parse(element.value));
|
);
|
||||||
}).on('error', function(err) {
|
|
||||||
return reject(err);
|
|
||||||
}).on('end', function() {
|
|
||||||
return resolve(results);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
AddressService.prototype.buildAddressSummary = function(address, tip, allOutputs, spent, confirmations) {
|
AddressService.prototype.buildAddressSummary = function(address, tip, allOutputs, spent, confirmations) {
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user