All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.fr.acinq.lightning.utils.satoshis.kt Maven / Gradle / Ivy

There is a newer version: 1.8.4
Show newest version
package fr.acinq.lightning.utils

import fr.acinq.bitcoin.Satoshi
import fr.acinq.lightning.MilliSatoshi


// sumByLong does not exist :(
fun Iterable.sum(): Satoshi {
    var sum: Long = 0
    for (element in this) {
        sum += element.sat
    }
    return Satoshi(sum)
}

fun Iterable.sum(): MilliSatoshi {
    var sum: Long = 0
    for (element in this) {
        sum += element.msat
    }
    return MilliSatoshi(sum)
}

fun Satoshi.toMilliSatoshi() = MilliSatoshi(sat * 1_000L)

operator fun MilliSatoshi.compareTo(other: Satoshi) = toLong().compareTo(other.toLong() * 1_000L)

private const val Coin = 100_000_000L
private const val MCoin = Coin / 1_000L

val Long.btc get() = Satoshi(this * Coin)
val Int.btc get() = toLong().btc
val Long.mbtc get() = Satoshi(this * MCoin)
val Int.mbtc get() = toLong().mbtc
val Long.sat get() = Satoshi(this)
val Int.sat get() = toLong().sat
val Long.msat get() = MilliSatoshi(this)
val Int.msat get() = toLong().msat




© 2015 - 2024 Weber Informatics LLC | Privacy Policy