Skip to content

Commit

Permalink
lsps2: save token with generated promises
Browse files Browse the repository at this point in the history
  • Loading branch information
JssDWt committed Sep 4, 2023
1 parent 835c7cb commit f7e5747
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lsps2/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func (s *mockLsps2Store) SetCompleted(ctx context.Context, registrationId uint64
return nil
}

func (s *mockLsps2Store) SavePromises(ctx context.Context, req *SavePromises) error {
return nil
}

type mockLightningClient struct {
openResponses []*wire.OutPoint
openRequests []*lightning.OpenChannelRequest
Expand Down
9 changes: 9 additions & 0 deletions lsps2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ func (s *server) GetInfo(
return nil, status.New(codes.InternalError, "internal error").Err()
}

err = s.store.SavePromises(ctx, &SavePromises{
Menu: m,
Token: *request.Token,
})
if err != nil {
log.Printf("Lsps2Server.GetInfo: store.SavePromises(%+v, %s) err: %v", m, *request.Token, err)
return nil, status.New(codes.InternalError, "internal error").Err()
}

menu := []*OpeningFeeParams{}
for _, p := range m {
menu = append(menu, &OpeningFeeParams{
Expand Down
6 changes: 6 additions & 0 deletions lsps2/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import (
"github.com/btcsuite/btcd/wire"
)

type SavePromises struct {
Menu []*shared.OpeningFeeParams
Token string
}

type RegisterBuy struct {
LspId string
PeerId string
Expand Down Expand Up @@ -59,6 +64,7 @@ var ErrScidExists = errors.New("scid exists")
var ErrNotFound = errors.New("not found")

type Lsps2Store interface {
SavePromises(ctx context.Context, req *SavePromises) error
RegisterBuy(ctx context.Context, req *RegisterBuy) error
GetBuyRegistration(ctx context.Context, scid lightning.ShortChannelID) (*BuyRegistration, error)
SetChannelOpened(ctx context.Context, channelOpened *ChannelOpened) error
Expand Down
21 changes: 21 additions & 0 deletions postgresql/lsps2_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,24 @@ func (s *Lsps2Store) SetCompleted(ctx context.Context, registrationId uint64) er

return nil
}

func (s *Lsps2Store) SavePromises(
ctx context.Context,
req *lsps2.SavePromises,
) error {
if len(req.Menu) == 0 {
return nil
}

rows := [][]interface{}{}
for _, p := range req.Menu {
rows = append(rows, []interface{}{p.Promise, req.Token})
}
_, err := s.pool.CopyFrom(
ctx,
pgx.Identifier{"promises"},
[]string{"promise", "token"},
pgx.CopyFromRows(rows),
)
return err
}

0 comments on commit f7e5747

Please sign in to comment.