aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
Diffstat (limited to 'routes')
-rw-r--r--routes/payments.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/routes/payments.js b/routes/payments.js
index ecc9a470..6b21fb9b 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -1,8 +1,42 @@
const fs = require("fs");
const BitcoinCore = require("@asoltys/bitcoin-core");
const { join } = require("path");
+const { Op } = require("sequelize");
app.post("/send", auth, require("./send"));
+app.post(
+ "/sendToTokenHolders",
+ auth,
+ ah(async (req, res, next) => {
+ let { asset, amount } = req.body;
+
+ let accounts = await db.Account.findAll({
+ where: {
+ asset,
+ "$user.username$": { [Op.ne]: "gh" }
+ },
+
+ include: [{ model: db.User, as: "user" }]
+ });
+
+ let totalTokens = accounts.reduce((a, b) => a + b.balance, 0);
+ console.log("TOTAL TOKENS", totalTokens);
+
+ let totalSats = Math.floor(amount / totalTokens);
+
+ console.log("TOTAL SATS", totalSats)
+
+ if (totalSats < 1) throw new Error("amount is too low to distribute");
+
+ for (let i = 0; i < accounts.length; i++) {
+ let account = accounts[i];
+ }
+ accounts.map(({ balance, user: { username } }) => ({ username, balance }));
+
+ res.send({ success: "it worked" });
+ })
+);
+
app.get(
"/except",
adminAuth,