Add support for newer Dash masternode format
-Automatically detect if using newer or older Dash masternode format and display applicable columns and data -Added new fields 'ip_address' and 'last_paid_block' to the Masternode collection
This commit is contained in:
+54
-24
@@ -289,7 +289,7 @@ module.exports = {
|
||||
// loop through masternode addresses
|
||||
for (m = 0; m < masternodes.length; m++) {
|
||||
// check if this is the correct address
|
||||
if (masternodes[m].addr == hash) {
|
||||
if ((masternodes[m].proTxHash != null ? masternodes[m].payee : masternodes[m].addr) == hash) {
|
||||
// update the claim name
|
||||
masternodes[m]['claim_name'] = claim_name;
|
||||
// mark as updated
|
||||
@@ -1043,14 +1043,30 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
check_masternodes: function(cb) {
|
||||
Masternode.findOne({}, function(err, masternode) {
|
||||
if (masternode) {
|
||||
// collection has data
|
||||
// determine if ip_address field exists
|
||||
check_add_db_field(Masternode, 'ip_address', null, function(exists) {
|
||||
// determine if last_paid_block field exists
|
||||
check_add_db_field(Masternode, 'last_paid_block', null, function(exists) {
|
||||
return cb(true);
|
||||
});
|
||||
});
|
||||
} else
|
||||
return cb(false);
|
||||
});
|
||||
},
|
||||
|
||||
// determine if masternode exists and save masternode to collection
|
||||
save_masternode: function (raw_masternode, cb) {
|
||||
// lookup masternode in local collection
|
||||
module.exports.find_masternode(raw_masternode.txhash, raw_masternode.outidx, function (masternode) {
|
||||
module.exports.find_masternode((raw_masternode.proTxHash != null ? raw_masternode.proTxHash : raw_masternode.txhash), function (masternode) {
|
||||
// determine if the claim address feature is enabled
|
||||
if (settings.claim_address_page.enabled == true) {
|
||||
// claim address is enabled so lookup the address claim name
|
||||
find_address(raw_masternode.addr, false, function(address) {
|
||||
find_address((raw_masternode.proTxHash != null ? raw_masternode.payee : raw_masternode.addr), false, function(address) {
|
||||
if (address) {
|
||||
// save claim name to masternode obejct
|
||||
raw_masternode.claim_name = address.name;
|
||||
@@ -1075,26 +1091,40 @@ module.exports = {
|
||||
|
||||
// add or update a single masternode
|
||||
add_update_masternode(masternode, add, cb) {
|
||||
if (!masternode.txhash == null || !masternode.outidx == null) {
|
||||
console.log('Masternode Update - TX or Outidx is missing');
|
||||
console.log(masternode.txhash);
|
||||
console.log(masternode.outidx);
|
||||
if (masternode.proTxHash == null && masternode.txhash == null) {
|
||||
console.log('Masternode Update - TXid is missing');
|
||||
|
||||
return cb(false);
|
||||
} else {
|
||||
var mn = new Masternode({
|
||||
rank: masternode.rank,
|
||||
network: masternode.network,
|
||||
txhash: masternode.txhash,
|
||||
outidx: masternode.outidx,
|
||||
status: masternode.status,
|
||||
addr: masternode.addr,
|
||||
version: masternode.version,
|
||||
lastseen: masternode.lastseen,
|
||||
activetime: masternode.activetime,
|
||||
lastpaid: masternode.lastpaid,
|
||||
claim_name: (masternode.claim_name == null ? '' : masternode.claim_name)
|
||||
});
|
||||
// Check if this older or newer Dash masternode format
|
||||
if (masternode.proTxHash != null) {
|
||||
// This is the newer Dash format
|
||||
var mn = new Masternode({
|
||||
txhash: masternode.proTxHash,
|
||||
status: masternode.status,
|
||||
addr: masternode.payee,
|
||||
lastpaid: masternode.lastpaidtime,
|
||||
ip_address: masternode.address,
|
||||
last_paid_block: masternode.lastpaidblock,
|
||||
lastseen: Math.floor(Date.now() / 1000),
|
||||
claim_name: (masternode.claim_name == null ? '' : masternode.claim_name)
|
||||
});
|
||||
} else {
|
||||
// This is the older Dash format, or an unknown format
|
||||
var mn = new Masternode({
|
||||
rank: masternode.rank,
|
||||
network: masternode.network,
|
||||
txhash: masternode.txhash,
|
||||
outidx: masternode.outidx,
|
||||
status: masternode.status,
|
||||
addr: masternode.addr,
|
||||
version: masternode.version,
|
||||
lastseen: masternode.lastseen,
|
||||
activetime: masternode.activetime,
|
||||
lastpaid: masternode.lastpaid,
|
||||
claim_name: (masternode.claim_name == null ? '' : masternode.claim_name)
|
||||
});
|
||||
}
|
||||
|
||||
if (add) {
|
||||
// add new masternode to collection
|
||||
@@ -1107,7 +1137,7 @@ module.exports = {
|
||||
});
|
||||
} else {
|
||||
// update existing masternode in local collection
|
||||
Masternode.updateOne({ txhash: masternode.txhash, outidx: masternode.outidx }, masternode, function (err) {
|
||||
Masternode.updateOne({ txhash: (masternode.proTxHash != null ? masternode.proTxHash : masternode.txhash) }, masternode, function (err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return cb(false);
|
||||
@@ -1118,9 +1148,9 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
// find masternode by txid and offset
|
||||
find_masternode: function (txhash, outidx, cb) {
|
||||
Masternode.findOne({ txhash: txhash, outidx: outidx }, function (err, masternode) {
|
||||
// find masternode by txid
|
||||
find_masternode: function (txhash, cb) {
|
||||
Masternode.findOne({ txhash: txhash }, function (err, masternode) {
|
||||
if (err)
|
||||
return cb(null);
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user