-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.js
74 lines (68 loc) · 1.92 KB
/
app.js
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
const express = require('express');
const app = express();
const TaoWallet = require('tao-wallet');
require('crypto');
app.listen(process.env.PORT || 3000, () => console.log('Welcome to Tao Wallet! Go to localhost:3000 in your browser.'))
app.use(express.static(__dirname + '/dist/tao-web'));
app.get('/', (req, res) => res.sendFile(path.join(__dirname)));
app.locals.data = {};
app.get('/login', async (req, res) => {
try {
const tao = await new TaoWallet({ lnmSecret: req.query.lnMarketsSecret, network: req.query.network });
app.locals.data.tao = tao;
await tao.login();
res.json(tao);
} catch (error) {
console.log(error)
}
});
app.get('/fetch-deposit-address', async (req, res) => {
try {
let payload = {
type: req.query.type
}
if (req.query.amountSats) payload['amountSats'] = parseInt(req.query.amountSats);
const address = await app.locals.data.tao.fetchDepositAddress(payload);
console.log(address)
res.json(address);
} catch (error) {
console.log(error)
}
});
app.get('/fetch-balances', async (req, res) => {
try {
const balances = await app.locals.data.tao.fetchBalances();
console.log(balances)
res.json(balances);
} catch (error) {
console.log(error)
}
});
app.get('/swap', async (req, res) => {
try {
let payload = {
from: req.query.from,
to: req.query.to,
amountUsd: parseInt(req.query.amountUsd)
}
const swap = await app.locals.data.tao.swap(payload);
console.log(swap)
res.json(swap);
} catch (error) {
console.log(error)
}
});
app.get('/send', async (req, res) => {
try {
let payload = {
type: req.query.type,
address: req.query.address
}
if (req.query.amountSats) payload['amountSats'] = parseInt(req.query.amountSats);
const invoice = await app.locals.data.tao.send(payload);
console.log(invoice)
res.json(invoice);
} catch (error) {
console.log(error)
}
});