aboutsummaryrefslogtreecommitdiffstats
path: root/routes/liquid
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-05-18 17:46:20 -0700
committerAdam Soltys <[email protected]>2020-05-18 17:46:20 -0700
commitaf2d18b6508a3b50ee8272850707b5bf8c0e50a2 (patch)
treea75fb42f37f12c8557534e29b48cfac57ad30274 /routes/liquid
parente8c461d90eb0f9618129a23b771851fdfec6edb1 (diff)
downloadcoinos-server-af2d18b6508a3b50ee8272850707b5bf8c0e50a2.tar.gz
coinos-server-af2d18b6508a3b50ee8272850707b5bf8c0e50a2.zip
handle reissuance tokens
Diffstat (limited to 'routes/liquid')
-rw-r--r--routes/liquid/receive.js49
1 files changed, 43 insertions, 6 deletions
diff --git a/routes/liquid/receive.js b/routes/liquid/receive.js
index f827f466..581d7ebc 100644
--- a/routes/liquid/receive.js
+++ b/routes/liquid/receive.js
@@ -58,6 +58,18 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
if (assets[asset]) {
({ ticker, precision, name } = assets[asset]);
+ } else {
+ const existing = await db.Account.findOne({
+ where: {
+ asset
+ },
+ order: [["id", "ASC"]],
+ limit: 1
+ });
+
+ if (existing) {
+ ({ ticker, precision, name } = existing);
+ }
}
params = { ...params, ...{ ticker, precision, name } };
@@ -136,8 +148,16 @@ zmqRawBlock.on("message", async (topic, message, sequence) => {
json.tx.map(async tx => {
if (issuances[tx.txid]) {
await db.transaction(async transaction => {
- const { user_id, asset, asset_amount, payment_id } = issuances[tx.txid];
- const account = await db.Account.findOne({
+ const {
+ user_id,
+ asset,
+ asset_amount,
+ asset_payment_id,
+ token,
+ token_amount,
+ token_payment_id
+ } = issuances[tx.txid];
+ let account = await db.Account.findOne({
where: { user_id, asset },
lock: transaction.LOCK.UPDATE,
transaction
@@ -146,8 +166,26 @@ zmqRawBlock.on("message", async (topic, message, sequence) => {
account.pending = 0;
await account.save({ transaction });
- const payment = await db.Payment.findOne({
- where: { id: payment_id },
+ let payment = await db.Payment.findOne({
+ where: { id: asset_payment_id },
+ lock: transaction.LOCK.UPDATE,
+ transaction
+ });
+
+ payment.confirmed = true;
+ await payment.save({ transaction });
+
+ account = await db.Account.findOne({
+ where: { user_id, asset: token },
+ lock: transaction.LOCK.UPDATE,
+ transaction
+ });
+ account.balance = token_amount * SATS;
+ account.pending = 0;
+ await account.save({ transaction });
+
+ payment = await db.Payment.findOne({
+ where: { id: token_payment_id },
lock: transaction.LOCK.UPDATE,
transaction
});
@@ -158,8 +196,7 @@ zmqRawBlock.on("message", async (topic, message, sequence) => {
const user = await getUserById(user_id, transaction);
emit(user.username, "user", user);
});
- }
- else if (hashes.includes(tx.txid)) queue[tx.txid] = 1;
+ } else if (hashes.includes(tx.txid)) queue[tx.txid] = 1;
});
});