aboutsummaryrefslogtreecommitdiffstats
path: root/routes/assets.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-06-08 13:04:02 -0700
committerAdam Soltys <[email protected]>2020-06-08 13:04:02 -0700
commit7a3a07bc711ea57fd8a84e809e7ecd0d6e64b5c2 (patch)
treeb31a06affa4b932990744997c271f6d65502d60c /routes/assets.js
parent298672d3f50938ba06a16f8e04d607b7033703b8 (diff)
downloadcoinos-server-7a3a07bc711ea57fd8a84e809e7ecd0d6e64b5c2.tar.gz
coinos-server-7a3a07bc711ea57fd8a84e809e7ecd0d6e64b5c2.zip
reduce network traffic
Diffstat (limited to 'routes/assets.js')
-rw-r--r--routes/assets.js24
1 files changed, 16 insertions, 8 deletions
diff --git a/routes/assets.js b/routes/assets.js
index 9c60500c..25ed8ea6 100644
--- a/routes/assets.js
+++ b/routes/assets.js
@@ -56,15 +56,15 @@ app.post("/assets", auth, async (req, res) => {
params.token_amount = token_amount;
params.token_address = token_address;
params.token_amount = parseInt(params.token_amount);
- }
+ }
let ria;
try {
ria = await lq.rawIssueAsset(funded.hex, [params]);
- } catch(e) {
+ } catch (e) {
l.info(asset_amount, token_amount, params);
throw new Error(e.message);
- }
+ }
const { asset, hex, token } = ria[0];
const brt = await lq.blindRawTransaction(hex, true, [], false);
@@ -79,10 +79,16 @@ app.post("/assets", auth, async (req, res) => {
user_id,
asset: config.liquid.btcasset
},
+ include: {
+ model: db.User,
+ as: "user"
+ },
lock: transaction.LOCK.UPDATE,
transaction
});
+ let { user } = account;
+
if (Math.round(funded.fee * SATS) > account.balance) {
l.error(
"amount exceeds balance",
@@ -95,6 +101,7 @@ app.post("/assets", auth, async (req, res) => {
account.balance -= Math.round(funded.fee * SATS);
await account.save({ transaction });
+ emit(user.username, "account", account);
account = await db.Account.create(
{
@@ -109,6 +116,8 @@ app.post("/assets", auth, async (req, res) => {
{ transaction }
);
+ emit(user.username, "account", account);
+
const asset_payment = await db.Payment.create(
{
account_id: account.id,
@@ -122,12 +131,13 @@ app.post("/assets", auth, async (req, res) => {
},
{ transaction }
);
+ emit(user.username, "payment", asset_payment);
issuances[txid] = {
user_id,
asset,
asset_amount,
- asset_payment_id: asset_payment.id,
+ asset_payment_id: asset_payment.id
};
if (token_amount) {
@@ -143,6 +153,7 @@ app.post("/assets", auth, async (req, res) => {
},
{ transaction }
);
+ emit(user.username, "account", account);
const token_payment = await db.Payment.create(
{
@@ -157,15 +168,12 @@ app.post("/assets", auth, async (req, res) => {
},
{ transaction }
);
+ emit(user.username, "payment", token_payment);
issuances[txid].token = token;
issuances[txid].token_amount = token_amount;
issuances[txid].token_payment_id = token_payment.id;
}
-
-
- let user = await getUserById(user_id, transaction);
- emit(user.username, "user", user);
});
res.send(issuances[txid]);