aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/launch/register/+page.svelte
blob: 437a48f11d6408ad763b35f5638f43c6ce86e53c (plain) (blame)
1
We need to get you registered
020-03-11 22:01:35 -0700 committer Adam Soltys <[email protected]> 2020-03-11 22:01:35 -0700 drop lnrpc' href='/coinos-server.git/commit/routes/lightning/receive.js?h=conversions&id=a22b5cd3769ea6d7aac4f34acf142534ee75491c'>a22b5cd3 ^
765c6a42 ^
a22b5cd3 ^

765c6a42 ^
a22b5cd3 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

                                    
 





                                            
 
                       
 
                           
 




                                                 
 



                                                                      
 


                                          
 

                                           
 

                                            
const handlePayment = async msg => {
  if (!msg.settled) return;

  let payment = await db.Payment.findOne({
    include: { model: db.User, as: "user" },
    where: {
      hash: msg.payment_request
    }
  });

  if (!payment) return;

  const { user } = payment;

  payment.received = true;
  user.balance += parseInt(msg.value);
  payment.rate = app.get("rates")[user.currency];
  payment.confirmed = true;
  payment.currency = user.currency;

  await payment.save();
  await user.save();
  payments.push(msg.payment_request);
  l.info("lightning payment received", user.username, payment.amount);

  emit(user.username, "payment", payment);
  emit(user.username, "user", user);
};

const invoices = lna.subscribeInvoices({});
invoices.on("data", handlePayment);

const invoicesb = lnb.subscribeInvoices({});
invoicesb.on("data", handlePayment);