Add support for bitcoin P2PK scripts/txes
-Adds a tx_type field to the tx model which is typically null for "normal" transaction types, but can also display 'p2pk' for bitcoin txes which require addtional encoding to reveal the P2PKH address as well as 'zksnarks' for transactions with hidden sender or receiver data -Additional fixes for how data is displayed when a valid wallet address cannot be found -Includes some small updates to how zksnarks transactions display hidden sender/receiver data
This commit is contained in:
+39
-16
@@ -10,6 +10,7 @@ var mongoose = require('mongoose'),
|
||||
Heavy = require('../models/heavy'),
|
||||
lib = require('./explorer'),
|
||||
settings = require('./settings'),
|
||||
locale = require('./locale'),
|
||||
fs = require('fs'),
|
||||
coindesk = require('./apis/coindesk'),
|
||||
async = require('async');
|
||||
@@ -115,8 +116,8 @@ function find_tx(txid, cb) {
|
||||
function save_tx(txid, blockheight, cb) {
|
||||
lib.get_rawtransaction(txid, function(tx) {
|
||||
if (tx && tx != 'There was an error. Check your console.') {
|
||||
lib.prepare_vin(tx, function(vin) {
|
||||
lib.prepare_vout(tx.vout, txid, vin, ((!settings.blockchain_specific.zksnarks.enabled || typeof tx.vjoinsplit === 'undefined' || tx.vjoinsplit == null) ? [] : tx.vjoinsplit), function(vout, nvin) {
|
||||
lib.prepare_vin(tx, function(vin, tx_type_vin) {
|
||||
lib.prepare_vout(tx.vout, txid, vin, ((!settings.blockchain_specific.zksnarks.enabled || typeof tx.vjoinsplit === 'undefined' || tx.vjoinsplit == null) ? [] : tx.vjoinsplit), function(vout, nvin, tx_type_vout) {
|
||||
lib.syncLoop(vin.length, function (loop) {
|
||||
var i = loop.iteration();
|
||||
|
||||
@@ -142,7 +143,8 @@ function save_tx(txid, blockheight, cb) {
|
||||
total: total.toFixed(8),
|
||||
timestamp: tx.time,
|
||||
blockhash: tx.blockhash,
|
||||
blockindex: blockheight
|
||||
blockindex: blockheight,
|
||||
tx_type: (tx_type_vout == null ? tx_type_vin : tx_type_vout)
|
||||
});
|
||||
|
||||
newTx.save(function(err) {
|
||||
@@ -172,6 +174,22 @@ function get_market_data(market, coin_symbol, pair_symbol, cb) {
|
||||
return cb(null);
|
||||
}
|
||||
|
||||
function check_add_db_field(model_obj, field_name, default_value, cb) {
|
||||
// determine if a particular field exists in a db collection
|
||||
model_obj.findOne({[field_name]: {$exists: false}}, function(err, model_data) {
|
||||
// check if field exists
|
||||
if (model_data) {
|
||||
// add field to all documents in the collection
|
||||
model_obj.updateMany({}, {
|
||||
$set: { [field_name]: default_value }
|
||||
}, function() {
|
||||
return cb(true);
|
||||
});
|
||||
} else
|
||||
return cb(false);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
// initialize DB
|
||||
connect: function(database, cb) {
|
||||
@@ -299,22 +317,27 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
check_txes: function(cb) {
|
||||
Tx.findOne({}, function(err, tx) {
|
||||
if (tx) {
|
||||
// collection has data
|
||||
// determine if tx_type field exists
|
||||
check_add_db_field(Tx, 'tx_type', null, function(exists) {
|
||||
return cb(true);
|
||||
});
|
||||
} else
|
||||
return cb(false);
|
||||
});
|
||||
},
|
||||
|
||||
check_stats: function(coin, cb) {
|
||||
Stats.findOne({coin: coin}, function(err, stats) {
|
||||
if (stats) {
|
||||
// collection exists, now check if it is missing the last_usd_price column
|
||||
Stats.findOne({last_usd_price: {$exists: false}}, function(err, stats) {
|
||||
if (stats) {
|
||||
// the last_usd_price needs to be added to the collection
|
||||
Stats.updateOne({coin: coin}, {
|
||||
last_usd_price: 0
|
||||
}, function() {
|
||||
return cb(null);
|
||||
});
|
||||
}
|
||||
// collection has data
|
||||
// determine if last_usd_price field exists
|
||||
check_add_db_field(Stats, 'last_usd_price', 0, function(exists) {
|
||||
return cb(true);
|
||||
});
|
||||
|
||||
return cb(true);
|
||||
} else
|
||||
return cb(false);
|
||||
});
|
||||
@@ -366,7 +389,7 @@ module.exports = {
|
||||
var burn_addresses = settings.richlist_page.burned_coins.addresses;
|
||||
|
||||
// always omit the private address from the richlist
|
||||
burn_addresses.push("private_tx");
|
||||
burn_addresses.push('hidden_address');
|
||||
|
||||
if (list == 'received') {
|
||||
// update 'received' richlist data
|
||||
|
||||
Reference in New Issue
Block a user