diff --git a/postgresql/lsps2_store.go b/postgresql/lsps2_store.go index 609950e..8ec08d1 100644 --- a/postgresql/lsps2_store.go +++ b/postgresql/lsps2_store.go @@ -54,7 +54,7 @@ func (s *Lsps2Store) RegisterBuy( , 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, $12)`, req.LspId, req.PeerId, int64(uint64(req.Scid)), @@ -116,15 +116,16 @@ func (s *Lsps2Store) GetBuyRegistration(ctx context.Context, scid lightning.Shor var db_params_max_client_to_self_delay uint32 var db_params_promise string var db_token string - var db_funding_tx_id []byte - var db_funding_tx_outnum uint32 - var db_is_completed bool + var db_funding_tx_id *[]byte + var db_funding_tx_outnum *uint32 + var db_is_completed *bool err := row.Scan( &db_id, &db_lsp_id, &db_peer_id, &db_scid, - db_payment_size_msat, + &db_mode, + &db_payment_size_msat, &db_params_min_fee_msat, &db_params_proportional, &db_params_valid_until, @@ -150,13 +151,18 @@ func (s *Lsps2Store) GetBuyRegistration(ctx context.Context, scid lightning.Shor } var cp *wire.OutPoint - if db_funding_tx_id != nil { - cp, err = lightning.NewOutPoint(db_funding_tx_id, db_funding_tx_outnum) + if db_funding_tx_id != nil && db_funding_tx_outnum != nil { + cp, err = lightning.NewOutPoint(*db_funding_tx_id, *db_funding_tx_outnum) if err != nil { return nil, fmt.Errorf("invalid funding tx id in db: %x", db_funding_tx_id) } } + isCompleted := false + if db_is_completed != nil { + isCompleted = *db_is_completed + } + return &lsps2.BuyRegistration{ Id: db_id, LspId: db_lsp_id, @@ -173,7 +179,7 @@ func (s *Lsps2Store) GetBuyRegistration(ctx context.Context, scid lightning.Shor PaymentSizeMsat: paymentSizeMsat, Mode: lsps2.OpeningMode(db_mode), ChannelPoint: cp, - IsComplete: db_is_completed, + IsComplete: isCompleted, }, nil } diff --git a/postgresql/migrations/000014_lsps2_buy.down.sql b/postgresql/migrations/000014_lsps2_buy.down.sql index f9cc836..3f60b26 100644 --- a/postgresql/migrations/000014_lsps2_buy.down.sql +++ b/postgresql/migrations/000014_lsps2_buy.down.sql @@ -1,6 +1,7 @@ +DROP TABLE lsps2.promises; DROP INDEX idx_lsps2_bought_channels_registration_id; DROP TABLE lsps2.bought_channels; DROP INDEX idx_lsps2_buy_registrations_valid_until; DROP INDEX idx_lsps2_buy_registrations_scid; DROP TABLE lsps2.buy_registrations; -DROP SCHEMA lsps2; \ No newline at end of file +DROP SCHEMA lsps2; diff --git a/postgresql/migrations/000014_lsps2_buy.up.sql b/postgresql/migrations/000014_lsps2_buy.up.sql index 4986a49..c805a15 100644 --- a/postgresql/migrations/000014_lsps2_buy.up.sql +++ b/postgresql/migrations/000014_lsps2_buy.up.sql @@ -1,8 +1,8 @@ CREATE SCHEMA lsps2; CREATE TABLE lsps2.buy_registrations ( id bigserial PRIMARY KEY, - lsp_id bytea NOT NULL, - peer_id bytea NOT NULL, + lsp_id varchar NOT NULL, + peer_id varchar NOT NULL, scid bigint NOT NULL, mode smallint NOT NULL, payment_size_msat bigint NULL, @@ -35,4 +35,4 @@ CREATE INDEX idx_lsps2_bought_channels_registration_id ON lsps2.bought_channels CREATE TABLE lsps2.promises ( promise varchar PRIMARY KEY, token varchar NOT NULL -) \ No newline at end of file +)