aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2021-04-27 15:03:44 -0700
committerAdam Soltys <[email protected]>2021-04-27 15:03:44 -0700
commit3c0e24599686733e85079241e9f38017f8027362 (patch)
tree74608e0644ef674bb47942c52ba7b767f61e9330
parentbfda62dabe0b6b7c8ac56bcc1c66074cee8b65a0 (diff)
downloadcoinos-server-3c0e24599686733e85079241e9f38017f8027362.tar.gz
coinos-server-3c0e24599686733e85079241e9f38017f8027362.zip
fix order placement bug
-rw-r--r--index.js4
-rw-r--r--routes/payments.js78
-rw-r--r--routes/swaps.js6
3 files changed, 45 insertions, 43 deletions
diff --git a/index.js b/index.js
index 29321caa..ef30244d 100644
--- a/index.js
+++ b/index.js
@@ -104,3 +104,7 @@ server.listen(config.port, () =>
);
process.on("SIGINT", process.exit);
+
+process.on('uncaughtException', function (exception) {
+ console.log(exception);
+});
diff --git a/routes/payments.js b/routes/payments.js
index cf9e1d00..e8c82853 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -13,64 +13,70 @@ ah(async () => {
const exceptions = [];
try {
- read(fs.createReadStream("exceptions"), (data) => exceptions.push(data));
+ read(fs.createReadStream("exceptions"), data => exceptions.push(data));
} catch (e) {
l.warn("couldn't read exceptions file", e.message);
}
- (await db.Invoice.findAll({
- include: {
- model: db.User,
- as: "user",
- },
- })).map(({ address, user, unconfidential }) => {
+ (
+ await db.Invoice.findAll({
+ include: {
+ model: db.User,
+ as: "user"
+ }
+ })
+ ).map(({ address, user, unconfidential }) => {
if (address && user) addresses[address] = user.username;
if (unconfidential && user) addresses[unconfidential] = user.username;
});
- const accounts = await db.Account.findAll({
- where: { pubkey: { [Op.ne]: null } },
- include: {
- model: db.User,
- as: "user",
- },
- });
+ try {
+ const accounts = await db.Account.findAll({
+ where: { pubkey: { [Op.ne]: null } },
+ include: {
+ model: db.User,
+ as: "user"
+ }
+ });
- accounts.map(({ address, user: { username } }) => {
- addresses[address] = username;
- });
+ accounts.map(({ address, user: { username } }) => {
+ addresses[address] = username;
+ });
+ } catch (e) {
+ console.log(e);
+ }
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,
- },
+ confirmed: 0
+ }
})
- ).map((p) => p.address);
+ ).map(p => p.address);
const transactions = await bc.listTransactions("*", 1000);
transactions
.filter(
- (tx) =>
+ tx =>
tx.category === "receive" &&
tx.confirmations > 0 &&
unconfirmed.includes(tx.address)
)
- .map((tx) => {
+ .map(tx => {
l.warn("tx unconfirmed in db", tx.txid, tx.address);
});
const unaccounted = [];
- transactions.map((tx) => {
+ transactions.map(tx => {
if (!payments.includes(tx.txid) && !exceptions.includes(tx.txid)) {
unaccounted.push(tx.txid);
}
@@ -117,18 +123,14 @@ ah(async () => {
setTimeout(async () => {
const address = await bc.getNewAddress();
const { hdkeypath } = await bc.getAddressInfo(address);
- const parts = hdkeypath.split('/');
+ const parts = hdkeypath.split("/");
app.set("bcAddressIndex", parts[parts.length - 1].slice(0, -1));
}, 50);
}
if (config.liquid) {
lq = new BitcoinCore(config.liquid);
- app.post(
- "/liquid/broadcast",
- optionalAuth,
- require("./liquid/broadcast")
- );
+ app.post("/liquid/broadcast", optionalAuth, require("./liquid/broadcast"));
app.get("/liquid/generate", auth, require("./liquid/generate"));
app.post("/liquid/fee", auth, require("./liquid/fee"));
app.post("/liquid/send", auth, require("./liquid/send"));
@@ -137,7 +139,7 @@ ah(async () => {
setTimeout(async () => {
const address = await lq.getNewAddress();
const { hdkeypath } = await lq.getAddressInfo(address);
- const parts = hdkeypath.split('/');
+ const parts = hdkeypath.split("/");
app.set("lqAddressIndex", parts[parts.length - 1].slice(0, -1));
}, 50);
}
@@ -148,13 +150,13 @@ ah(async () => {
ah(async (req, res) => {
let payments = await req.user.getPayments({
where: {
- account_id: req.user.account_id,
+ account_id: req.user.account_id
},
order: [["id", "DESC"]],
include: {
model: db.Account,
- as: "account",
- },
+ as: "account"
+ }
});
res.send(payments);
@@ -168,12 +170,12 @@ ah(async () => {
const { redeemcode } = req.params;
let payment = await db.Payment.findOne({
where: {
- redeemcode,
+ redeemcode
},
include: {
model: db.Account,
- as: "account",
- },
+ as: "account"
+ }
});
if (!payment) fail("invalid code");
diff --git a/routes/swaps.js b/routes/swaps.js
index 7311629c..385d7e84 100644
--- a/routes/swaps.js
+++ b/routes/swaps.js
@@ -240,9 +240,6 @@ const swap = async (user, { a1, a2, v1, v2 }) => {
{ transaction }
);
- a1acc.increment({ balance: v1 }, { transaction });
- await a1acc.reload({ transaction });
-
emit(user.username, "payment", payment.get({ plain: true }));
emit(user.username, "account", a1acc.get({ plain: true }));
@@ -450,13 +447,12 @@ app.post(
"/orders",
auth,
ah(async (req, res) => {
- return res.status(500).send("Trading temporarily disabled");
const { user } = req;
try {
await swap(user, req.body);
res.end();
} catch (e) {
- l.error(req.user.username, e.message, e.stack);
+ l.error(req.user.username, e.message);
res.status(500).send(e.message);
}
})