From f3e8bf22e334c3a2882630a5063f4548f40ab483 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Thu, 11 Nov 2021 13:52:07 -0600 Subject: [PATCH 1/6] Fix some issues tracking unconfirmed txs --- backend/app.js | 23 +++++++++-------------- backend/models/tx.js | 4 +++- src/app/login/login.component.html | 1 + src/app/login/login.component.ts | 4 ++++ 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/backend/app.js b/backend/app.js index e51a2cd..7c41fa0 100644 --- a/backend/app.js +++ b/backend/app.js @@ -98,7 +98,7 @@ var blockInterval = setInterval( function() { rpc.z_listreceivedbyaddress(fullnode.addr, 1).then(txs => { var re = /.*ZGO::(.*)\sReply-To:\s(z\w+)/; async.each (txs, function(txData, callback) { - var memo = hexToString(txData.memo); + var memo = hexToString(txData.memo).replace(/\0/g, ''); if (re.test(memo)) { //console.log('Processing tx:', memo); var match = re.exec(memo); @@ -109,6 +109,11 @@ var blockInterval = setInterval( function() { var amount = txData.amount; var expiration = blocktime; //console.log(' ', session, blocktime); + txmodel.updateOne({txid: txData.txid}, { address: address, session: session, confirmations: txData.confirmations, amount:txData.amount, memo: memo}, {new:true, upsert:true}, function(err,docs) { + if (err) { + console.log(err); + } + }); if (txData.confirmations >= 10 ) { usermodel.findOne({address: address, session: session, blocktime: blocktime}).then(function(doc){ if (doc != null) { @@ -162,17 +167,7 @@ var blockInterval = setInterval( function() { }).catch((err) => { console.log(err); }); - txmodel.deleteMany({session: session}, function(err) { - if (err) console.log(err); - console.log('Deleted confirmed login'); - }); - } else { - txmodel.updateOne({address: address, session: session}, { confirmations: txData.confirmations, amount:txData.amount}, {new:true, upsert:true}, function(err,docs) { - if (err) { - console.log(err); - } - }); - } + } } } }, function (err) { @@ -230,8 +225,8 @@ app.get('/api/users', (req, res, next) => { }); app.get('/api/pending', (req, res, next) => { - console.log('Get: /api/pending'); - txmodel.find({'session': req.query.session}). + console.log('Get: /api/pending', req.query.session); + txmodel.find({'session': req.query.session, 'confirmations': {$lt: 10}}). then((documents) => { if (documents.length > 0) { //console.log('pending', documents); diff --git a/backend/models/tx.js b/backend/models/tx.js index d55ba1d..570b325 100644 --- a/backend/models/tx.js +++ b/backend/models/tx.js @@ -4,7 +4,9 @@ const txSchema = mongoose.Schema({ address: {type: String}, session: {type: String, required:true}, confirmations: {type: Number, required:true}, - amount: {type: Number, required:true} + amount: {type: Number, required:true}, + txid: {type:String, required:true}, + memo: {type:String} }); module.exports = mongoose.model('Tx', txSchema); diff --git a/src/app/login/login.component.html b/src/app/login/login.component.html index 222274e..052079c 100644 --- a/src/app/login/login.component.html +++ b/src/app/login/login.component.html @@ -52,6 +52,7 @@ +

Wrong pin!


+

Can't scan? Use this wallet link. + From 01dcdaecd095e30e75f86d3a9100388a7c8b5518 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Sat, 13 Nov 2021 06:33:51 -0600 Subject: [PATCH 3/6] Ensure all txs are logged to DB Not just the ones with the proper memo --- backend/app.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/app.js b/backend/app.js index 7c41fa0..47356c6 100644 --- a/backend/app.js +++ b/backend/app.js @@ -99,6 +99,11 @@ var blockInterval = setInterval( function() { var re = /.*ZGO::(.*)\sReply-To:\s(z\w+)/; async.each (txs, function(txData, callback) { var memo = hexToString(txData.memo).replace(/\0/g, ''); + txmodel.updateOne({txid: txData.txid}, { confirmations: txData.confirmations, amount:txData.amount, memo: memo}, {new:true, upsert:true}, function(err,docs) { + if (err) { + console.log(err); + } + }); if (re.test(memo)) { //console.log('Processing tx:', memo); var match = re.exec(memo); @@ -114,7 +119,7 @@ var blockInterval = setInterval( function() { console.log(err); } }); - if (txData.confirmations >= 10 ) { + if (txData.confirmations >= 6 ) { usermodel.findOne({address: address, session: session, blocktime: blocktime}).then(function(doc){ if (doc != null) { console.log('Found user'); From 5c043b1e0e46b15ba215f47fc2d5c32560a4df51 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Sat, 13 Nov 2021 06:34:28 -0600 Subject: [PATCH 4/6] Reduced required confirmations to 6 --- src/app/login/login.component.html | 2 +- src/app/scan/scan.component.html | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/login/login.component.html b/src/app/login/login.component.html index 5f095bf..39ea6a9 100644 --- a/src/app/login/login.component.html +++ b/src/app/login/login.component.html @@ -39,7 +39,7 @@

Login received!

- It needs {{10 - tx.confirmations}} more confirmations. + It needs {{6 - tx.confirmations}} more confirmations. diff --git a/src/app/scan/scan.component.html b/src/app/scan/scan.component.html index 6dba52f..6674c8a 100644 --- a/src/app/scan/scan.component.html +++ b/src/app/scan/scan.component.html @@ -3,6 +3,7 @@ +
Be sure to include your reply-to address.
From 8e3c773d1e6e2167dbccbdbd602bc02616044e0b Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Sat, 13 Nov 2021 06:51:20 -0600 Subject: [PATCH 5/6] Adjust look of scan component --- src/app/scan/scan.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/scan/scan.component.html b/src/app/scan/scan.component.html index 6674c8a..0562b90 100644 --- a/src/app/scan/scan.component.html +++ b/src/app/scan/scan.component.html @@ -3,7 +3,7 @@ -
Be sure to include your reply-to address.
+

Be sure to include your reply-to address.

From fb46c626ec77cfb10219998902e6e0a5dcdb3e63 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Sat, 13 Nov 2021 07:05:54 -0600 Subject: [PATCH 6/6] Correct wallet link --- src/app/scan/scan.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/scan/scan.component.html b/src/app/scan/scan.component.html index 0562b90..641fa88 100644 --- a/src/app/scan/scan.component.html +++ b/src/app/scan/scan.component.html @@ -11,6 +11,6 @@
-

Can't scan? Use this wallet link. +

Can't scan? Use this wallet link.