move TIME_FORMAT into lsps0

This commit is contained in:
Jesse de Wit
2023-09-04 09:24:28 +02:00
parent ea89f92eb5
commit b8e67a2968
5 changed files with 14 additions and 12 deletions

View File

@@ -8,10 +8,10 @@ import (
"log"
"time"
"github.com/breez/lspd/basetypes"
"github.com/breez/lspd/btceclegacy"
"github.com/breez/lspd/interceptor"
"github.com/breez/lspd/lightning"
"github.com/breez/lspd/lsps0"
lspdrpc "github.com/breez/lspd/rpc"
"github.com/breez/lspd/shared"
ecies "github.com/ecies/go/v2"
@@ -146,7 +146,7 @@ func (s *channelOpenerServer) RegisterPayment(
pi.OpeningFeeParams = &lspdrpc.OpeningFeeParams{
MinMsat: uint64(node.NodeConfig.ChannelMinimumFeeMsat),
Proportional: uint32(node.NodeConfig.ChannelFeePermyriad * 100),
ValidUntil: time.Now().UTC().Add(time.Duration(time.Hour * 24)).Format(basetypes.TIME_FORMAT),
ValidUntil: time.Now().UTC().Add(time.Duration(time.Hour * 24)).Format(lsps0.TIME_FORMAT),
MaxIdleTime: uint32(node.NodeConfig.MaxInactiveDuration / 600),
MaxClientToSelfDelay: uint32(10000),
}

View File

@@ -13,6 +13,7 @@ import (
"github.com/breez/lspd/chain"
"github.com/breez/lspd/config"
"github.com/breez/lspd/lightning"
"github.com/breez/lspd/lsps0"
"github.com/breez/lspd/notifications"
"github.com/breez/lspd/shared"
"github.com/btcsuite/btcd/wire"
@@ -191,7 +192,7 @@ func (i *Interceptor) Intercept(scid *basetypes.ShortChannelID, reqPaymentHash [
params = &shared.OpeningFeeParams{
MinFeeMsat: uint64(i.config.ChannelMinimumFeeMsat),
Proportional: uint32(i.config.ChannelFeePermyriad * 100),
ValidUntil: time.Now().UTC().Add(time.Duration(time.Hour * 24)).Format(basetypes.TIME_FORMAT),
ValidUntil: time.Now().UTC().Add(time.Duration(time.Hour * 24)).Format(lsps0.TIME_FORMAT),
MinLifetime: uint32(i.config.MaxInactiveDuration / 600),
MaxClientToSelfDelay: uint32(10000),
}
@@ -206,9 +207,9 @@ func (i *Interceptor) Intercept(scid *basetypes.ShortChannelID, reqPaymentHash [
}, nil
}
validUntil, err := time.Parse(basetypes.TIME_FORMAT, params.ValidUntil)
validUntil, err := time.Parse(lsps0.TIME_FORMAT, params.ValidUntil)
if err != nil {
log.Printf("time.Parse(%s, %s) failed. Failing channel open: %v", basetypes.TIME_FORMAT, params.ValidUntil, err)
log.Printf("time.Parse(%s, %s) failed. Failing channel open: %v", lsps0.TIME_FORMAT, params.ValidUntil, err)
return InterceptResult{
Action: INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,

View File

@@ -1,3 +1,3 @@
package basetypes
package lsps0
var TIME_FORMAT string = "2006-01-02T15:04:05.999Z"

View File

@@ -7,6 +7,7 @@ import (
"time"
"github.com/breez/lspd/basetypes"
"github.com/breez/lspd/lsps0"
"github.com/breez/lspd/shared"
"github.com/btcsuite/btcd/wire"
)
@@ -33,9 +34,9 @@ type BuyRegistration struct {
}
func (b *BuyRegistration) IsExpired() bool {
t, err := time.Parse(basetypes.TIME_FORMAT, b.OpeningFeeParams.ValidUntil)
t, err := time.Parse(lsps0.TIME_FORMAT, b.OpeningFeeParams.ValidUntil)
if err != nil {
log.Printf("BuyRegistration.IsExpired(): time.Parse(%v, %v) error: %v", basetypes.TIME_FORMAT, b.OpeningFeeParams.ValidUntil, err)
log.Printf("BuyRegistration.IsExpired(): time.Parse(%v, %v) error: %v", lsps0.TIME_FORMAT, b.OpeningFeeParams.ValidUntil, err)
return true
}

View File

@@ -9,7 +9,7 @@ import (
"sort"
"time"
"github.com/breez/lspd/basetypes"
"github.com/breez/lspd/lsps0"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
)
@@ -51,7 +51,7 @@ func (s *openingService) GetFeeParamsMenu(token string, privateKey *btcec.Privat
params := &OpeningFeeParams{
MinFeeMsat: setting.Params.MinFeeMsat,
Proportional: setting.Params.Proportional,
ValidUntil: validUntil.Format(basetypes.TIME_FORMAT),
ValidUntil: validUntil.Format(lsps0.TIME_FORMAT),
MinLifetime: setting.Params.MinLifetime,
MaxClientToSelfDelay: setting.Params.MaxClientToSelfDelay,
}
@@ -86,9 +86,9 @@ func (s *openingService) ValidateOpeningFeeParams(params *OpeningFeeParams, publ
return false
}
t, err := time.Parse(basetypes.TIME_FORMAT, params.ValidUntil)
t, err := time.Parse(lsps0.TIME_FORMAT, params.ValidUntil)
if err != nil {
log.Printf("validateOpeningFeeParams: time.Parse(%v, %v) error: %v", basetypes.TIME_FORMAT, params.ValidUntil, err)
log.Printf("validateOpeningFeeParams: time.Parse(%v, %v) error: %v", lsps0.TIME_FORMAT, params.ValidUntil, err)
return false
}