Fix foreign key constraint violation during market creation
This commit is contained in:
parent
afba1c2bfb
commit
aa6db6a5e1
|
@ -19,7 +19,7 @@ func (db *DB) CreateMarket(tx *sql.Tx, ctx context.Context, market *Market) erro
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// For now, we only support binary markets.
|
// 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 err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -81,18 +81,22 @@ func HandleCreateMarket(sc context.ServerContext) echo.HandlerFunc {
|
||||||
// TODO: add [market:<id>] for redirect after payment
|
// TODO: add [market:<id>] for redirect after payment
|
||||||
invDescription = fmt.Sprintf("create market \"%s\"", m.Description)
|
invDescription = fmt.Sprintf("create market \"%s\"", m.Description)
|
||||||
if invoice, err = sc.Lnd.CreateInvoice(tx, ctx, sc.Db, u.Pubkey, msats, invDescription); err != nil {
|
if invoice, err = sc.Lnd.CreateInvoice(tx, ctx, sc.Db, u.Pubkey, msats, invDescription); err != nil {
|
||||||
|
tx.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if qr, err = lib.ToQR(invoice.PaymentRequest); err != nil {
|
if qr, err = lib.ToQR(invoice.PaymentRequest); err != nil {
|
||||||
|
tx.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if hash, err = lntypes.MakeHashFromStr(invoice.Hash); err != nil {
|
if hash, err = lntypes.MakeHashFromStr(invoice.Hash); err != nil {
|
||||||
|
tx.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
go sc.Lnd.CheckInvoice(sc.Db, hash)
|
go sc.Lnd.CheckInvoice(sc.Db, hash)
|
||||||
|
|
||||||
m.InvoiceId = invoice.Id
|
m.InvoiceId = invoice.Id
|
||||||
if err := sc.Db.CreateMarket(tx, ctx, &m); err != nil {
|
if err := sc.Db.CreateMarket(tx, ctx, &m); err != nil {
|
||||||
|
tx.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue