diff options
| author | Adam Soltys <[email protected]> | 2020-05-18 17:46:20 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-05-18 17:46:20 -0700 |
| commit | af2d18b6508a3b50ee8272850707b5bf8c0e50a2 (patch) | |
| tree | a75fb42f37f12c8557534e29b48cfac57ad30274 /routes/assets.js | |
| parent | e8c461d90eb0f9618129a23b771851fdfec6edb1 (diff) | |
| download | coinos-server-af2d18b6508a3b50ee8272850707b5bf8c0e50a2.tar.gz coinos-server-af2d18b6508a3b50ee8272850707b5bf8c0e50a2.zip | |
handle reissuance tokens
Diffstat (limited to 'routes/assets.js')
| -rw-r--r-- | routes/assets.js | 69 |
1 files changed, 56 insertions, 13 deletions
diff --git a/routes/assets.js b/routes/assets.js index f2221e36..4a963b48 100644 --- a/routes/assets.js +++ b/routes/assets.js @@ -55,7 +55,7 @@ app.post("/assets", auth, async (req, res) => { contract_hash } ]); - const { asset, hex } = ria[0]; + const { asset, hex, token } = ria[0]; const brt = await lq.blindRawTransaction(hex, true, [], false); const srt = await lq.signRawTransactionWithWallet(brt); const allowed = (await lq.testMempoolAccept([srt.hex]))[0].allowed; @@ -73,7 +73,12 @@ app.post("/assets", auth, async (req, res) => { }); if (Math.round(funded.fee * SATS) > account.balance) { - l.error("amount exceeds balance", asset_amount, funded.fee, account.balance); + l.error( + "amount exceeds balance", + asset_amount, + funded.fee, + account.balance + ); throw new Error(`Insufficient funds to pay fee of ${funded.fee} BTC`); } @@ -93,18 +98,56 @@ app.post("/assets", auth, async (req, res) => { { transaction } ); - const payment = await db.Payment.create({ - account_id: account.id, - user_id, - hash: txid, - amount: asset_amount * SATS, - received: true, - confirmed: false, - address: asset_address, - network: "LBTC" - }); + const asset_payment = await db.Payment.create( + { + account_id: account.id, + user_id, + hash: txid, + amount: asset_amount * SATS, + received: true, + confirmed: false, + address: asset_address, + network: "LBTC" + }, + { transaction } + ); + + account = await db.Account.create( + { + asset: token, + user_id, + ticker: `${ticker}REISSUANCETOKEN`, + precision: 8, + name: `${name} Reissuance Token`, + balance: 0, + pending: token_amount * SATS + }, + { transaction } + ); - issuances[txid] = { user_id, asset, asset_amount, payment_id: payment.id }; + const token_payment = await db.Payment.create( + { + account_id: account.id, + user_id, + hash: txid, + amount: token_amount * SATS, + received: true, + confirmed: false, + address: token_address, + network: "LBTC" + }, + { transaction } + ); + + issuances[txid] = { + user_id, + asset, + asset_amount, + token, + token_amount, + asset_payment_id: asset_payment.id, + token_payment_id: token_payment.id, + }; let user = await getUserById(user_id, transaction); emit(user.username, "user", user); |
