@@ -11,6 +11,7 @@ import fr.acinq.lightning.NodeParams
1111import fr.acinq.lightning.PaymentEvents
1212import fr.acinq.lightning.blockchain.fee.FeeratePerByte
1313import fr.acinq.lightning.blockchain.fee.FeeratePerKw
14+ import fr.acinq.lightning.channel.ChannelCloseResponse
1415import fr.acinq.lightning.channel.ChannelCommand
1516import fr.acinq.lightning.channel.ChannelFundingResponse
1617import fr.acinq.lightning.channel.states.*
@@ -453,16 +454,11 @@ class Api(
453454 val channelId = formParameters.getByteVector32(" channelId" )
454455 val scriptPubKey = formParameters.getAddressAndConvertToScript(" address" )
455456 val feerate = FeeratePerKw (FeeratePerByte (formParameters.getLong(" feerateSatByte" ).sat))
456- val res = async {
457- nodeParams.nodeEvents
458- .filterIsInstance<PaymentEvents .PaymentSent >()
459- .map { it.payment }
460- .filterIsInstance<ChannelCloseOutgoingPayment >()
461- .first()
457+ when (val r = peer.mutualClose(channelId, scriptPubKey, feerate)) {
458+ is ChannelCloseResponse .Success -> call.respondText(r.closingTxId.toString())
459+ is ChannelCloseResponse .Failure -> call.respondText(r.toString())
460+ else -> call.respondText(" no channel available" )
462461 }
463- peer.send(WrappedChannelCommand (channelId, ChannelCommand .Close .MutualClose (scriptPubKey, ClosingFeerates (feerate))))
464- val channelClose = res.await()
465- call.respondText(channelClose.txId.toString())
466462 }
467463 }
468464 post(" export" ) {
0 commit comments