functional

This commit is contained in:
nannal
2021-05-30 01:11:38 +03:00
parent 1ffe5d8f0f
commit b161f0892e
10 changed files with 350 additions and 0 deletions

View 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)

View 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)