Skip to content

Commit

Permalink
rfq: update expiryWithinBounds to use time.Time for expiry
Browse files Browse the repository at this point in the history
Changed the `expiry` argument in `expiryWithinBounds` to be of type
`time.Time` for improved type safety and clarity.
  • Loading branch information
ffranr committed Nov 15, 2024
1 parent 9746620 commit f48e568
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions rfq/negotiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,8 @@ func (n *Negotiator) HandleOutgoingSellOrder(order SellOrder) {
// expiryWithinBounds checks if a quote expiry unix timestamp (in seconds) is
// within acceptable bounds. This check ensures that the expiry timestamp is far
// enough in the future for the quote to be useful.
func expiryWithinBounds(expiryUnixTimestamp uint64,
minExpiryLifetime uint64) bool {

// Convert the expiry timestamp into a time.Time.
actualExpiry := time.Unix(int64(expiryUnixTimestamp), 0)
diff := actualExpiry.Unix() - time.Now().Unix()
func expiryWithinBounds(expiry time.Time, minExpiryLifetime uint64) bool {
diff := expiry.Unix() - time.Now().Unix()
return diff >= int64(minExpiryLifetime)
}

Expand All @@ -549,8 +545,9 @@ func (n *Negotiator) HandleIncomingBuyAccept(msg rfqmsg.BuyAccept,
// timestamp given the expiry timestamp in our outgoing buy request.
// The expiry timestamp in the outgoing request relates to the lifetime
// of the lightning invoice.
expiry := uint64(msg.AssetRate.Expiry.Unix())
if !expiryWithinBounds(expiry, minAssetRatesExpiryLifetime) {
if !expiryWithinBounds(
msg.AssetRate.Expiry, minAssetRatesExpiryLifetime,
) {
// The expiry time is not within the acceptable bounds.
log.Debugf("Buy accept quote expiry time is not within "+
"acceptable bounds (asset_rate=%s)",
Expand Down Expand Up @@ -676,8 +673,9 @@ func (n *Negotiator) HandleIncomingSellAccept(msg rfqmsg.SellAccept,
//
// TODO(ffranr): Sanity check the quote expiry timestamp given
// the expiry timestamp provided by the price oracle.
expiry := uint64(msg.AssetRate.Expiry.Unix())
if !expiryWithinBounds(expiry, minAssetRatesExpiryLifetime) {
if !expiryWithinBounds(
msg.AssetRate.Expiry, minAssetRatesExpiryLifetime,
) {
// The expiry time is not within the acceptable bounds.
log.Debugf("Sell accept quote expiry time is not within "+
"acceptable bounds (asset_rate=%s)",
Expand Down

0 comments on commit f48e568

Please sign in to comment.