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
|
||||
};
|
||||
+16
-4
@@ -615,7 +615,10 @@ exports.index_page = {
|
||||
// reload_table_seconds: The time in seconds to automatically reload the table data from the server
|
||||
// Set to 0 to disable automatic reloading of table data
|
||||
"reload_table_seconds": 60
|
||||
}
|
||||
},
|
||||
// show_extracted_by: Determine whether to show a new column with the address(es) that mined the block
|
||||
// If enabled, a new column will be displayed on the index page that displays the address(es) that mined the block for the coinbase transaction only
|
||||
"show_extracted_by": false
|
||||
};
|
||||
|
||||
// block_page: a collection of settings that pertain to the block page
|
||||
@@ -649,7 +652,10 @@ exports.block_page = {
|
||||
// key_name: The name of the key or identifier in the raw block data that determines which hash algorithm was used to mine a particular block
|
||||
// NOTE: Changing this option will require a full reindex of the blockchain data before previously synced blocks can display the algorithm
|
||||
"key_name": "pow_algo"
|
||||
}
|
||||
},
|
||||
// show_extracted_by: Determine whether to show a new column with the address(es) that mined the block
|
||||
// If enabled, a new column will be displayed on the block page that displays the address(es) that mined the block
|
||||
"show_extracted_by": false
|
||||
};
|
||||
|
||||
// transaction_page: a collection of settings that pertain to the transaction/tx page
|
||||
@@ -675,7 +681,10 @@ exports.transaction_page = {
|
||||
"genesis_tx": "dd1d332ad2d8d8f49195056d482ae3c96fd2d16e9d166413b27ca7f19775644c",
|
||||
// show_op_return: Determine whether to decode and show OP_RETURN values that may have been embeddeded in a transaction
|
||||
// NOTE: Enabling this option will require a full reindex of the blockchain data before previously synced transactions can display the OP_RETURN value
|
||||
"show_op_return": false
|
||||
"show_op_return": false,
|
||||
// show_extracted_by: Determine whether to show a new column with the address(es) that mined the block
|
||||
// If enabled, a new column will be displayed on the transaction page that displays the address(es) that mined the block for the coinbase transaction only
|
||||
"show_extracted_by": false
|
||||
};
|
||||
|
||||
// address_page: a collection of settings that pertain to the address page
|
||||
@@ -1263,7 +1272,10 @@ exports.api_page = {
|
||||
// If set to false, the /ext/getlasttxs api will be completely disabled for public use (no definition on the api page and a disabled error msg if you try to call the endpoint directly) but the api will still be available internally to the explorer
|
||||
"enabled": true,
|
||||
// max_items_per_query: The maximum # of transactions that can be returned from the /ext/getlasttxs api endpoint in a single call
|
||||
"max_items_per_query": 100
|
||||
"max_items_per_query": 100,
|
||||
// show_extracted_by: Determine whether to return a new field with the address(es) that mined the block
|
||||
// If enabled, a new field will be added to the /ext/getlasttxs api endpoint that displays the address(es) that mined the block for the coinbase transaction only
|
||||
"show_extracted_by": false
|
||||
},
|
||||
// getcurrentprice: a collection of settings that pertain to the /ext/getcurrentprice api endpoint
|
||||
// Returns last known exchange price
|
||||
|
||||
Reference in New Issue
Block a user