aboutsummaryrefslogtreecommitdiffstats
path: root/index.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2019-01-02 15:31:03 -0800
committerAdam Soltys <[email protected]>2019-02-05 20:53:45 -0800
commitfea5db65026c883bc36199d53c233faaf1021c11 (patch)
tree801421c37ef4dbef24f449f3706aad3055bb1e94 /index.js
parentfe1607d4da4e981b685333defcab521ae3ef87f3 (diff)
downloadcoinos-server-fea5db65026c883bc36199d53c233faaf1021c11.tar.gz
coinos-server-fea5db65026c883bc36199d53c233faaf1021c11.zip
check payment confirmations
Diffstat (limited to 'index.js')
-rw-r--r--index.js32
1 files changed, 15 insertions, 17 deletions
diff --git a/index.js b/index.js
index 001e9214..c63e764c 100644
--- a/index.js
+++ b/index.js
@@ -199,7 +199,8 @@ const l = console.log
currency: 'CAD',
rate: app.get('rates').ask,
received: true,
- tip
+ tip,
+ confirmed: false,
})
socket.to(sids[user.username]).emit('tx', message)
@@ -218,24 +219,21 @@ const l = console.log
let block = bitcoin.Block.fromHex(message)
l('block', block.getHash().toString('hex'))
- await db.User.findAll({
- where: {
- pending: {
- [Sequelize.Op.ne]: null,
- [Sequelize.Op.ne]: 0,
- }
- },
- }).map(async user => {
- user.balance += user.pending
- user.pending = 0
- await user.save()
- socket.to(sids[user.username]).emit('user', user)
+ let payments = await db.Payment.findAll({
+ include: { model: db.User, as: 'user' },
+ where: { confirmed: false },
+ }).map(async p => {
+ if ((await bc.getRawTransaction(p.hash, true)).confirmations > 0) {
+ let user = p.user
+ p.confirmed = true
+ user.balance += p.amount
+ user.pending -= p.amount
+ await user.save()
+ await p.save()
+ socket.to(sids[user.username]).emit('user', user)
+ }
})
- await db.Payment.update({
- confirmed: true,
- }, { where: {} })
-
socket.emit('block', message)
break
}