aboutsummaryrefslogtreecommitdiffstats
path: root/public/css/bootstrap.css
diff options
context:
space:
mode:
Diffstat (limited to 'public/css/bootstrap.css')
0 files changed, 0 insertions, 0 deletions
migration' href='/coinos-server.git/commit/routes/invoices.js?id=412df5f844de11b3fc71bb7ffaf9c8e1d9f19d65'>412df5f8 ^
c3efae9d ^


a0422300 ^
3161dd7e ^











7b444094 ^
3161dd7e ^

fb91aa04 ^







28179d6b ^








fb91aa04 ^
28179d6b ^
fb91aa04 ^










3161dd7e ^

7b444094 ^
3161dd7e ^

c3efae9d ^


e894563f ^
c3efae9d ^

3161dd7e ^
3ff26389 ^
3161dd7e ^
68a4352c ^

3161dd7e ^
fb2a1a9f ^
3161dd7e ^




c3efae9d ^



3161dd7e ^



c3efae9d ^
















c3efae9d ^






















d1cc66d1 ^
3161dd7e ^







a0422300 ^
3161dd7e ^
a0422300 ^
c3efae9d ^
13352f9b ^
3161dd7e ^
13352f9b ^
3161dd7e ^
19038304 ^
3161dd7e ^


d1cc66d1 ^
8a82c694 ^
3161dd7e ^

68d41ff2 ^



3161dd7e ^
68d41ff2 ^
3161dd7e ^
68d41ff2 ^
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
                       

                               
                                             

                                     
                                      


                                                                          
 











                                               
 

                      







                                                     








                                                                  
                                              
            










                                            

   
 

                                                              


                                                                             
 

                                                           
                                                 
 
                        

                                                           
     
 




                                    



                            



                                                    
















                                                                           






















                                                                           
      







                                                                                
 
                                      
 
                                               
                                                     
                                 
                                                              
                                                                          
     


                      
                            
                                                                        

   



                                
                             
                                           
   
  
import app from "$app";
import db from "$db";
import store from "$lib/store";
import { optionalAuth } from "$lib/passport";
import { Op } from "@sequelize/core";
import axios from "axios";
import { err, l } from "$lib/logging";
import bc from "$lib/bitcoin";
import lq from "$lib/liquid";
import { SATS, bip21, deriveAddress, derivePayRequest } from "$lib/utils";

app.get("/invoice", async (req, res, next) => {
  try {
    const invoice = await db.Invoice.findOne({
      where: {
        uuid: req.query.uuid
      },
      include: {
        model: db.User,
        as: "user",
        attributes: ["username", "currency"]
      }
    });

    res.send(invoice);
  } catch (e) {
    err("invoice not found", e);
    res.code(500).send("Invoice not found");
  }
});

app.get("/invoice/:text", async (req, res, next) => {
  try {
    let { text } = req.params;
    let where =
      text.split("-").length > 4
        ? { uuid: text }
        : text.startsWith("ln")
        ? { text }
        : {
            [Op.or]: [{ unconfidential: text }, { address: text }]
          };

    const invoice = await db.Invoice.findOne({
      where,
      include: {
        model: db.User,
        as: "user",
        attributes: ["username", "currency"]
      }
    });

    res.send(invoice);
  } catch (e) {
    err("invoice not found", e);
    res.code(500).send("Invoice not found");
  }
});

app.post("/invoice", optionalAuth, async (req, res, next) => {
  try {
    let { type = "bech32", liquidAddress, id, invoice, user, tx } = req.body;
    let { blindkey, currency, tip, amount, rate, network } = invoice;
    let address, unconfidential, text;

    if (amount < 0) throw new Error("amount out of range");
    if (tip > amount || tip > 1000000 || tip < 0)
      throw new Error("tip amount out of range");

    if (liquidAddress) {
      l("conversion request for", liquidAddress, text);
      store.convert[text] = { address: liquidAddress, tx };
    }

    if (!user) ({ user } = req);
    else {
      user = await db.User.findOne({
        where: {
          username: user.username
        },
        include: {
          model: db.Account,
          as: "account"
        }
      });
    }
    if (!user) throw new Error("user not provided");
    if (!currency) currency = user.currency;
    if (!rate) rate = store.rates[currency];
    if (tip > amount || tip > 1000000) throw new Error("tip is too large");
    if (tip < 0 || amount < 0) throw new Error("invalid amount");

    if (user.account.pubkey) {
      let { address, confidentialAddress } = await deriveAddress(
        user.account,
        type
      );
      if (confidentialAddress) {
        address = confidentialAddress;
        unconfidential = address;
      } else {
        address = address;
      }
    } else if (network !== "lightning") {
      address = await { bitcoin: bc, liquid: lq }[network].getNewAddress();
      if (network === "liquid")
        ({ unconfidential } = await lq.getAddressInfo(address));
    }

    invoice = {
      ...invoice,
      account_id: user.account.id,
      address,
      amount,
      currency,
      rate,
      tip,
      unconfidential,
      user_id: user.id
    };

    if (network === "lightning") {
      invoice.text = await derivePayRequest(invoice);
    } else {
      invoice.text = bip21(invoice, user.account);
    }

    l(
      "creating invoice",
      user.username,
      invoice.network,
      invoice.amount,
      invoice.tip,
      invoice.currency,
      invoice.text && `${invoice.text.substr(0, 8)}..${invoice.text.substr(-6)}`
    );

    if (!invoice.tip) invoice.tip = 0;

    invoice = await db.Invoice.create(invoice);
    store.addresses[invoice.address] = user.username;
    if (invoice.unconfidential) {
      store.addresses[invoice.unconfidential] = user.username;
      if (blindkey) await lq.importBlindingKey(invoice.address, blindkey);
    }

    res.send(invoice);
  } catch (e) {
    err(e.message, e.stack);
    res.code(500).send(`Problem during invoice creation: ${e.message}`);
  }
});

app.post(
  "/:username/:network/invoice",
  optionalAuth,
  async (req, res, next) => {
    let { network, username } = req.params;
  }
);