commit b15d8918bf301e0c4bba7925997946dad3d0d7d1
parent 740d67b2fa350a7a4723cd5f89e0347e8fa2d8d8
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Wed, 13 Dec 2023 22:33:11 -0500
db transaction
Diffstat:
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -829,20 +829,23 @@ func PokerHomeHandler(c echo.Context) error {
data.Error = fmt.Sprintf("not enough funds to pay for transaction fee %d (%s xmr)", transactionFee, transactionFee.XmrStr())
return c.Render(http.StatusOK, "poker", data)
}
- authUser.XmrBalanceStagenet = authUser.XmrBalanceStagenet - (withdrawAmount + houseFee + transactionFee)
- authUser.DoSave(db)
+ tx := db.Begin()
+ err = tx.DB().Exec(`UPDATE users SET xmr_balance_stagenet = xmr_balance_stagenet - ? WHERE id = ?`, withdrawAmount+houseFee+transactionFee, authUser.ID).Error
if _, err := config.Xmr().RelayTx(&wallet1.RequestRelayTx{Hex: res.TxMetadata}); err != nil {
logrus.Error(err)
data.Error = err.Error()
+ tx.Rollback()
return c.Render(http.StatusOK, "poker", data)
}
-
- if _, err := db.CreatePokerXmrTransaction(authUser.ID, res); err != nil {
- logrus.Error(err)
+ if _, err := tx.CreatePokerXmrTransaction(authUser.ID, res); err != nil {
+ logrus.Error("failed to create poker xmr transaction", err)
data.Error = err.Error()
+ tx.Commit()
return c.Render(http.StatusOK, "poker", data)
}
+ tx.Commit()
+
return c.Redirect(http.StatusFound, c.Request().Referer())
}