diff --git a/backend/app.js b/backend/app.js index 7944318..b374f9f 100644 --- a/backend/app.js +++ b/backend/app.js @@ -10,6 +10,7 @@ const itemmodel = require('./models/item'); const ordermodel = require('./models/order'); const pricemodel = require('./models/price'); const txmodel = require('./models/tx'); +const paymentmodel = require('./models/payment'); const zecTxModel = require('./models/zectxs.js'); const mongoose = require('mongoose'); const stdrpc = require('stdrpc'); @@ -98,6 +99,7 @@ var blockInterval = setInterval( function() { console.log('Node periodic Zcash scan'); rpc.z_listreceivedbyaddress(fullnode.addr, 1).then(txs => { var re = /.*ZGO::(.*)\sReply-To:\s(z\w+)/; + var pay = /.*ZGOp::(.*)/; async.each (txs, function(txData, callback) { var memo = hexToString(txData.memo).replace(/\0/g, ''); if (!txData.change) { @@ -126,12 +128,6 @@ var blockInterval = setInterval( function() { usermodel.findOne({address: address, session: session, blocktime: blocktime}).then(function(doc){ if (doc == null){ console.log('User not found', session, blocktime, amount); - if (amount >= 0.001 && amount < 0.005){ - expiration = blocktime + 3600; - } else if (amount >= 0.005){ - expiration = blocktime + 24*3600; - } - console.log('exp', expiration); const n = crypto.randomInt(0, 10000000); const pin = n.toString().padStart(6, '0'); sendPin(pin, address); @@ -139,7 +135,6 @@ var blockInterval = setInterval( function() { address: address, session: session, blocktime: blocktime, - expiration: expiration, pin: pin, validated: false }); @@ -152,28 +147,48 @@ var blockInterval = setInterval( function() { }); } }); - ownermodel.findOne({address: address}).then(function (oDoc) { - if (oDoc == null) { - console.log('Owner not found', session); - var owner = new ownermodel({ - address: address, - name: 'Z-Go-'.concat(address.substring(0,5)) - }); - owner.save().then(function(err) { - if (err) { - console.log(err); - } - console.log('Owner saved!'); - }).catch(() => { - console.log('Owner exists'); - }); - } - }).catch((err) => { - console.log(err); - }); } } } + var exptime = 0; + if (pay.test(memo) && txData.confirmations < 100) { + var match2 = pay.exec(memo); + if (match2 != null) { + var session = match[1]; + } + if (txData.amount >= 0.001 && txData.amount < 0.005){ + exptime = blocktime + 3600; + } else if (txData.amount >= 0.005 && txData.amount < 0.025){ + exptime = blocktime + 24*3600; + } else if (txData.amount >= 0.025 && txData.amount < 0.1) { + exptime = blocktime + 7*24*3600; + } else if (txData.mount >= 0.1) { + exptime = blocktime + 4*7*24*3600; + } + + usermodel.findOne({session: session}).then(function(doc){ + if(doc != null) { + paymentmodel.findOne({address: doc.address, blocktime: txData.blocktime, amount: txData.amount}).then(function(payments){ + if(payments == null){ + var payment = new paymentmodel({ + address: doc.address, + blocktime: txData.blocktime, + expiration: new Date(exptime * 1000), + amount: txData.amount + }); + + payment.save(function(error) { + if (error) { + console.log(error); + } + + console.log('Payment saved'); + }); + } + }); + } + }); + } }, function (err) { if (err) { console.log(err); diff --git a/backend/models/user.js b/backend/models/user.js index 83ae866..4ac0030 100644 --- a/backend/models/user.js +++ b/backend/models/user.js @@ -4,7 +4,6 @@ const userSchema = mongoose.Schema({ address: {type: String, required:true}, session: {type: String, required:true}, blocktime: {type: Number, required:true}, - expiration: {type: Number, required:true, default:0}, pin: {type: String, required:true}, validated: {type: Boolean, required:true} }); diff --git a/src/app/owner.model.ts b/src/app/owner.model.ts index 0db35f4..ad4c0ed 100644 --- a/src/app/owner.model.ts +++ b/src/app/owner.model.ts @@ -7,4 +7,10 @@ export interface Owner { taxValue: number; vat: boolean; vatValue: number; + email: string; + street: string; + city: string; + state: string; + postal: string; + phone: string; } diff --git a/src/app/payment.model.ts b/src/app/payment.model.ts new file mode 100644 index 0000000..7a7e09c --- /dev/null +++ b/src/app/payment.model.ts @@ -0,0 +1,7 @@ +export interface Payment { + _id?: string; + address: string; + blocktime: number; + expiration: string; + amount: number; +}