Better vout/vin unique checks
This commit is contained in:
+60
-27
@@ -73,7 +73,7 @@ function processVoutAddresses(address_list, vout_value, arr_vout, cb) {
|
|||||||
// check if there are any addresses to process
|
// check if there are any addresses to process
|
||||||
if (address_list != null && address_list.length > 0) {
|
if (address_list != null && address_list.length > 0) {
|
||||||
// check if vout address is unique, if so add to array, if not add its amount to existing index
|
// check if vout address is unique, if so add to array, if not add its amount to existing index
|
||||||
module.exports.is_unique(arr_vout, address_list[0], function(unique, index) {
|
module.exports.is_unique(arr_vout, address_list[0], 'addresses', function(unique, index) {
|
||||||
if (unique == true) {
|
if (unique == true) {
|
||||||
// unique vout
|
// unique vout
|
||||||
module.exports.convert_to_satoshi(parseFloat(vout_value), function(amount_sat) {
|
module.exports.convert_to_satoshi(parseFloat(vout_value), function(amount_sat) {
|
||||||
@@ -980,14 +980,14 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
is_unique: function(array, object, cb) {
|
is_unique: function(array, object, key_name, cb) {
|
||||||
var unique = true;
|
var unique = true;
|
||||||
var index = null;
|
var index = null;
|
||||||
|
|
||||||
module.exports.syncLoop(array.length, function (loop) {
|
module.exports.syncLoop(array.length, function (loop) {
|
||||||
var i = loop.iteration();
|
var i = loop.iteration();
|
||||||
|
|
||||||
if (array[i].addresses == object) {
|
if (array[i][key_name] == object) {
|
||||||
unique = false;
|
unique = false;
|
||||||
index = i;
|
index = i;
|
||||||
loop.break(true);
|
loop.break(true);
|
||||||
@@ -1044,18 +1044,24 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// could not decipher the address, save as unknown and move to next vout
|
// could not decipher the address, save as unknown and move to next vout
|
||||||
module.exports.convert_to_satoshi(parseFloat(vout[i].value), function(amount_sat) {
|
console.log('Failed to find vout address from tx ' + txid);
|
||||||
console.log('Failed to find vout address from tx ' + txid);
|
// process vout addresses
|
||||||
arr_vout.push({addresses: 'unknown_address', amount: amount_sat});
|
processVoutAddresses(['unknown_address'], vout[i].value, arr_vout, function(vout_array) {
|
||||||
|
// save updated array
|
||||||
|
arr_vout = vout_array;
|
||||||
|
// move to next vout
|
||||||
loop.next();
|
loop.next();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// could not decipher the address, save as unknown and move to next vout
|
// could not decipher the address, save as unknown and move to next vout
|
||||||
module.exports.convert_to_satoshi(parseFloat(vout[i].value), function(amount_sat) {
|
console.log('Failed to find vout address from tx ' + txid);
|
||||||
console.log('Failed to find vout address from tx ' + txid);
|
// process vout addresses
|
||||||
arr_vout.push({addresses: 'unknown_address', amount: amount_sat});
|
processVoutAddresses(['unknown_address'], vout[i].value, arr_vout, function(vout_array) {
|
||||||
|
// save updated array
|
||||||
|
arr_vout = vout_array;
|
||||||
|
// move to next vout
|
||||||
loop.next();
|
loop.next();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1105,7 +1111,7 @@ module.exports = {
|
|||||||
// save updated array
|
// save updated array
|
||||||
arr_vout = vout_array;
|
arr_vout = vout_array;
|
||||||
// add a private send address with the known amount sent
|
// add a private send address with the known amount sent
|
||||||
module.exports.is_unique(arr_vin, 'hidden_address', function(unique, index) {
|
module.exports.is_unique(arr_vin, 'hidden_address', 'addresses', function(unique, index) {
|
||||||
if (unique == true) {
|
if (unique == true) {
|
||||||
module.exports.convert_to_satoshi(parseFloat(vhidden[i].vpub_new), function(amount_sat) {
|
module.exports.convert_to_satoshi(parseFloat(vhidden[i].vpub_new), function(amount_sat) {
|
||||||
arr_vin.push({addresses: 'hidden_address', amount: amount_sat});
|
arr_vin.push({addresses: 'hidden_address', amount: amount_sat});
|
||||||
@@ -1122,7 +1128,7 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
module.exports.is_unique(arr_vin, 'hidden_address', function(unique, index) {
|
module.exports.is_unique(arr_vin, 'hidden_address', 'addresses', function(unique, index) {
|
||||||
if (unique == true) {
|
if (unique == true) {
|
||||||
module.exports.convert_to_satoshi(parseFloat(vhidden[i].vpub_new), function(amount_sat) {
|
module.exports.convert_to_satoshi(parseFloat(vhidden[i].vpub_new), function(amount_sat) {
|
||||||
arr_vin.push({addresses: 'hidden_address', amount: amount_sat});
|
arr_vin.push({addresses: 'hidden_address', amount: amount_sat});
|
||||||
@@ -1185,10 +1191,15 @@ module.exports = {
|
|||||||
|
|
||||||
if (tx.vout[i].n == input.vout) {
|
if (tx.vout[i].n == input.vout) {
|
||||||
if (tx.vout[i].scriptPubKey.addresses) {
|
if (tx.vout[i].scriptPubKey.addresses) {
|
||||||
addresses.push({hash: tx.vout[i].scriptPubKey.addresses[0], amount:tx.vout[i].value});
|
module.exports.is_unique(addresses, tx.vout[i].scriptPubKey.addresses[0], 'hash', function(unique, index) {
|
||||||
|
if (unique == true)
|
||||||
|
addresses.push({hash: tx.vout[i].scriptPubKey.addresses[0], amount: tx.vout[i].value});
|
||||||
|
else
|
||||||
|
addresses[index].amount = addresses[index].amount + tx.vout[i].value;
|
||||||
|
|
||||||
loop.break(true);
|
loop.break(true);
|
||||||
loop.next();
|
loop.next();
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// no addresses defined
|
// no addresses defined
|
||||||
// check if bitcoin features are enabled
|
// check if bitcoin features are enabled
|
||||||
@@ -1200,23 +1211,41 @@ module.exports = {
|
|||||||
// mark this tx as p2pk
|
// mark this tx as p2pk
|
||||||
tx_type = 'p2pk';
|
tx_type = 'p2pk';
|
||||||
// save the P2PKH address
|
// save the P2PKH address
|
||||||
addresses.push({hash: p2pkh_address, amount: tx.vout[i].value});
|
module.exports.is_unique(addresses, p2pkh_address, 'hash', function(unique, index) {
|
||||||
|
if (unique == true)
|
||||||
|
addresses.push({hash: p2pkh_address, amount: tx.vout[i].value});
|
||||||
|
else
|
||||||
|
addresses[index].amount = addresses[index].amount + tx.vout[i].value;
|
||||||
|
|
||||||
|
loop.break(true);
|
||||||
|
loop.next();
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// could not decipher the address, save as unknown and move to next vin
|
// could not decipher the address, save as unknown and move to next vin
|
||||||
addresses.push({hash: 'unknown_address', amount: tx.vout[i].value});
|
|
||||||
console.log('Failed to find vin address from tx ' + input.txid);
|
console.log('Failed to find vin address from tx ' + input.txid);
|
||||||
|
module.exports.is_unique(addresses, 'unknown_address', 'hash', function(unique, index) {
|
||||||
|
if (unique == true)
|
||||||
|
addresses.push({hash: 'unknown_address', amount: tx.vout[i].value});
|
||||||
|
else
|
||||||
|
addresses[index].amount = addresses[index].amount + tx.vout[i].value;
|
||||||
|
|
||||||
|
loop.break(true);
|
||||||
|
loop.next();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// could not decipher the address, save as unknown and move to next vin
|
||||||
|
console.log('Failed to find vin address from tx ' + input.txid);
|
||||||
|
module.exports.is_unique(addresses, 'unknown_address', 'hash', function(unique, index) {
|
||||||
|
if (unique == true)
|
||||||
|
addresses.push({hash: 'unknown_address', amount: tx.vout[i].value});
|
||||||
|
else
|
||||||
|
addresses[index].amount = addresses[index].amount + tx.vout[i].value;
|
||||||
|
|
||||||
loop.break(true);
|
loop.break(true);
|
||||||
loop.next();
|
loop.next();
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
// could not decipher the address, save as unknown and move to next vin
|
|
||||||
addresses.push({hash: 'unknown_address', amount: tx.vout[i].value});
|
|
||||||
console.log('Failed to find vin address from tx ' + input.txid);
|
|
||||||
|
|
||||||
loop.break(true);
|
|
||||||
loop.next();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
@@ -1245,10 +1274,10 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (addresses && addresses.length) {
|
if (addresses && addresses.length) {
|
||||||
module.exports.is_unique(arr_vin, addresses[0].hash, function(unique, index) {
|
module.exports.is_unique(arr_vin, addresses[0].hash, 'addresses', function(unique, index) {
|
||||||
if (unique == true) {
|
if (unique == true) {
|
||||||
module.exports.convert_to_satoshi(parseFloat(addresses[0].amount), function(amount_sat) {
|
module.exports.convert_to_satoshi(parseFloat(addresses[0].amount), function(amount_sat) {
|
||||||
arr_vin.push({addresses:addresses[0].hash, amount:amount_sat});
|
arr_vin.push({addresses: addresses[0].hash, amount: amount_sat});
|
||||||
loop.next();
|
loop.next();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -1261,8 +1290,12 @@ module.exports = {
|
|||||||
} else {
|
} else {
|
||||||
// could not decipher the address, save as unknown and move to next vin
|
// could not decipher the address, save as unknown and move to next vin
|
||||||
console.log('Failed to find vin address from tx ' + tx.txid);
|
console.log('Failed to find vin address from tx ' + tx.txid);
|
||||||
arr_vin.push({addresses: 'unknown_address', amount: 0});
|
module.exports.is_unique(arr_vin, 'unknown_address', 'addresses', function(unique, index) {
|
||||||
loop.next();
|
if (unique == true)
|
||||||
|
arr_vin.push({addresses: 'unknown_address', amount: 0});
|
||||||
|
|
||||||
|
loop.next();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, function() {
|
}, function() {
|
||||||
|
|||||||
@@ -38,28 +38,28 @@ describe('explorer', function() {
|
|||||||
];
|
];
|
||||||
|
|
||||||
it('should return index of matching string object', function() {
|
it('should return index of matching string object', function() {
|
||||||
lib.is_unique(arrayStrMap, arrayStrMap[2].addresses, function(unique, index) {
|
lib.is_unique(arrayStrMap, arrayStrMap[2].addresses, 'addresses', function(unique, index) {
|
||||||
expect(index).toEqual(2);
|
expect(index).toEqual(2);
|
||||||
expect(unique).toEqual(false);
|
expect(unique).toEqual(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return index of matching array object', function() {
|
it('should return index of matching array object', function() {
|
||||||
lib.is_unique(arrayArrMap, arrayArrMap[2].addresses, function(unique, index) {
|
lib.is_unique(arrayArrMap, arrayArrMap[2].addresses, 'addresses', function(unique, index) {
|
||||||
expect(index).toEqual(2);
|
expect(index).toEqual(2);
|
||||||
expect(unique).toEqual(false);
|
expect(unique).toEqual(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true if no matching string object', function() {
|
it('should return true if no matching string object', function() {
|
||||||
lib.is_unique(arrayStrMap, 'unique', function(unique, index) {
|
lib.is_unique(arrayStrMap, 'unique', 'addresses', function(unique, index) {
|
||||||
expect(index).toEqual(null);
|
expect(index).toEqual(null);
|
||||||
expect(unique).toEqual(true);
|
expect(unique).toEqual(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true if no matching array object', function() {
|
it('should return true if no matching array object', function() {
|
||||||
lib.is_unique(arrayArrMap, ['unique'], function(unique, index) {
|
lib.is_unique(arrayArrMap, ['unique'], 'addresses', function(unique, index) {
|
||||||
expect(index).toEqual(null);
|
expect(index).toEqual(null);
|
||||||
expect(unique).toEqual(true);
|
expect(unique).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user