Skip to content

Commit 27dcb81

Browse files
committed
rfq: update expiryWithinBounds to use time.Time for expiry
Changed the `expiry` argument in `expiryWithinBounds` to be of type `time.Time` for improved type safety and clarity.
1 parent 2702cb2 commit 27dcb81

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

rfq/negotiator.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -525,12 +525,8 @@ func (n *Negotiator) HandleOutgoingSellOrder(order SellOrder) {
525525
// expiryWithinBounds checks if a quote expiry unix timestamp (in seconds) is
526526
// within acceptable bounds. This check ensures that the expiry timestamp is far
527527
// enough in the future for the quote to be useful.
528-
func expiryWithinBounds(expiryUnixTimestamp uint64,
529-
minExpiryLifetime uint64) bool {
530-
531-
// Convert the expiry timestamp into a time.Time.
532-
actualExpiry := time.Unix(int64(expiryUnixTimestamp), 0)
533-
diff := actualExpiry.Unix() - time.Now().Unix()
528+
func expiryWithinBounds(expiry time.Time, minExpiryLifetime uint64) bool {
529+
diff := expiry.Unix() - time.Now().Unix()
534530
return diff >= int64(minExpiryLifetime)
535531
}
536532

@@ -547,8 +543,9 @@ func (n *Negotiator) HandleIncomingBuyAccept(msg rfqmsg.BuyAccept,
547543
// timestamp given the expiry timestamp in our outgoing buy request.
548544
// The expiry timestamp in the outgoing request relates to the lifetime
549545
// of the lightning invoice.
550-
expiry := uint64(msg.AssetRate.Expiry.Unix())
551-
if !expiryWithinBounds(expiry, minAssetRatesExpiryLifetime) {
546+
if !expiryWithinBounds(
547+
msg.AssetRate.Expiry, minAssetRatesExpiryLifetime,
548+
) {
552549
// The expiry time is not within the acceptable bounds.
553550
log.Debugf("Buy accept quote expiry time is not within "+
554551
"acceptable bounds (asset_rate=%s)",
@@ -674,8 +671,9 @@ func (n *Negotiator) HandleIncomingSellAccept(msg rfqmsg.SellAccept,
674671
//
675672
// TODO(ffranr): Sanity check the quote expiry timestamp given
676673
// the expiry timestamp provided by the price oracle.
677-
expiry := uint64(msg.AssetRate.Expiry.Unix())
678-
if !expiryWithinBounds(expiry, minAssetRatesExpiryLifetime) {
674+
if !expiryWithinBounds(
675+
msg.AssetRate.Expiry, minAssetRatesExpiryLifetime,
676+
) {
679677
// The expiry time is not within the acceptable bounds.
680678
log.Debugf("Sell accept quote expiry time is not within "+
681679
"acceptable bounds (asset_rate=%s)",

0 commit comments

Comments
 (0)