mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
staticaddr/loopin: default payment timeout duration
Add a duration helper that falls back to the default payment timeout. Recovered legacy swaps can have a zero persisted timeout, so later deadline logic can use this without treating zero as immediate expiry.
This commit is contained in:
parent
7f57f6fc6b
commit
d8b24d31c0
1 changed files with 18 additions and 2 deletions
|
|
@ -467,12 +467,28 @@ func (l *StaticAddressLoopIn) TotalDepositAmount() btcutil.Amount {
|
|||
|
||||
// RemainingPaymentTimeSeconds returns the remaining time in seconds until the
|
||||
// payment timeout is reached. The remaining time is calculated from the
|
||||
// initiation time of the swap. If more than the swaps configured payment
|
||||
// initiation time of the swap. If more than the swap's configured payment
|
||||
// timeout has passed, the remaining time will be negative.
|
||||
func (l *StaticAddressLoopIn) RemainingPaymentTimeSeconds() int64 {
|
||||
elapsedSinceInitiation := time.Since(l.InitiationTime).Seconds()
|
||||
|
||||
return int64(l.PaymentTimeoutSeconds) - int64(elapsedSinceInitiation)
|
||||
return l.paymentTimeoutSeconds() - int64(elapsedSinceInitiation)
|
||||
}
|
||||
|
||||
// PaymentTimeoutDuration returns the configured payment timeout duration,
|
||||
// falling back to the default if the swap predates the persisted timeout field.
|
||||
func (l *StaticAddressLoopIn) PaymentTimeoutDuration() time.Duration {
|
||||
return time.Duration(l.paymentTimeoutSeconds()) * time.Second
|
||||
}
|
||||
|
||||
// paymentTimeoutSeconds returns the configured timeout in seconds.
|
||||
func (l *StaticAddressLoopIn) paymentTimeoutSeconds() int64 {
|
||||
timeoutSeconds := int64(l.PaymentTimeoutSeconds)
|
||||
if timeoutSeconds == 0 {
|
||||
timeoutSeconds = int64(DefaultPaymentTimeoutSeconds)
|
||||
}
|
||||
|
||||
return timeoutSeconds
|
||||
}
|
||||
|
||||
// Outpoints returns the wire outpoints of the deposits.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue