diff --git a/db/market.go b/db/market.go index d2ae5e2..7ba4eb0 100644 --- a/db/market.go +++ b/db/market.go @@ -19,7 +19,7 @@ func (db *DB) CreateMarket(tx *sql.Tx, ctx context.Context, market *Market) erro return err } // For now, we only support binary markets. - if _, err := db.Exec("INSERT INTO shares(market_id, description) VALUES ($1, 'YES'), ($1, 'NO')", market.Id); err != nil { + if _, err := tx.Exec("INSERT INTO shares(market_id, description) VALUES ($1, 'YES'), ($1, 'NO')", market.Id); err != nil { return err } return nil diff --git a/server/router/handler/market.go b/server/router/handler/market.go index 12f7fcb..c883cdc 100644 --- a/server/router/handler/market.go +++ b/server/router/handler/market.go @@ -81,18 +81,22 @@ func HandleCreateMarket(sc context.ServerContext) echo.HandlerFunc { // TODO: add [market:] for redirect after payment invDescription = fmt.Sprintf("create market \"%s\"", m.Description) if invoice, err = sc.Lnd.CreateInvoice(tx, ctx, sc.Db, u.Pubkey, msats, invDescription); err != nil { + tx.Rollback() return err } if qr, err = lib.ToQR(invoice.PaymentRequest); err != nil { + tx.Rollback() return err } if hash, err = lntypes.MakeHashFromStr(invoice.Hash); err != nil { + tx.Rollback() return err } go sc.Lnd.CheckInvoice(sc.Db, hash) m.InvoiceId = invoice.Id if err := sc.Db.CreateMarket(tx, ctx, &m); err != nil { + tx.Rollback() return err }