@@ -16,9 +16,13 @@ import org.lightningdevkit.ldknode.PaymentDetails
1616import org.lightningdevkit.ldknode.PaymentId
1717import org.lightningdevkit.ldknode.Txid
1818import org.lightningdevkit.ldknode.UserChannelId
19+ import to.bitkit.data.SettingsStore
1920import to.bitkit.di.BgDispatcher
21+ import to.bitkit.ext.getSatsPerVByteFor
2022import to.bitkit.models.LnPeer
2123import to.bitkit.models.NodeLifecycleState
24+ import to.bitkit.models.TransactionSpeed
25+ import to.bitkit.services.CoreService
2226import to.bitkit.services.LdkNodeEventBus
2327import to.bitkit.services.LightningService
2428import to.bitkit.services.NodeEventHandler
@@ -34,7 +38,9 @@ class LightningRepo @Inject constructor(
3438 @BgDispatcher private val bgDispatcher : CoroutineDispatcher ,
3539 private val lightningService : LightningService ,
3640 private val ldkNodeEventBus : LdkNodeEventBus ,
37- private val addressChecker : AddressChecker
41+ private val addressChecker : AddressChecker ,
42+ private val settingsStore : SettingsStore ,
43+ private val coreService : CoreService ,
3844) {
3945 private val _nodeLifecycleState : MutableStateFlow <NodeLifecycleState > = MutableStateFlow (NodeLifecycleState .Stopped )
4046 val nodeLifecycleState = _nodeLifecycleState .asStateFlow()
@@ -221,9 +227,23 @@ class LightningRepo @Inject constructor(
221227 Result .success(paymentId)
222228 }
223229
224- suspend fun sendOnChain (address : Address , sats : ULong ): Result <Txid > =
230+ /* *
231+ * Sends bitcoin to an on-chain address
232+ *
233+ * @param address The bitcoin address to send to
234+ * @param sats The amount in satoshis to send
235+ * @param speed The desired transaction speed determining the fee rate. If null, the user's default speed is used.
236+ * @return A `Result` with the `Txid` of sent transaction, or an error if the transaction fails
237+ * or the fee rate cannot be retrieved.
238+ */
239+ suspend fun sendOnChain (address : Address , sats : ULong , speed : TransactionSpeed ? = null): Result <Txid > =
225240 executeWhenNodeRunning(" Send on-chain" ) {
226- val txId = lightningService.send(address = address, sats = sats)
241+ val transactionSpeed = speed ? : settingsStore.defaultTransactionSpeed.first()
242+
243+ var fees = coreService.blocktank.getFees().getOrThrow()
244+ var satsPerVByte = fees.getSatsPerVByteFor(transactionSpeed)
245+
246+ val txId = lightningService.send(address = address, sats = sats, satsPerVByte = satsPerVByte)
227247 Result .success(txId)
228248 }
229249
0 commit comments