Created
December 9, 2017 20:02
-
-
Save hirishh/709a60d2409571e01ba941c171ebaeb8 to your computer and use it in GitHub Desktop.
SYNC DEL PD E PM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'user strict'; | |
var debug = require('debug')('aps-scheduler'); | |
var config = require('config'); | |
var Address = require('mysql-easy-model').model('address'); | |
var Repeat = require('repeat'); | |
var hub = require('hub'); | |
var satoshi = 100000000; | |
exports.updateAddresses = function() { | |
debug("Start Update"); | |
debug("Updating all balances..."); | |
Address.find(function(err, addresses) { | |
if(err) | |
debug("ERROR while retrieving addresses: " + err); | |
else { | |
for(var i = 0; i < addresses.length; i++) | |
{ | |
var address = addresses[i]; | |
hub.LSK.getAccount(address.lisk_address, function(liskAccountCall) { | |
if(!liskAccountCall.success) { | |
debug("[" + address.lisk_address + "] ERROR while retrieving lisk account"); | |
return; | |
} | |
var oldBalance = address.lisk_balance; | |
var newBalance = liskAccountCall.account.balance / satoshi; | |
if(newBalance == oldBalance) | |
return; | |
if(newBalance == 0) | |
newBalance = 0.00000001 //Due to bug on mysql-easy | |
//Update the user with the new balances | |
address.lisk_balance = newBalance; | |
address.update(function(err){ | |
if(err) { | |
debug("[" + address.lisk_address + "] ERROR while updating lisk account: " + err); | |
} else { | |
debug("[" + address.lisk_address + "] Account Updated: " + oldBalance + " > " + newBalance); | |
} | |
}); | |
}); | |
} | |
} | |
}); | |
} | |
new Repeat(exports.updateAddresses) | |
.every(config.get("every"), 's') | |
.start.now(); |
vekexasia
commented
Dec 9, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment