File tree Expand file tree Collapse file tree 1 file changed +21
-4
lines changed
app/src/main/java/to/bitkit/ext Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -3,9 +3,26 @@ package to.bitkit.ext
33import com.synonym.bitkitcore.LnurlPayData
44import com.synonym.bitkitcore.LnurlWithdrawData
55
6+ private const val MSATS_PER_SAT : ULong = 1000u
7+
8+ /* *
9+ * LNURL amounts are expressed in millisatoshis (msat).
10+ *
11+ * When converting a minimum bound to whole sats we must round up:
12+ * `minSendable = 100500 msat` means the minimum payable amount is `101 sat` (not `100 sat`).
13+ */
14+ private fun msatsToSatsCeil (msats : ULong ): ULong {
15+ val quotient = msats / MSATS_PER_SAT
16+ val remainder = msats % MSATS_PER_SAT
17+ return when (remainder) {
18+ 0uL -> quotient
19+ else -> quotient + 1uL
20+ }
21+ }
22+
623fun LnurlPayData.commentAllowed (): Boolean = commentAllowed?.let { it > 0u } == true
7- fun LnurlPayData.maxSendableSat (): ULong = maxSendable / 1000u
8- fun LnurlPayData.minSendableSat (): ULong = minSendable / 1000u
24+ fun LnurlPayData.maxSendableSat (): ULong = maxSendable / MSATS_PER_SAT
25+ fun LnurlPayData.minSendableSat (): ULong = msatsToSatsCeil( minSendable)
926
10- fun LnurlWithdrawData.minWithdrawableSat (): ULong = (minWithdrawable ? : 0u ) / 1000u
11- fun LnurlWithdrawData.maxWithdrawableSat (): ULong = maxWithdrawable / 1000u
27+ fun LnurlWithdrawData.minWithdrawableSat (): ULong = msatsToSatsCeil (minWithdrawable ? : 0u )
28+ fun LnurlWithdrawData.maxWithdrawableSat (): ULong = maxWithdrawable / MSATS_PER_SAT
You can’t perform that action at this time.
0 commit comments