Update index.js

This commit is contained in:
sairajzero 2023-01-28 17:20:34 +05:30
parent 35c506ac65
commit f73ccfd02e

View File

@ -373,50 +373,6 @@ AddressService.prototype._setInputResults = function(tx, address, result) {
}
};
AddressService.prototype._aggregateAddressSummaryResult = function (tx, address, result, options){
var self = this;
let output = self._getOutputResults(tx, address);
let input = self._getInputResults(tx, address);
//Since tx with multiple (x) input/output occurances of address will invoke this fn x time(s), (as we are not storing txid and hence cannot check for duplications)
//we divide the values by x and aggregate it to result.
//eg. tx with 1 input, 1 output => x=1+1=2.... input_val = 2, output_val = 1.
//the values will be aggregated 2 times, hence, we divide values by x i.e, 2.
//now agg_input_val = 2/2 =1, agg_output_val = 1/2 =0.5
//the fn ll be called x times, hence the total result will be, result=agg*x: input(1*2=2), output(0.5*2=1)
let total_count = input.count + output.count;
let div_input_val = input.value / total_count,
div_output_val = output.value / total_count;
//aggregate the result
txApperances += 1/total_count;
totalReceivedSat += div_output_val;
balanceSat += div_output_val;
totalSentSat += div_input_val;
balanceSat -= div_output_val;
if(!tx.confirmations){
unconfirmedTxApperances += 1/total_count;
unconfirmedBalanceSat += div_output_val;
unconfirmedBalanceSat -= div_input_val;
}
if (!options.noTxList) {
if (!result.transactions) {
result.transactions = [];
}
let txid = tx.txid();
if(!result.transactions.includes(txid)) //push txid only if its not in the array
result.transactions.push(txid);
}
}
AddressService.prototype._getAddressSummaryResult = function(txs, address, result, options) {
var self = this;
@ -481,6 +437,50 @@ AddressService.prototype._getInputResults = function(tx, address) {
};
AddressService.prototype._aggregateAddressSummaryResult = function (tx, address, result, options){
var self = this;
let output = self._getOutputResults(tx, address);
let input = self._getInputResults(tx, address);
//Since tx with multiple (x) input/output occurances of address will invoke this fn x time(s), (as we are not storing txid and hence cannot check for duplications)
//we divide the values by x and aggregate it to result.
//eg. tx with 1 input, 1 output => x=1+1=2.... input_val = 2, output_val = 1.
//the values will be aggregated 2 times, hence, we divide values by x i.e, 2.
//now agg_input_val = 2/2 =1, agg_output_val = 1/2 =0.5
//the fn ll be called x times, hence the total result will be, result=agg*x: input(1*2=2), output(0.5*2=1)
let total_count = input.count + output.count;
let div_input_val = input.value / total_count,
div_output_val = output.value / total_count;
//aggregate the result
result.txApperances += 1/total_count;
result.totalReceivedSat += div_output_val;
result.balanceSat += div_output_val;
result.totalSentSat += div_input_val;
result.balanceSat -= div_output_val;
if(!tx.confirmations){
result.unconfirmedTxApperances += 1/total_count;
result.unconfirmedBalanceSat += div_output_val;
result.unconfirmedBalanceSat -= div_input_val;
}
if (!options.noTxList) {
if (!result.transactions) {
result.transactions = [];
}
let txid = tx.txid();
if(!result.transactions.includes(txid)) //push txid only if its not in the array
result.transactions.push(txid);
}
}
AddressService.prototype.getAddressUnspentOutputs = function(address, options, callback) {
var self = this;