Add support for vin/vout hashes inside an array

-Some blockchains store certain vin or vout addresses within an array instead of as a simple string which would cause them to be read improperly by the explorer and result in transactions that were not attributed to the proper address. It also caused multiple inputs/outputs from the same address in a single transaction to not be grouped together like other transactions in the explorer
This commit is contained in:
Joe Uhren
2022-07-17 14:28:58 -06:00
parent 58bd8ffec8
commit bfbc50beda
2 changed files with 31 additions and 0 deletions
+12
View File
@@ -122,6 +122,12 @@ function save_tx(txid, blockheight, cb) {
lib.syncLoop(vin.length, function (loop) {
var i = loop.iteration();
// check if address is inside an array
if (Array.isArray(nvin[i].addresses)) {
// extract the address
nvin[i].addresses = nvin[i].addresses[0];
}
update_address(nvin[i].addresses, blockheight, txid, nvin[i].amount, 'vin', function() {
loop.next();
});
@@ -129,6 +135,12 @@ function save_tx(txid, blockheight, cb) {
lib.syncLoop(vout.length, function (subloop) {
var t = subloop.iteration();
// check if address is inside an array
if (Array.isArray(vout[t].addresses)) {
// extract the address
vout[t].addresses = vout[t].addresses[0];
}
if (vout[t].addresses) {
update_address(vout[t].addresses, blockheight, txid, vout[t].amount, 'vout', function() {
subloop.next();
+19
View File
@@ -72,6 +72,12 @@ function convertHashUnits(hashes) {
function processVoutAddresses(address_list, vout_value, arr_vout, cb) {
// check if there are any addresses to process
if (address_list != null && address_list.length > 0) {
// check if vout address is inside an array
if (Array.isArray(address_list[0])) {
// extract the address
address_list[0] = address_list[0][0];
}
// 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], 'addresses', function(unique, index) {
if (unique == true) {
@@ -1233,6 +1239,12 @@ module.exports = {
if (tx.vout[i].scriptPubKey.addresses || tx.vout[i].scriptPubKey.address) {
var new_address = tx.vout[i].scriptPubKey.address || tx.vout[i].scriptPubKey.addresses[0];
// check if address is inside an array
if (Array.isArray(new_address)) {
// extract the address
new_address = new_address[0];
}
module.exports.is_unique(addresses, new_address, 'hash', function(unique, index) {
if (unique == true)
addresses.push({hash: new_address, amount: tx.vout[i].value});
@@ -1252,6 +1264,13 @@ module.exports = {
if (p2pkh_address != null) {
// mark this tx as p2pk
tx_type = 'p2pk';
// check if address is inside an array
if (Array.isArray(p2pkh_address)) {
// extract the address
p2pkh_address = p2pkh_address[0];
}
// save the P2PKH address
module.exports.is_unique(addresses, p2pkh_address, 'hash', function(unique, index) {
if (unique == true)