mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-19 23:04:22 +01:00
lsps2: save token with generated promises
This commit is contained in:
@@ -79,6 +79,10 @@ func (s *mockLsps2Store) SetCompleted(ctx context.Context, registrationId uint64
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *mockLsps2Store) SavePromises(ctx context.Context, req *SavePromises) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type mockLightningClient struct {
|
type mockLightningClient struct {
|
||||||
openResponses []*wire.OutPoint
|
openResponses []*wire.OutPoint
|
||||||
openRequests []*lightning.OpenChannelRequest
|
openRequests []*lightning.OpenChannelRequest
|
||||||
|
|||||||
@@ -132,6 +132,15 @@ func (s *server) GetInfo(
|
|||||||
return nil, status.New(codes.InternalError, "internal error").Err()
|
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{}
|
menu := []*OpeningFeeParams{}
|
||||||
for _, p := range m {
|
for _, p := range m {
|
||||||
menu = append(menu, &OpeningFeeParams{
|
menu = append(menu, &OpeningFeeParams{
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ import (
|
|||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type SavePromises struct {
|
||||||
|
Menu []*shared.OpeningFeeParams
|
||||||
|
Token string
|
||||||
|
}
|
||||||
|
|
||||||
type RegisterBuy struct {
|
type RegisterBuy struct {
|
||||||
LspId string
|
LspId string
|
||||||
PeerId string
|
PeerId string
|
||||||
@@ -59,6 +64,7 @@ var ErrScidExists = errors.New("scid exists")
|
|||||||
var ErrNotFound = errors.New("not found")
|
var ErrNotFound = errors.New("not found")
|
||||||
|
|
||||||
type Lsps2Store interface {
|
type Lsps2Store interface {
|
||||||
|
SavePromises(ctx context.Context, req *SavePromises) error
|
||||||
RegisterBuy(ctx context.Context, req *RegisterBuy) error
|
RegisterBuy(ctx context.Context, req *RegisterBuy) error
|
||||||
GetBuyRegistration(ctx context.Context, scid lightning.ShortChannelID) (*BuyRegistration, error)
|
GetBuyRegistration(ctx context.Context, scid lightning.ShortChannelID) (*BuyRegistration, error)
|
||||||
SetChannelOpened(ctx context.Context, channelOpened *ChannelOpened) error
|
SetChannelOpened(ctx context.Context, channelOpened *ChannelOpened) error
|
||||||
|
|||||||
@@ -216,3 +216,24 @@ func (s *Lsps2Store) SetCompleted(ctx context.Context, registrationId uint64) er
|
|||||||
|
|
||||||
return nil
|
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{"lsps2", "promises"},
|
||||||
|
[]string{"promise", "token"},
|
||||||
|
pgx.CopyFromRows(rows),
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user