Add new setting to decode tx OP_RETURN values

This commit is contained in:
joeuhren
2021-07-09 20:39:02 -06:00
parent 460ca331b6
commit 6057b875ec
6 changed files with 45 additions and 6 deletions
+1 -1
View File
@@ -122,7 +122,7 @@ Table of Contents
- **getmasternoderewardstotal:** Returns the total number of coins earned in masternode rewards for a specific address that arrived after a specific block height *\*only applicable to masternode coins* - **getmasternoderewardstotal:** Returns the total number of coins earned in masternode rewards for a specific address that arrived after a specific block height *\*only applicable to masternode coins*
- **Claim Address:** Allows anyone to set custom display names for wallet addresses that they own using the **Sign Message** feature from their local wallet. Includes *bad word* filter support. - **Claim Address:** Allows anyone to set custom display names for wallet addresses that they own using the **Sign Message** feature from their local wallet. Includes *bad word* filter support.
- **Block Info:** Displays block summary and list of transactions for a specific block height - **Block Info:** Displays block summary and list of transactions for a specific block height
- **Transaction Info:** Displays transaction summary, list of input addresses and output addresses for a specific transaction - **Transaction Info:** Displays transaction summary, optional OP_RETURN value, list of input addresses and output addresses for a specific transaction
- **Address Info:** Displays wallet address summary (balance, total sent, total received, QR code) and a list of latest transactions for a specific wallet address - **Address Info:** Displays wallet address summary (balance, total sent, total received, QR code) and a list of latest transactions for a specific wallet address
- Choose from 22 built-in themes with tweakable settings such as light and dark options to customize the look and feel of the explorer: - Choose from 22 built-in themes with tweakable settings such as light and dark options to customize the look and feel of the explorer:
- **Exor** *\*default theme made especially for eIquidus* - **Exor** *\*default theme made especially for eIquidus*
+26 -2
View File
@@ -136,6 +136,19 @@ function save_tx(txid, blockheight, cb) {
subloop.next(); subloop.next();
}, function() { }, function() {
lib.calculate_total(vout, function(total) { lib.calculate_total(vout, function(total) {
var op_return = null;
// check if the op_return value should be decoded and saved
if (settings.transaction_page.show_op_return) {
// loop through vout to find the op_return value
tx.vout.forEach(function (vout_data) {
// check if the op_return value exists
if (vout_data.scriptPubKey != null && vout_data.scriptPubKey.asm != null && vout_data.scriptPubKey.asm.indexOf('OP_RETURN') > -1) {
// decode the op_return value
op_return = hex_to_ascii(vout_data.scriptPubKey.asm.replace('OP_RETURN', '').trim());
}
});
}
var newTx = new Tx({ var newTx = new Tx({
txid: tx.txid, txid: tx.txid,
vin: nvin, vin: nvin,
@@ -144,7 +157,8 @@ function save_tx(txid, blockheight, cb) {
timestamp: tx.time, timestamp: tx.time,
blockhash: tx.blockhash, blockhash: tx.blockhash,
blockindex: blockheight, blockindex: blockheight,
tx_type: (tx_type_vout == null ? tx_type_vin : tx_type_vout) tx_type: (tx_type_vout == null ? tx_type_vin : tx_type_vout),
op_return: op_return
}); });
newTx.save(function(err) { newTx.save(function(err) {
@@ -190,6 +204,13 @@ function check_add_db_field(model_obj, field_name, default_value, cb) {
}); });
} }
function hex_to_ascii(hex) {
var str = '';
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
}
module.exports = { module.exports = {
// initialize DB // initialize DB
connect: function(database, cb) { connect: function(database, cb) {
@@ -323,7 +344,10 @@ module.exports = {
// collection has data // collection has data
// determine if tx_type field exists // determine if tx_type field exists
check_add_db_field(Tx, 'tx_type', null, function(exists) { check_add_db_field(Tx, 'tx_type', null, function(exists) {
return cb(true); // determine if op_return field exists
check_add_db_field(Tx, 'op_return', null, function(exists) {
return cb(true);
});
}); });
} else } else
return cb(false); return cb(false);
+4 -1
View File
@@ -354,7 +354,10 @@ exports.transaction_page = {
// genesis_tx: Your coins genesis transaction hash is used to determine the beginning of the blockchain // genesis_tx: Your coins genesis transaction hash is used to determine the beginning of the blockchain
// For many bitcoin clones you can use the following cmd to find the list of transaction hashes from the genesis block: coin-cli getblock 00014f36c648cdbc750f7dd28487a23cd9e0b0f95f5fccc5b5d01367e3f57469 // For many bitcoin clones you can use the following cmd to find the list of transaction hashes from the genesis block: coin-cli getblock 00014f36c648cdbc750f7dd28487a23cd9e0b0f95f5fccc5b5d01367e3f57469
// NOTE: If this value is not entered correctly it will not be possible for the explorer to find or navigate to the genesis block by searching for the genesis transaction hash // NOTE: If this value is not entered correctly it will not be possible for the explorer to find or navigate to the genesis block by searching for the genesis transaction hash
"genesis_tx": "dd1d332ad2d8d8f49195056d482ae3c96fd2d16e9d166413b27ca7f19775644c" "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
}; };
// address_page: a collection of settings that pertain to the address page // address_page: a collection of settings that pertain to the address page
+2 -1
View File
@@ -9,7 +9,8 @@ var TxSchema = new Schema({
timestamp: { type: Number, default: 0, index: true }, timestamp: { type: Number, default: 0, index: true },
blockhash: { type: String, index: true }, blockhash: { type: String, index: true },
blockindex: {type: Number, default: 0, index: true}, blockindex: {type: Number, default: 0, index: true},
tx_type: { type: String, default: null } tx_type: { type: String, default: null },
op_return: { type: String, default: null }
}, {id: false}); }, {id: false});
TxSchema.index({total: 1, total: -1, blockindex: 1, blockindex: -1}); TxSchema.index({total: 1, total: -1, blockindex: 1, blockindex: -1});
+4 -1
View File
@@ -438,7 +438,10 @@
// genesis_tx: Your coins genesis transaction hash is used to determine the beginning of the blockchain // genesis_tx: Your coins genesis transaction hash is used to determine the beginning of the blockchain
// For many bitcoin clones you can use the following cmd to find the list of transaction hashes from the genesis block: coin-cli getblock 00014f36c648cdbc750f7dd28487a23cd9e0b0f95f5fccc5b5d01367e3f57469 // For many bitcoin clones you can use the following cmd to find the list of transaction hashes from the genesis block: coin-cli getblock 00014f36c648cdbc750f7dd28487a23cd9e0b0f95f5fccc5b5d01367e3f57469
// NOTE: If this value is not entered correctly it will not be possible for the explorer to find or navigate to the genesis block by searching for the genesis transaction hash // NOTE: If this value is not entered correctly it will not be possible for the explorer to find or navigate to the genesis block by searching for the genesis transaction hash
"genesis_tx": "dd1d332ad2d8d8f49195056d482ae3c96fd2d16e9d166413b27ca7f19775644c" "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
}, },
// address_page: a collection of settings that pertain to the address page // address_page: a collection of settings that pertain to the address page
+8
View File
@@ -43,6 +43,8 @@ block content
tr tr
th.text-center.d-table-cell.d-md-none th.text-center.d-table-cell.d-md-none
th.d-none.d-md-table-cell #{settings.locale.tx_block_hash} th.d-none.d-md-table-cell #{settings.locale.tx_block_hash}
if settings.transaction_page.show_op_return == true
th='OP_RETURN'
th.text-center #{settings.locale.confirmations} th.text-center #{settings.locale.confirmations}
th.text-center #{settings.locale.timestamp} th.text-center #{settings.locale.timestamp}
tbody tbody
@@ -54,6 +56,8 @@ block content
span.fa.fa-eye(data-toggle='tooltip', data-placement='top', title=settings.locale.view_block) span.fa.fa-eye(data-toggle='tooltip', data-placement='top', title=settings.locale.view_block)
td.d-none.d-md-table-cell td.d-none.d-md-table-cell
a.breakWord(href='/block/' + tx.blockhash) #{tx.blockhash} a.breakWord(href='/block/' + tx.blockhash) #{tx.blockhash}
if settings.transaction_page.show_op_return == true
td.breakWord #{tx.op_return}
td.text-center #{confirms} td.text-center #{confirms}
td.text-center td.text-center
span#timestampCol span#timestampCol
@@ -65,6 +69,8 @@ block content
span.fa.fa-eye(data-toggle='tooltip', data-placement='top', title=settings.locale.view_block) span.fa.fa-eye(data-toggle='tooltip', data-placement='top', title=settings.locale.view_block)
td.d-none.d-md-table-cell td.d-none.d-md-table-cell
a.breakWord(href='/block/' + tx.blockhash) #{tx.blockhash} a.breakWord(href='/block/' + tx.blockhash) #{tx.blockhash}
if settings.transaction_page.show_op_return == true
td.breakWord #{tx.op_return}
td.text-center #{confirms} td.text-center #{confirms}
td.text-center td.text-center
span#timestampCol span#timestampCol
@@ -75,6 +81,8 @@ block content
span.fa.fa-eye(data-toggle='tooltip', data-placement='top', title=settings.locale.view_block) span.fa.fa-eye(data-toggle='tooltip', data-placement='top', title=settings.locale.view_block)
td.d-none.d-md-table-cell td.d-none.d-md-table-cell
a.breakWord(href='/block/' + tx.blockhash) #{tx.blockhash} a.breakWord(href='/block/' + tx.blockhash) #{tx.blockhash}
if settings.transaction_page.show_op_return == true
td.breakWord #{tx.op_return}
td.text-center #{confirms} td.text-center #{confirms}
td.text-center td.text-center
span#timestampCol span#timestampCol