-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into maxHtlcValueInFlight_comparison
# Conflicts: # eclair-core/src/main/scala/fr/acinq/eclair/package.scala # eclair-core/src/test/scala/fr/acinq/eclair/payment/RelayerSpec.scala
- Loading branch information
Showing
124 changed files
with
4,661 additions
and
3,351 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
eclair-core/src/main/scala/fr/acinq/eclair/CltvExpiry.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2019 ACINQ SAS | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package fr.acinq.eclair | ||
|
||
/** | ||
* Created by t-bast on 21/08/2019. | ||
*/ | ||
|
||
/** | ||
* Bitcoin scripts (in particular HTLCs) need an absolute block expiry (greater than the current block count) to work | ||
* with OP_CLTV. | ||
* | ||
* @param underlying the absolute cltv expiry value (current block count + some delta). | ||
*/ | ||
case class CltvExpiry(private val underlying: Long) extends Ordered[CltvExpiry] { | ||
// @formatter:off | ||
def +(d: CltvExpiryDelta): CltvExpiry = CltvExpiry(underlying + d.toInt) | ||
def -(d: CltvExpiryDelta): CltvExpiry = CltvExpiry(underlying - d.toInt) | ||
def -(other: CltvExpiry): CltvExpiryDelta = CltvExpiryDelta((underlying - other.underlying).toInt) | ||
override def compare(other: CltvExpiry): Int = underlying.compareTo(other.underlying) | ||
def toLong: Long = underlying | ||
// @formatter:on | ||
} | ||
|
||
/** | ||
* Channels advertise a cltv expiry delta that should be used when routing through them. | ||
* This value needs to be converted to a [[fr.acinq.eclair.CltvExpiry]] to be used in OP_CLTV. | ||
* | ||
* CltvExpiryDelta can also be used when working with OP_CSV which is by design a delta. | ||
* | ||
* @param underlying the cltv expiry delta value. | ||
*/ | ||
case class CltvExpiryDelta(private val underlying: Int) extends Ordered[CltvExpiryDelta] { | ||
|
||
/** | ||
* Adds the current block height to the given delta to obtain an absolute expiry. | ||
*/ | ||
def toCltvExpiry = CltvExpiry(Globals.blockCount.get() + underlying) | ||
|
||
// @formatter:off | ||
def +(other: Int): CltvExpiryDelta = CltvExpiryDelta(underlying + other) | ||
def +(other: CltvExpiryDelta): CltvExpiryDelta = CltvExpiryDelta(underlying + other.underlying) | ||
def compare(other: CltvExpiryDelta): Int = underlying.compareTo(other.underlying) | ||
def toInt: Int = underlying | ||
// @formatter:on | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.