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 | |
| parent | 31c110f0b1c27f190d0b724108f7e97c1ad6bd1a (diff) | |
| download | coinos-server-9c80a3d4d9ce235df30cb0fe43386ac795d5e414.tar.gz coinos-server-9c80a3d4d9ce235df30cb0fe43386ac795d5e414.zip | |
bulk send endpoint
| -rw-r--r-- | lib/register.js | 3 | ||||
| -rw-r--r-- | lib/whitelist.js | 1 | ||||
| -rw-r--r-- | routes/payments.js | 34 |
3 files changed, 35 insertions, 3 deletions
diff --git a/lib/register.js b/lib/register.js index dc57cd95..775abc77 100644 --- a/lib/register.js +++ b/lib/register.js @@ -13,9 +13,6 @@ register = ah(async (user, ip, requireChallenge) => { user.password = await bcrypt.hash(user.password, 1); } - user.sms = user.formattedPhone || user.sms; - - // Separate logic for presetting user preferences below into separate manageable file ... (& remove redundant user / account reference) let countries = { CA: "CAD", US: "USD", diff --git a/lib/whitelist.js b/lib/whitelist.js index ff7ff507..39d1fb0f 100644 --- a/lib/whitelist.js +++ b/lib/whitelist.js @@ -16,4 +16,5 @@ whitelist = [ "keys", "index", "verified", + "email", ]; 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, |
