Fix for identifiying multi MNs created in same tx
-The find_masternodes function now searches for both txhash and address instead of only txhash to prevent matching different masternodes that were created in the same tx -Moved the find_masternodes function out of the module.exports section of the database file since it doesn't need to be exported
This commit is contained in:
+18
-15
@@ -268,6 +268,19 @@ function init_heavy(cb) {
|
||||
return cb();
|
||||
}
|
||||
|
||||
// find masternode by txid and
|
||||
function find_masternode(txhash, addr, cb) {
|
||||
Masternode.findOne({ txhash: txhash, addr: addr }).then((masternode) => {
|
||||
if (masternode)
|
||||
return cb(masternode);
|
||||
else
|
||||
return cb(null);
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
return cb(null);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
// initialize DB
|
||||
connect: function(database, cb) {
|
||||
@@ -1243,12 +1256,15 @@ module.exports = {
|
||||
|
||||
// determine if masternode exists and save masternode to collection
|
||||
save_masternode: function (raw_masternode, cb) {
|
||||
var txhash = (raw_masternode.proTxHash != null ? raw_masternode.proTxHash : raw_masternode.txhash);
|
||||
var addr = (raw_masternode.proTxHash != null ? raw_masternode.payee : raw_masternode.addr);
|
||||
|
||||
// lookup masternode in local collection
|
||||
module.exports.find_masternode((raw_masternode.proTxHash != null ? raw_masternode.proTxHash : raw_masternode.txhash), function (masternode) {
|
||||
find_masternode(txhash, addr, 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.proTxHash != null ? raw_masternode.payee : raw_masternode.addr), false, function(address) {
|
||||
find_address(addr, false, function(address) {
|
||||
if (address) {
|
||||
// save claim name to masternode obejct
|
||||
raw_masternode.claim_name = address.name;
|
||||
@@ -1328,19 +1344,6 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
// find masternode by txid
|
||||
find_masternode: function (txhash, cb) {
|
||||
Masternode.findOne({ txhash: txhash }).then((masternode) => {
|
||||
if (masternode)
|
||||
return cb(masternode);
|
||||
else
|
||||
return cb(null);
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
return cb(null);
|
||||
});
|
||||
},
|
||||
|
||||
// remove masternodes older than 24 hours
|
||||
remove_old_masternodes: function (cb) {
|
||||
Masternode.deleteMany({ lastseen: { $lte: (Math.floor(Date.now() / 1000) - 86400) } }).then(() => {
|
||||
|
||||
Reference in New Issue
Block a user