mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-19 06:44:23 +01:00
move get fee params settings to shared
This commit is contained in:
@@ -8,18 +8,13 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/breez/lspd/basetypes"
|
||||
"github.com/breez/lspd/interceptor"
|
||||
"github.com/breez/lspd/shared"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/jackc/pgtype"
|
||||
"github.com/jackc/pgx/v4"
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
)
|
||||
|
||||
type extendedParams struct {
|
||||
Token string `json:"token"`
|
||||
Params interceptor.OpeningFeeParams `json:"fees_params"`
|
||||
}
|
||||
|
||||
type PostgresInterceptStore struct {
|
||||
pool *pgxpool.Pool
|
||||
}
|
||||
@@ -28,7 +23,7 @@ func NewPostgresInterceptStore(pool *pgxpool.Pool) *PostgresInterceptStore {
|
||||
return &PostgresInterceptStore{pool: pool}
|
||||
}
|
||||
|
||||
func (s *PostgresInterceptStore) PaymentInfo(htlcPaymentHash []byte) (string, *interceptor.OpeningFeeParams, []byte, []byte, []byte, int64, int64, *wire.OutPoint, *string, error) {
|
||||
func (s *PostgresInterceptStore) PaymentInfo(htlcPaymentHash []byte) (string, *shared.OpeningFeeParams, []byte, []byte, []byte, int64, int64, *wire.OutPoint, *string, error) {
|
||||
var (
|
||||
p, tag *string
|
||||
paymentHash, paymentSecret, destination []byte
|
||||
@@ -77,7 +72,7 @@ func (s *PostgresInterceptStore) SetFundingTx(paymentHash []byte, channelPoint *
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *PostgresInterceptStore) RegisterPayment(token string, params *interceptor.OpeningFeeParams, destination, paymentHash, paymentSecret []byte, incomingAmountMsat, outgoingAmountMsat int64, tag string) error {
|
||||
func (s *PostgresInterceptStore) RegisterPayment(token string, params *shared.OpeningFeeParams, destination, paymentHash, paymentSecret []byte, incomingAmountMsat, outgoingAmountMsat int64, tag string) error {
|
||||
var t *string
|
||||
if tag != "" {
|
||||
t = &tag
|
||||
@@ -127,36 +122,3 @@ func (s *PostgresInterceptStore) InsertChannel(initialChanID, confirmedChanId ui
|
||||
initialChanID, confirmedChanId, nodeID, c.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *PostgresInterceptStore) GetFeeParamsSettings(token string) ([]*interceptor.OpeningFeeParamsSetting, error) {
|
||||
rows, err := s.pool.Query(context.Background(), `SELECT validity, params FROM new_channel_params WHERE token=$1`, token)
|
||||
if err != nil {
|
||||
log.Printf("GetFeeParamsSettings(%v) error: %v", token, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var settings []*interceptor.OpeningFeeParamsSetting
|
||||
for rows.Next() {
|
||||
var validity int64
|
||||
var param string
|
||||
err = rows.Scan(&validity, ¶m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var params *interceptor.OpeningFeeParams
|
||||
err := json.Unmarshal([]byte(param), ¶ms)
|
||||
if err != nil {
|
||||
log.Printf("Failed to unmarshal fee param '%v': %v", param, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
duration := time.Second * time.Duration(validity)
|
||||
settings = append(settings, &interceptor.OpeningFeeParamsSetting{
|
||||
Validity: duration,
|
||||
Params: params,
|
||||
})
|
||||
}
|
||||
|
||||
return settings, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user