lsps2: persist token with buy registration

This commit is contained in:
Jesse de Wit
2023-09-04 13:45:23 +02:00
parent 4cdb5e1c94
commit 4a6fcff707
3 changed files with 27 additions and 2 deletions

View File

@@ -25,6 +25,7 @@ type BuyRegistration struct {
Id uint64 Id uint64
LspId string LspId string
PeerId string // TODO: Make peerId in the registration a byte array. PeerId string // TODO: Make peerId in the registration a byte array.
Token string
Scid lightning.ShortChannelID Scid lightning.ShortChannelID
OpeningFeeParams shared.OpeningFeeParams OpeningFeeParams shared.OpeningFeeParams
PaymentSizeMsat *uint64 PaymentSizeMsat *uint64

View File

@@ -25,7 +25,20 @@ func (s *Lsps2Store) RegisterBuy(
ctx context.Context, ctx context.Context,
req *lsps2.RegisterBuy, req *lsps2.RegisterBuy,
) error { ) error {
_, err := s.pool.Exec( row := s.pool.QueryRow(
ctx,
`SELECT token
FROM lsps2.promises
WHERE promise = $1`,
req.OpeningFeeParams.Promise,
)
var token string
err := row.Scan(&token)
if err != nil {
return fmt.Errorf("promise does not have matching token")
}
_, err = s.pool.Exec(
ctx, ctx,
`INSERT INTO lsps2.buy_registrations ( `INSERT INTO lsps2.buy_registrations (
lsp_id lsp_id
@@ -39,6 +52,7 @@ func (s *Lsps2Store) RegisterBuy(
, params_min_lifetime , params_min_lifetime
, params_max_client_to_self_delay , params_max_client_to_self_delay
, params_promise , params_promise
, token
) )
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)`, VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)`,
req.LspId, req.LspId,
@@ -52,6 +66,7 @@ func (s *Lsps2Store) RegisterBuy(
req.OpeningFeeParams.MinLifetime, req.OpeningFeeParams.MinLifetime,
req.OpeningFeeParams.MaxClientToSelfDelay, req.OpeningFeeParams.MaxClientToSelfDelay,
req.OpeningFeeParams.Promise, req.OpeningFeeParams.Promise,
token,
) )
if err != nil { if err != nil {
if strings.Contains(err.Error(), "idx_lsps2_buy_registrations_scid") { if strings.Contains(err.Error(), "idx_lsps2_buy_registrations_scid") {
@@ -79,6 +94,7 @@ func (s *Lsps2Store) GetBuyRegistration(ctx context.Context, scid lightning.Shor
, r.params_min_lifetime , r.params_min_lifetime
, r.params_max_client_to_self_delay , r.params_max_client_to_self_delay
, r.params_promise , r.params_promise
, r.token
, c.funding_tx_id , c.funding_tx_id
, c.funding_tx_outnum , c.funding_tx_outnum
, c.is_completed , c.is_completed
@@ -99,6 +115,7 @@ func (s *Lsps2Store) GetBuyRegistration(ctx context.Context, scid lightning.Shor
var db_params_min_lifetime uint32 var db_params_min_lifetime uint32
var db_params_max_client_to_self_delay uint32 var db_params_max_client_to_self_delay uint32
var db_params_promise string var db_params_promise string
var db_token string
var db_funding_tx_id []byte var db_funding_tx_id []byte
var db_funding_tx_outnum uint32 var db_funding_tx_outnum uint32
var db_is_completed bool var db_is_completed bool
@@ -114,6 +131,7 @@ func (s *Lsps2Store) GetBuyRegistration(ctx context.Context, scid lightning.Shor
&db_params_min_lifetime, &db_params_min_lifetime,
&db_params_max_client_to_self_delay, &db_params_max_client_to_self_delay,
&db_params_promise, &db_params_promise,
&db_token,
&db_funding_tx_id, &db_funding_tx_id,
&db_funding_tx_outnum, &db_funding_tx_outnum,
&db_is_completed, &db_is_completed,

View File

@@ -11,7 +11,8 @@ CREATE TABLE lsps2.buy_registrations (
params_valid_until varchar NOT NULL, params_valid_until varchar NOT NULL,
params_min_lifetime bigint NOT NULL, params_min_lifetime bigint NOT NULL,
params_max_client_to_self_delay bigint NOT NULL, params_max_client_to_self_delay bigint NOT NULL,
params_promise varchar NOT NULL params_promise varchar NOT NULL,
token VARCHAR NOT NULL
); );
CREATE UNIQUE INDEX idx_lsps2_buy_registrations_scid ON lsps2.buy_registrations (scid); CREATE UNIQUE INDEX idx_lsps2_buy_registrations_scid ON lsps2.buy_registrations (scid);
CREATE INDEX idx_lsps2_buy_registrations_valid_until ON lsps2.buy_registrations (params_valid_until); CREATE INDEX idx_lsps2_buy_registrations_valid_until ON lsps2.buy_registrations (params_valid_until);
@@ -30,3 +31,8 @@ CREATE TABLE lsps2.bought_channels (
ON DELETE CASCADE ON DELETE CASCADE
); );
CREATE INDEX idx_lsps2_bought_channels_registration_id ON lsps2.bought_channels (registration_id); CREATE INDEX idx_lsps2_bought_channels_registration_id ON lsps2.bought_channels (registration_id);
CREATE TABLE lsps2.promises (
promise varchar PRIMARY KEY,
token varchar NOT NULL
)