2021-05-29 22:11:38 +00:00
|
|
|
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 {
|
|
|
|
if (element.txs[0].data.memo == userArr[0]._id && element.txs[0].data.amount >= userArr[0].price && userArr[0].status == "Inactive" ){
|
|
|
|
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"
|
2021-05-29 22:45:55 +00:00
|
|
|
mongo.update(config.database, "users", {_id: userArr[0]._id}, userArr[0])
|
2021-05-29 22:11:38 +00:00
|
|
|
console.log(res)
|
2021-05-29 22:45:55 +00:00
|
|
|
tx2 = {
|
|
|
|
type: 3,
|
|
|
|
data: {
|
2021-05-29 22:51:37 +00:00
|
|
|
amount: (Math.floor(parseInt(config.fee))/2),
|
2021-05-29 22:58:06 +00:00
|
|
|
memo: "Welcome to DTube",
|
2021-05-29 22:55:22 +00:00
|
|
|
receiver: userArr[0].username
|
2021-05-29 22:45:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
signedTx2 = javalon.sign(config.accountCreator.privKey,config.accountCreator.username, tx2)
|
|
|
|
javalon.sendTransaction(signedTx2, function(err, res) {
|
|
|
|
if (err){
|
|
|
|
console.log(err)
|
|
|
|
} else {
|
|
|
|
console.log(res)
|
|
|
|
}
|
|
|
|
})
|
2021-05-29 22:11:38 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setInterval(checkPayment, 60000)
|
|
|
|
|