52 lines
2.3 KiB
JavaScript
52 lines
2.3 KiB
JavaScript
|
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)
|
||
|
|