API improvements

This commit is contained in:
sairajzero 2023-02-04 20:33:18 +05:30
parent 450e6b9d21
commit 729072738b

View File

@ -329,6 +329,8 @@ AddressService.prototype.getAddressSummary = function(address, options, streamer
result.totalReceivedSat = parseInt(result.totalReceivedSat.toFixed());
result.totalSentSat = parseInt(result.totalSentSat.toFixed());
result.txApperances = parseInt(result.txApperances.toFixed());
result.unconfirmedBalanceSat = parseInt(result.unconfirmedBalanceSat.toFixed());
result.unconfirmedTxApperances = parseInt(result.unconfirmedTxApperances.toFixed());
result.balance = Unit.fromSatoshis(result.balanceSat).toBTC();
result.totalReceived = Unit.fromSatoshis(result.totalReceivedSat).toBTC();
@ -659,10 +661,19 @@ AddressService.prototype.stop = function(callback) {
AddressService.prototype._getTxidStream = function(address, options) {
var start = this._encoding.encodeAddressIndexKey(address);
var start;
if(options.after) {
start = this._encoding.encodeAddressIndexKey(address, options.start, options.after, 0xffffffff, 1, 0xffffffff); //0xffffffff is for getting after the txid
} else {
start = this._encoding.encodeAddressIndexKey(address, options.start);
}
var endHeightBuf = new Buffer(4);
endHeightBuf.writeUInt32BE(options.end);
var end = Buffer.concat([
start.slice(0, address.length + 4),
options.endHeightBuf,
endHeightBuf,
new Buffer(new Array(83).join('f'), 'hex')
]);
@ -719,9 +730,6 @@ AddressService.prototype._getAddressTxidHistory = function(address, options, cal
var results = [];
options.endHeightBuf = new Buffer(4);
options.endHeightBuf.writeUInt32BE(options.end);
if (_.isUndefined(options.queryMempool)) {
options.queryMempool = true;
}
@ -802,13 +810,6 @@ AddressService.prototype._streamAddressSummary = function(address, options, stre
options.queryMempool = true;
}
options.endHeightBuf = new Buffer(4);
options.endHeightBuf.writeUInt32BE(options.end);
if (_.isUndefined(options.queryMempool)) {
options.queryMempool = true;
}
//declare the queue to process tx data
var tmpTxList = {}; //store processed txid temporarily to ignore duplication
@ -866,7 +867,7 @@ AddressService.prototype._streamAddressSummary = function(address, options, stre
streamer(err, tx);
if(err){
if(err || options.flag_stop){
q.kill();
return callback();
@ -896,6 +897,31 @@ AddressService.prototype._streamAddressSummary = function(address, options, stre
mempoolTxids.map(id => q.push(id, chunkCallback));
next();
},
function(next){
if(_.isUndefined(options.after)) {
return next();
}
self._transaction.getTransaction(id.txid, options, function(err, tx) {
if(tx && tx.confirmations && tx.height > options.start) {
options.start = tx.height;
} else {
delete options.after;
}
next();
});
},
// stream the rest of the confirmed txids out of the address index
function(next) {
@ -920,6 +946,10 @@ AddressService.prototype._streamAddressSummary = function(address, options, stre
});
txIdTransformStream._transform = function(chunk, enc, cb) {
if(options.flag_stop)//stop data query
return txIdTransformStream.unpipe();
var txInfo = self._encoding.decodeAddressIndexKey(chunk);
q.push({ txid: txInfo.txid, height: txInfo.height }, chunkCallback);