Add an "Extracted By" field for block and tx data
-An optional "Extracted By" column can now be added to the homepage tx data, the block page, tx page and/or in the /ext/getlasttxs api -Added 4 new settings to allow displaying the "Extracted By" data on the homepage, block page, transaction page and/or in the /ext/getlasttxs api -Fixed an issue with the get_txs function where it wasn't properly searching by txid -The rl_labels.pug file has been updated to consolidate similar code without being duplicated -Updated the README with new verbiage for the extracted by data
This commit is contained in:
+120
-29
@@ -433,6 +433,46 @@ function after_update_claim_name(hash, claim_name, cb) {
|
||||
});
|
||||
}
|
||||
|
||||
function get_extracted_by_addresses(show_extracted_by, internal, tx, cb) {
|
||||
// check if the extracted by addresses should be found
|
||||
if (show_extracted_by == true) {
|
||||
// check if this is a coinbase tx
|
||||
if (
|
||||
tx != null &&
|
||||
tx.vout != null &&
|
||||
(
|
||||
tx.vin == null ||
|
||||
tx.vin.length === 0 ||
|
||||
(
|
||||
tx.vin.length === 1 &&
|
||||
tx.vin[0].addresses === 'coinbase' &&
|
||||
tx.vin[0].amount != 0
|
||||
)
|
||||
)
|
||||
) {
|
||||
// get a list of all the block reward addresses
|
||||
const extracted_by_addresses = tx.vout.map(v => v.addresses);
|
||||
|
||||
// check if this is an internal call which requires an additional lookup on claim names
|
||||
if (internal) {
|
||||
// add claim name data to the array
|
||||
module.exports.get_extracted_by_claim_names(extracted_by_addresses, function(updated_extracted_by_addresses) {
|
||||
return cb(updated_extracted_by_addresses);
|
||||
});
|
||||
} else {
|
||||
// return the extracted by addresses without looking up claim name data
|
||||
return cb(extracted_by_addresses);
|
||||
}
|
||||
} else {
|
||||
// no extracted by addresses for this tx
|
||||
return cb([]);
|
||||
}
|
||||
} else {
|
||||
// extracted by addresses are not enabled
|
||||
return cb([]);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
// initialize DB
|
||||
connect: function(database, cb) {
|
||||
@@ -680,6 +720,15 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
get_claim_names: function(hash_array, cb) {
|
||||
ClaimAddress.find({ a_id: { $in: hash_array } }).exec().then((claim_records) => {
|
||||
return cb(claim_records);
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
return cb([]);
|
||||
});
|
||||
},
|
||||
|
||||
get_richlist: function(coin, cb) {
|
||||
find_richlist(coin, function(richlist) {
|
||||
return cb(richlist);
|
||||
@@ -861,7 +910,7 @@ module.exports = {
|
||||
let txs = [];
|
||||
|
||||
async.eachSeries(block.tx, function(current_tx, loop) {
|
||||
find_tx(current_tx[i], function(tx) {
|
||||
find_tx(current_tx, function(tx) {
|
||||
if (tx) {
|
||||
// add tx to the list
|
||||
txs.push(tx);
|
||||
@@ -877,41 +926,53 @@ module.exports = {
|
||||
|
||||
get_last_txs: function(start, length, min, internal, cb) {
|
||||
this.get_last_txs_ajax(start, length, min, function(txs, count) {
|
||||
var data = [];
|
||||
const show_extracted_by = (internal ? settings.index_page.show_extracted_by : settings.api_page.public_apis.ext.getlasttxs.show_extracted_by);
|
||||
let data = [];
|
||||
|
||||
for (i = 0; i < txs.length; i++) {
|
||||
if (internal) {
|
||||
var row = [];
|
||||
async.timesSeries(txs.length, function(i, loop) {
|
||||
// get the extracted by address data for this tx
|
||||
get_extracted_by_addresses(show_extracted_by, internal, txs[i], function(extracted_by_addresses) {
|
||||
if (internal) {
|
||||
let row = [];
|
||||
|
||||
row.push(txs[i].blockindex);
|
||||
row.push(txs[i].blockhash);
|
||||
row.push(txs[i].txid);
|
||||
row.push(txs[i].vout.length);
|
||||
row.push((txs[i].total / 100000000));
|
||||
row.push(txs[i].timestamp);
|
||||
row.push(txs[i].blockindex);
|
||||
row.push(txs[i].blockhash);
|
||||
row.push(txs[i].txid);
|
||||
row.push(txs[i].vout.length);
|
||||
row.push((txs[i].total / 100000000));
|
||||
row.push(txs[i].timestamp);
|
||||
|
||||
if (settings.block_page.multi_algorithm.show_algo == true)
|
||||
row.push('algo:' + (txs[i].algo == null ? '' : txs[i].algo));
|
||||
if (settings.block_page.multi_algorithm.show_algo == true)
|
||||
row.push('algo:' + (txs[i].algo == null ? '' : txs[i].algo));
|
||||
|
||||
data.push(row);
|
||||
} else {
|
||||
let data_entry = {
|
||||
blockindex: txs[i].blockindex,
|
||||
blockhash: txs[i].blockhash,
|
||||
txid: txs[i].txid,
|
||||
recipients: txs[i].vout.length,
|
||||
amount: (txs[i].total / 100000000),
|
||||
timestamp: txs[i].timestamp
|
||||
};
|
||||
if (show_extracted_by == true)
|
||||
row.push('extracted_by:' + JSON.stringify(extracted_by_addresses));
|
||||
|
||||
data.push(row);
|
||||
loop();
|
||||
} else {
|
||||
let data_entry = {
|
||||
blockindex: txs[i].blockindex,
|
||||
blockhash: txs[i].blockhash,
|
||||
txid: txs[i].txid,
|
||||
recipients: txs[i].vout.length,
|
||||
amount: (txs[i].total / 100000000),
|
||||
timestamp: txs[i].timestamp
|
||||
};
|
||||
|
||||
if (settings.block_page.multi_algorithm.show_algo == true)
|
||||
data_entry.algo = (txs[i].algo == null ? '' : txs[i].algo);
|
||||
if (settings.block_page.multi_algorithm.show_algo == true)
|
||||
data_entry.algo = (txs[i].algo == null ? '' : txs[i].algo);
|
||||
|
||||
data.push(data_entry);
|
||||
}
|
||||
}
|
||||
if (show_extracted_by == true)
|
||||
data_entry.extracted_by = extracted_by_addresses;
|
||||
|
||||
return cb(data, count);
|
||||
data.push(data_entry);
|
||||
loop();
|
||||
}
|
||||
});
|
||||
}, function() {
|
||||
return cb(data, count);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
@@ -1988,5 +2049,35 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
get_extracted_by_claim_names: function(extracted_by_addresses, cb) {
|
||||
// check if custom claim names are enabled
|
||||
if (settings.claim_address_page.enabled == true) {
|
||||
// lookup the claim names for the extracted addresses
|
||||
module.exports.get_claim_names(extracted_by_addresses, function(claim_names) {
|
||||
// combine the addresses from the original array with the claim names to create an object array
|
||||
extracted_by_addresses = extracted_by_addresses.map(address => {
|
||||
const match = claim_names.find(doc => doc.a_id === address);
|
||||
|
||||
return {
|
||||
a_id: address,
|
||||
claimname: match ? match.claim_name : ''
|
||||
};
|
||||
});
|
||||
|
||||
return cb(extracted_by_addresses);
|
||||
});
|
||||
} else {
|
||||
// create an object array of the extracted addresses
|
||||
extracted_by_addresses = extracted_by_addresses.map(address => {
|
||||
return {
|
||||
a_id: address,
|
||||
claimname: ''
|
||||
};
|
||||
});
|
||||
|
||||
return cb(extracted_by_addresses);
|
||||
}
|
||||
},
|
||||
|
||||
fs: fs
|
||||
};
|
||||
Reference in New Issue
Block a user