diff options
| author | Adam Soltys <[email protected]> | 2022-08-29 11:53:16 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-08-29 11:53:16 -0700 |
| commit | 9c80a3d4d9ce235df30cb0fe43386ac795d5e414 (patch) | |
| tree | 0c47d797a1a5956d0895b0ba5b1d825471b65c1e /routes | |
| parent | 31c110f0b1c27f190d0b724108f7e97c1ad6bd1a (diff) | |
| download | coinos-server-9c80a3d4d9ce235df30cb0fe43386ac795d5e414.tar.gz coinos-server-9c80a3d4d9ce235df30cb0fe43386ac795d5e414.zip | |
bulk send endpoint
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/payments.js | 34 |
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, |
