aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--createExceptions.js32
-rw-r--r--lib/read.js25
-rw-r--r--routes/payments.js100
4 files changed, 135 insertions, 23 deletions
diff --git a/.gitignore b/.gitignore
index faa85fde..d513d759 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,3 +10,4 @@ yarn-error.log
tls.*
leveldb
swaps
+exceptions
diff --git a/createExceptions.js b/createExceptions.js
new file mode 100644
index 00000000..bec6ebc6
--- /dev/null
+++ b/createExceptions.js
@@ -0,0 +1,32 @@
+BitcoinCore = require("bitcoin-core");
+fs = require("fs");
+config = require("./config");
+bc = new BitcoinCore(config.bitcoin);
+l = require("pino")();
+require("./db");
+
+console.log(db.Payment);
+
+(async () => {
+ payments = (
+ await db.Payment.findAll({
+ attributes: ["hash"],
+ })
+ ).map((p) => p.hash);
+ const transactions = await bc.listTransactions("*", 1000);
+ var stream = fs.createWriteStream("exceptions", {
+ flags: "a",
+ emitClose: true,
+ });
+ transactions.map((tx) => {
+ if (!payments.includes(tx.txid)) {
+ l.info("writing", tx.txid);
+ stream.write(tx.txid + "\n");
+ }
+ });
+ stream.end();
+ stream.on("close", () => {
+ l.info("done");
+ process.exit();
+ });
+})();
diff --git a/lib/read.js b/lib/read.js
new file mode 100644
index 00000000..dfd70e75
--- /dev/null
+++ b/lib/read.js
@@ -0,0 +1,25 @@
+module.exports = (stream, func) => {
+ var remaining = "";
+
+ stream.on("data", function (data) {
+ remaining += data;
+ var index = remaining.indexOf("\n");
+ var last = 0;
+ while (index > -1) {
+ var line = remaining.substring(last, index);
+ last = index + 1;
+ func(line);
+ index = remaining.indexOf("\n", last);
+ }
+
+ remaining = remaining.substring(last);
+ });
+
+ stream.on("error", () => {});
+
+ stream.on("end", function () {
+ if (remaining.length > 0) {
+ func(remaining);
+ }
+ });
+};
diff --git a/routes/payments.js b/routes/payments.js
index e16d6c3d..20a56baf 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -2,33 +2,80 @@ const BitcoinCore = require("bitcoin-core");
const lnd = require("../lib/lnd");
const { Op } = require("sequelize");
const { join } = require("path");
+const fs = require("fs");
+const read = require("../lib/read");
(async () => {
seen = [];
addresses = {};
issuances = {};
+ const exceptions = [];
+ try {
+ read(fs.createReadStream("exceptions"), (data) => exceptions.push(data));
+ } catch (e) {
+ l.warn("couldn't read exceptions file", e.message);
+ }
+
await db.User.findAll({
- attributes: ["username", "address", "liquid"]
- }).map(u => {
+ attributes: ["username", "address", "liquid"],
+ }).map((u) => {
if (u.address) addresses[u.address] = u.username;
if (u.liquid) addresses[u.liquid] = u.username;
});
await db.Invoice.findAll({
- include: [{
- model: db.User,
- as: 'user'}]
- }).map(i => {
+ include: [
+ {
+ model: db.User,
+ as: "user",
+ },
+ ],
+ }).map((i) => {
if (i.address && i.user) addresses[i.address] = i.user.username;
- if (i.unconfidential && i.user) addresses[i.unconfidential] = i.user.username;
+ if (i.unconfidential && i.user)
+ addresses[i.unconfidential] = i.user.username;
});
payments = (
await db.Payment.findAll({
- attributes: ["hash"]
+ attributes: ["hash"],
})
- ).map(p => p.hash);
+ ).map((p) => p.hash);
+
+ setInterval(async () => {
+ const unconfirmed = (
+ await db.Payment.findAll({
+ where: {
+ confirmed: 0,
+ },
+ })
+ ).map((p) => p.address);
+
+ const transactions = await bc.listTransactions("*", 1000);
+
+ transactions
+ .filter(
+ (tx) =>
+ tx.category === "receive" &&
+ tx.confirmations > 0 &&
+ unconfirmed.includes(tx.address)
+ )
+ .map((tx) => {
+ l.warn("tx unconfirmed in db", tx.txid);
+ });
+
+ const unaccounted = [];
+
+ transactions.map((tx) => {
+ if (!payments.includes(tx.txid) && !exceptions.includes(tx.txid)) {
+ unaccounted.push(tx.txid);
+ }
+ });
+
+ if (unaccounted.length)
+ l.warn("wallet transactions missing from database", unaccounted);
+ }, 60000);
app.post("/send", auth, require("./send"));
@@ -44,7 +91,10 @@ const { join } = require("path");
}
app.post("/lightning/channel", require("./lightning/channel"));
- app.post("/lightning/channelRequest", require("./lightning/channelRequest"));
+ app.post(
+ "/lightning/channelRequest",
+ require("./lightning/channelRequest")
+ );
app.post("/lightning/invoice", auth, require("./lightning/invoice"));
app.post("/lightning/query", auth, require("./lightning/query"));
app.post("/lightning/send", auth, require("./lightning/send"));
@@ -68,18 +118,22 @@ const { join } = require("path");
require("./liquid/receive");
}
- app.get("/payments", auth, ah(async (req, res, next) => {
- let payments = await req.user.getPayments({
- where: {
- account_id: req.user.account_id
- },
- order: [["id", "DESC"]],
- include: {
- model: db.Account,
- as: "account"
- }
- });
+ app.get(
+ "/payments",
+ auth,
+ ah(async (req, res, next) => {
+ let payments = await req.user.getPayments({
+ where: {
+ account_id: req.user.account_id,
+ },
+ order: [["id", "DESC"]],
+ include: {
+ model: db.Account,
+ as: "account",
+ },
+ });
- res.send(payments);
- }));
+ res.send(payments);
+ })
+ );
})();
-05-13 14:31:44 -0700 use ws instead of socket.io' href='/coinos-server.git/commit/lib/sockets.js?h=test&id=816bfa54afd50059d781a9da5dc953611b9fdc66'>816bfa54 ^
4487ee2d ^
0414346c ^

40fc89ab ^
37162b27 ^
4487ee2d ^
40fc89ab ^
0414346c ^
816bfa54 ^
91e84712 ^

e36990c3 ^
3161dd7e ^
13352f9b ^
3161dd7e ^









d1cc66d1 ^
3161dd7e ^




7d5a9b5a ^
3161dd7e ^



91e84712 ^
3161dd7e ^




c3565838 ^
91e84712 ^


5ae42095 ^
dce07aa9 ^
3161dd7e ^
91e84712 ^

3161dd7e ^
91e84712 ^
e918a818 ^
3161dd7e ^
91e84712 ^

3161dd7e ^

91e84712 ^

14b363bc ^
3161dd7e ^
2d7352ed ^
91e84712 ^
2d7352ed ^
3161dd7e ^



91e84712 ^
d1cc66d1 ^
3161dd7e ^












5afcf12b ^
3161dd7e ^
3161dd7e ^



d1cc66d1 ^
3161dd7e ^



3161dd7e ^
91e84712 ^


3161dd7e ^



d1cc66d1 ^
3161dd7e ^

816bfa54 ^
91e84712 ^
c0888fab ^
91e84712 ^



40fc89ab ^
91e84712 ^
40fc89ab ^

e918a818 ^
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