aboutsummaryrefslogtreecommitdiffstats
path: root/routes/swaps.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-07-29 16:40:30 -0700
committerAdam Soltys <[email protected]>2020-07-29 16:40:30 -0700
commit99d71f034cfb7c1675263539fa6aecb17429d134 (patch)
tree6d29806937436fde454f357a8dd5f7a30fa6b8bd /routes/swaps.js
parentffee4c7051982f3677d6717d24e7b357a89802eb (diff)
downloadcoinos-server-99d71f034cfb7c1675263539fa6aecb17429d134.tar.gz
coinos-server-99d71f034cfb7c1675263539fa6aecb17429d134.zip
redeem codes
Diffstat (limited to 'routes/swaps.js')
-rw-r--r--routes/swaps.js43
1 files changed, 1 insertions, 42 deletions
diff --git a/routes/swaps.js b/routes/swaps.js
index 0d88f3bf..203b6602 100644
--- a/routes/swaps.js
+++ b/routes/swaps.js
@@ -4,6 +4,7 @@ const level = require("level");
const fs = require("fs");
const { spawn } = require("child_process");
const leveldb = level("leveldb");
+const getAccount = require("../lib/account");
const assets = {
b2e15d0d7a0c94e4e2ce0fe6e8691b9e451377f6e46e8045a86f7c4b5d4f0f23: "bitcoin",
@@ -538,45 +539,3 @@ app.post("/publish", auth, ah(async (req, res) => {
}
}));
-const getAccount = async (asset, user) => {
- const account = await db.Account.findOne({
- where: {
- user_id: user.id,
- asset,
- },
- });
-
- if (account) return account;
-
- let params = {
- user_id: user.id,
- asset,
- };
- let name = asset.substr(0, 6);
- let domain = '';
- let ticker = asset.substr(0, 3).toUpperCase();
- let precision = 8;
-
- const assets = (await axios.get("https://assets.blockstream.info/")).data;
-
- if (assets[asset]) {
- ({ domain, ticker, precision, name } = assets[asset]);
- } else {
- const existing = await db.Account.findOne({
- where: {
- asset,
- },
- order: [["id", "ASC"]],
- limit: 1,
- });
-
- if (existing) {
- ({ domain, ticker, precision, name } = existing);
- }
- }
-
- params = { ...params, ...{ domain, ticker, precision, name } };
- params.balance = 0;
- params.pending = 0;
- return db.Account.create(params);
-};