functional
This commit is contained in:
51
peroidicActions/checkPayment.js
Normal file
51
peroidicActions/checkPayment.js
Normal file
@@ -0,0 +1,51 @@
|
||||
mongo = require("../mongoHelp.js")
|
||||
config = require("../config.js")
|
||||
|
||||
javalon = require("javalon")
|
||||
|
||||
function checkPayment(){
|
||||
javalon.getAccountHistory(config.accountCreator.username, 0, (err, blocks) => {
|
||||
if (err) {
|
||||
console.log(err)
|
||||
} else {
|
||||
blocks.forEach(element => {
|
||||
if (element.txs[0].type == 3) {
|
||||
if (element.txs[0].data.memo.length > 8){
|
||||
mongo.get(config.database, "users", {_id: element.txs[0].data.memo}).then(userArr => {
|
||||
if (userArr.length != 1){
|
||||
console.log("UserArray too long, this could indicate duplicate IDs which would be bad")
|
||||
} else {
|
||||
console.log(element.txs[0].data.amount , userArr[0].price)
|
||||
if (element.txs[0].data.memo == userArr[0]._id && element.txs[0].data.amount >= userArr[0].price && userArr[0].status == "Inactive" ){
|
||||
id = userArr[0]._id
|
||||
|
||||
tx = {
|
||||
type: 0,
|
||||
data: {
|
||||
pub: userArr[0].keys.pub,
|
||||
name: userArr[0].username
|
||||
}
|
||||
}
|
||||
signedTx = javalon.sign(config.accountCreator.privKey,config.accountCreator.username, tx)
|
||||
javalon.sendTransaction(signedTx, function(err, res) {
|
||||
if (err){
|
||||
console.log(err)
|
||||
} else {
|
||||
userArr[0].status = "Active"
|
||||
mongo.update(config.database, "users", {_id: id}, userArr[0])
|
||||
console.log(res)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
setInterval(checkPayment, 60000)
|
||||
|
23
peroidicActions/pruneUnpaidAccounts.js
Normal file
23
peroidicActions/pruneUnpaidAccounts.js
Normal file
@@ -0,0 +1,23 @@
|
||||
mongo = require("../mongoHelp.js")
|
||||
config = require("../config.js")
|
||||
|
||||
javalon = require("javalon")
|
||||
|
||||
function pruneUnpaidAccounts(){
|
||||
agg = [ {'$match': {
|
||||
timeLimit: { $lt: Date.now()}
|
||||
}},
|
||||
{'$match': {
|
||||
status: "Inactive"
|
||||
}}]
|
||||
mongo.aggregate(config.database, "users", agg).then(oldArr => {
|
||||
oldArr.forEach(element => {
|
||||
mongo.deleteOne(config.database, "users", {_id:element._id})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
setInterval(pruneUnpaidAccounts, 3600000)
|
Reference in New Issue
Block a user