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