Add masternodes page/feature
-Added a new "Masternodes" page which displays the current list of masternodes on the network -/api/getmasternodelist is no longer publicly accessible and has been replaced by /ext/getmasternodelist which returns the masternode list from local collection instead of directly from wallet -Added new masternode sync options to sync.js and sync.sh -Added new masternodes_last_updated field to the Stats collection -Updated delete_database.sh and restore_backup.sh to include support for the new masternodes collection -Network header menu icon changed to allow the new Masternodes menu item to use the old network icon
This commit is contained in:
+214
-38
@@ -1,6 +1,7 @@
|
||||
var mongoose = require('mongoose')
|
||||
, Stats = require('../models/stats')
|
||||
, Markets = require('../models/markets')
|
||||
, Masternode = require('../models/masternode')
|
||||
, Address = require('../models/address')
|
||||
, AddressTx = require('../models/addresstx')
|
||||
, Tx = require('../models/tx')
|
||||
@@ -250,49 +251,18 @@ module.exports = {
|
||||
return fs.existsSync('./tmp/show_sync_message.tmp');
|
||||
},
|
||||
|
||||
update_label: function(hash, message, cb) {
|
||||
update_label: function(hash, claim_name, cb) {
|
||||
find_address(hash, false, function(address) {
|
||||
if (address) {
|
||||
Address.updateOne({a_id: hash}, {
|
||||
name: message
|
||||
name: claim_name
|
||||
}, function() {
|
||||
// ensure that if this address exists in the richlist that it displays the new alias
|
||||
module.exports.get_richlist(settings.coin, function(richlist) {
|
||||
var updated = false;
|
||||
// loop through received addresses
|
||||
for (r = 0; r < richlist.received.length; r++) {
|
||||
// check if this is the correct address
|
||||
if (richlist.received[r].a_id == hash) {
|
||||
// update the claim name
|
||||
richlist.received[r]['name'] = message;
|
||||
// mark as updated
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
// loop through balance addresses
|
||||
for (b = 0; b < richlist.balance.length; b++) {
|
||||
// check if this is the correct address
|
||||
if (richlist.balance[b].a_id == hash) {
|
||||
// update the claim name
|
||||
richlist.balance[b]['name'] = message;
|
||||
// mark as updated
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
// check if the address was updated in the richlist
|
||||
if (updated) {
|
||||
// save the richlist back to collection
|
||||
Richlist.updateOne({coin: settings.coin}, {
|
||||
received: richlist.received,
|
||||
balance: richlist.balance
|
||||
}, function() {
|
||||
// finished updating the claim label
|
||||
return cb('');
|
||||
});
|
||||
} else {
|
||||
// finished updating the claim label
|
||||
// update claim name in richlist
|
||||
module.exports.update_richlist_claim_name(hash, claim_name, function() {
|
||||
// update claim name in masternode list
|
||||
module.exports.update_masternode_claim_name(hash, claim_name, function() {
|
||||
return cb('');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
@@ -302,6 +272,89 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
update_richlist_claim_name: function(hash, claim_name, cb) {
|
||||
// check if the richlist is enabled
|
||||
if (settings.display.richlist) {
|
||||
// ensure that if this address exists in the richlist that it displays the new alias
|
||||
module.exports.get_richlist(settings.coin, function(richlist) {
|
||||
var updated = false;
|
||||
// loop through received addresses
|
||||
for (r = 0; r < richlist.received.length; r++) {
|
||||
// check if this is the correct address
|
||||
if (richlist.received[r].a_id == hash) {
|
||||
// update the claim name
|
||||
richlist.received[r]['name'] = claim_name;
|
||||
// mark as updated
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
// loop through balance addresses
|
||||
for (b = 0; b < richlist.balance.length; b++) {
|
||||
// check if this is the correct address
|
||||
if (richlist.balance[b].a_id == hash) {
|
||||
// update the claim name
|
||||
richlist.balance[b]['name'] = claim_name;
|
||||
// mark as updated
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
// check if the address was updated in the richlist
|
||||
if (updated) {
|
||||
// save the richlist back to collection
|
||||
Richlist.updateOne({coin: settings.coin}, {
|
||||
received: richlist.received,
|
||||
balance: richlist.balance
|
||||
}, function() {
|
||||
// finished updating the claim label
|
||||
return cb('');
|
||||
});
|
||||
} else {
|
||||
// finished updating the claim label
|
||||
return cb('');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// richlist is not enabled so nothing to update
|
||||
return cb('');
|
||||
}
|
||||
},
|
||||
|
||||
update_masternode_claim_name: function(hash, claim_name, cb) {
|
||||
// check if the masternode list is enabled
|
||||
if (settings.display.masternodes) {
|
||||
// ensure that if this address exists in the masternode that it displays the new alias
|
||||
module.exports.get_masternodes(function(masternodes) {
|
||||
var updated = false;
|
||||
// loop through masternode addresses
|
||||
for (m = 0; m < masternodes.length; m++) {
|
||||
// check if this is the correct address
|
||||
if (masternodes[m].addr == hash) {
|
||||
// update the claim name
|
||||
masternodes[m]['claim_name'] = claim_name;
|
||||
// mark as updated
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
// check if the address was updated in the masternode list
|
||||
if (updated) {
|
||||
// save the updated masternode back to collection
|
||||
Masternode.updateOne({addr: hash}, {
|
||||
claim_name: claim_name
|
||||
}, function() {
|
||||
// finished updating the claim label
|
||||
return cb('');
|
||||
});
|
||||
} else {
|
||||
// finished updating the claim label
|
||||
return cb('');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// masternode list is not enabled so nothing to update
|
||||
return cb('');
|
||||
}
|
||||
},
|
||||
|
||||
check_stats: function(coin, cb) {
|
||||
Stats.findOne({coin: coin}, function(err, stats) {
|
||||
if(stats) {
|
||||
@@ -993,6 +1046,129 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
// 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) {
|
||||
// determine if the claim address feature is enabled
|
||||
if (settings.display.claim_address) {
|
||||
// claim address is enabled so lookup the address claim name
|
||||
find_address(raw_masternode.addr, false, function(address) {
|
||||
if (address) {
|
||||
// save claim name to masternode obejct
|
||||
raw_masternode.claim_name = address.name;
|
||||
} else {
|
||||
// save blank claim name to masternode obejct
|
||||
raw_masternode.claim_name = '';
|
||||
}
|
||||
// add/update the masternode
|
||||
module.exports.add_update_masternode(raw_masternode, (masternode == null), function(success) {
|
||||
return cb(success);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// claim address is disabled so add/update the masternode
|
||||
module.exports.add_update_masternode(raw_masternode, (masternode == null), function(success) {
|
||||
return cb(success);
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 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);
|
||||
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)
|
||||
});
|
||||
|
||||
if (add) {
|
||||
// add new masternode to collection
|
||||
mn.save(function (err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return cb(false);
|
||||
} else
|
||||
return cb(true);
|
||||
});
|
||||
} else {
|
||||
// update existing masternode in local collection
|
||||
Masternode.updateOne({ txhash: masternode.txhash, outidx: masternode.outidx }, masternode, function (err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return cb(false);
|
||||
} else
|
||||
return cb(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// find masternode by txid and offset
|
||||
find_masternode: function (txhash, outidx, cb) {
|
||||
Masternode.findOne({ txhash: txhash, outidx: outidx }, function (err, masternode) {
|
||||
if (err)
|
||||
return cb(null);
|
||||
else {
|
||||
if (masternode)
|
||||
return cb(masternode);
|
||||
else
|
||||
return cb(null);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// remove masternodes older than 24 hours
|
||||
remove_old_masternodes: function (cb) {
|
||||
Masternode.deleteMany({ lastseen: { $lte: (Math.floor(Date.now() / 1000) - 86400) } }, function (err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return cb();
|
||||
} else
|
||||
return cb();
|
||||
});
|
||||
},
|
||||
|
||||
// get the list of masternodes from local collection
|
||||
get_masternodes: function (cb) {
|
||||
Masternode.find({}, function (err, masternodes) {
|
||||
if (err)
|
||||
return cb([]);
|
||||
else
|
||||
return cb(masternodes);
|
||||
});
|
||||
},
|
||||
|
||||
// updates last_updated stats; called by sync.js
|
||||
update_last_updated_stats: function (coin, param, cb) {
|
||||
if (param.masternodes_last_updated) {
|
||||
// update masternode last updated date
|
||||
Stats.updateOne({ coin: coin }, {
|
||||
masternodes_last_updated: param.masternodes_last_updated
|
||||
}, function () {
|
||||
return cb(true);
|
||||
});
|
||||
} else {
|
||||
// invalid option
|
||||
return cb(false);
|
||||
}
|
||||
},
|
||||
|
||||
populate_claim_address_names: function(tx, cb) {
|
||||
var addresses = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user