getTransactionsForAddress() without mempool
This commit is contained in:
parent
32000bc5ff
commit
d5801c9172
|
@ -31,7 +31,8 @@ AddressModule.prototype.getAPIMethods = function() {
|
||||||
['getBalance', this, this.getBalance, 2],
|
['getBalance', this, this.getBalance, 2],
|
||||||
['getOutputs', this, this.getOutputs, 2],
|
['getOutputs', this, this.getOutputs, 2],
|
||||||
['getUnspentOutputs', this, this.getUnspentOutputs, 2],
|
['getUnspentOutputs', this, this.getUnspentOutputs, 2],
|
||||||
['isSpent', this, this.isSpent, 2]
|
['isSpent', this, this.isSpent, 2],
|
||||||
|
['getTransactionsForAddress', this, this.getTransactionsForAddress, 2]
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -281,4 +282,55 @@ AddressModule.prototype.isSpent = function(output, queryMempool, callback) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AddressModule.prototype.getTransactionsForAddress = function(address, queryMempool, callback) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
var txids = [];
|
||||||
|
var key = [AddressModule.PREFIXES.OUTPUTS, address].join('-');
|
||||||
|
|
||||||
|
var stream = this.db.store.createReadStream({
|
||||||
|
start: key,
|
||||||
|
end: key + '~'
|
||||||
|
});
|
||||||
|
|
||||||
|
stream.on('data', function(data) {
|
||||||
|
var key = data.key.split('-');
|
||||||
|
txids.push(key[3]);
|
||||||
|
});
|
||||||
|
|
||||||
|
var error;
|
||||||
|
|
||||||
|
stream.on('error', function(streamError) {
|
||||||
|
if (streamError) {
|
||||||
|
error = streamError;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
stream.on('close', function() {
|
||||||
|
if (error) {
|
||||||
|
return callback(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
async.map(
|
||||||
|
txids,
|
||||||
|
function(txid, next) {
|
||||||
|
self.db.getTransaction(txid, next);
|
||||||
|
},
|
||||||
|
function(err, transactions) {
|
||||||
|
if(err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(queryMempool) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(null, transactions);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return stream;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = AddressModule;
|
module.exports = AddressModule;
|
Loading…
Reference in New Issue