diff --git a/src/commonMain/kotlin/fr/acinq/lightning/channel/InteractiveTx.kt b/src/commonMain/kotlin/fr/acinq/lightning/channel/InteractiveTx.kt index 3b0086c74..5ee837ce2 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/channel/InteractiveTx.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/channel/InteractiveTx.kt @@ -799,15 +799,15 @@ data class InteractiveTxSigningSession( } } - fun receiveTxSigs(channelKeys: KeyManager.ChannelKeys, remoteTxSigs: TxSignatures, currentBlockHeight: Long): InteractiveTxSigningSessionAction { + fun receiveTxSigs(channelKeys: KeyManager.ChannelKeys, remoteTxSigs: TxSignatures, currentBlockHeight: Long): Either { return when (localCommit) { - is Either.Left -> InteractiveTxSigningSessionAction.AbortFundingAttempt(UnexpectedFundingSignatures(fundingParams.channelId)) + is Either.Left -> Either.Left(InteractiveTxSigningSessionAction.AbortFundingAttempt(UnexpectedFundingSignatures(fundingParams.channelId))) is Either.Right -> when (val fullySignedTx = fundingTx.addRemoteSigs(channelKeys, fundingParams, remoteTxSigs)) { - null -> InteractiveTxSigningSessionAction.AbortFundingAttempt(InvalidFundingSignature(fundingParams.channelId, fundingTx.txId)) + null -> Either.Left(InteractiveTxSigningSessionAction.AbortFundingAttempt(InvalidFundingSignature(fundingParams.channelId, fundingTx.txId))) else -> { val fundingStatus = LocalFundingStatus.UnconfirmedFundingTx(fullySignedTx, fundingParams, currentBlockHeight) val commitment = Commitment(fundingTxIndex, fundingParams.remoteFundingPubkey, fundingStatus, RemoteFundingStatus.NotLocked, localCommit.value, remoteCommit, nextRemoteCommit = null) - InteractiveTxSigningSessionAction.SendTxSigs(fundingStatus, commitment, fundingTx.localSigs) + Either.Right(InteractiveTxSigningSessionAction.SendTxSigs(fundingStatus, commitment, fundingTx.localSigs)) } } } diff --git a/src/commonMain/kotlin/fr/acinq/lightning/channel/states/Normal.kt b/src/commonMain/kotlin/fr/acinq/lightning/channel/states/Normal.kt index 739fe3c0d..e29abd09c 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/channel/states/Normal.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/channel/states/Normal.kt @@ -525,13 +525,16 @@ data class Normal( } is TxSignatures -> when (spliceStatus) { is SpliceStatus.WaitingForSigs -> { - when (val action = spliceStatus.session.receiveTxSigs(channelKeys(), cmd.message, currentBlockHeight.toLong())) { - is InteractiveTxSigningSessionAction.AbortFundingAttempt -> { + when (val res = spliceStatus.session.receiveTxSigs(channelKeys(), cmd.message, currentBlockHeight.toLong())) { + is Either.Left -> { + val action: InteractiveTxSigningSessionAction.AbortFundingAttempt = res.value logger.warning { "splice attempt failed: ${action.reason.message}" } Pair(this@Normal.copy(spliceStatus = SpliceStatus.Aborted), listOf(ChannelAction.Message.Send(TxAbort(channelId, action.reason.message)))) } - InteractiveTxSigningSessionAction.WaitForTxSigs -> Pair(this@Normal, listOf()) - is InteractiveTxSigningSessionAction.SendTxSigs -> sendSpliceTxSigs(spliceStatus.origins, action, cmd.message.channelData) + is Either.Right -> { + val action: InteractiveTxSigningSessionAction.SendTxSigs = res.value + sendSpliceTxSigs(spliceStatus.origins, action, cmd.message.channelData) + } } } else -> when (commitments.latest.localFundingStatus) { diff --git a/src/commonMain/kotlin/fr/acinq/lightning/channel/states/WaitForFundingConfirmed.kt b/src/commonMain/kotlin/fr/acinq/lightning/channel/states/WaitForFundingConfirmed.kt index f53af97c7..06e9c8f35 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/channel/states/WaitForFundingConfirmed.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/channel/states/WaitForFundingConfirmed.kt @@ -56,13 +56,16 @@ data class WaitForFundingConfirmed( } is FullySignedSharedTransaction -> when (rbfStatus) { is RbfStatus.WaitingForSigs -> { - when (val action = rbfStatus.session.receiveTxSigs(channelKeys(), cmd.message, currentBlockHeight.toLong())) { - is InteractiveTxSigningSessionAction.AbortFundingAttempt -> { + when (val res = rbfStatus.session.receiveTxSigs(channelKeys(), cmd.message, currentBlockHeight.toLong())) { + is Either.Left -> { + val action: InteractiveTxSigningSessionAction.AbortFundingAttempt = res.value logger.warning { "rbf attempt failed: ${action.reason.message}" } Pair(this@WaitForFundingConfirmed.copy(rbfStatus = RbfStatus.RbfAborted), listOf(ChannelAction.Message.Send(TxAbort(channelId, action.reason.message)))) } - InteractiveTxSigningSessionAction.WaitForTxSigs -> Pair(this@WaitForFundingConfirmed, listOf()) - is InteractiveTxSigningSessionAction.SendTxSigs -> sendRbfTxSigs(action, cmd.message.channelData) + is Either.Right -> { + val action: InteractiveTxSigningSessionAction.SendTxSigs = res.value + sendRbfTxSigs(action, cmd.message.channelData) + } } } else -> { diff --git a/src/commonMain/kotlin/fr/acinq/lightning/channel/states/WaitForFundingSigned.kt b/src/commonMain/kotlin/fr/acinq/lightning/channel/states/WaitForFundingSigned.kt index 8e66a48b1..a1191d3fc 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/channel/states/WaitForFundingSigned.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/channel/states/WaitForFundingSigned.kt @@ -60,10 +60,15 @@ data class WaitForFundingSigned( } } is TxSignatures -> { - when (val action = signingSession.receiveTxSigs(channelParams.localParams.channelKeys(keyManager), cmd.message, currentBlockHeight.toLong())) { - is InteractiveTxSigningSessionAction.AbortFundingAttempt -> handleLocalError(cmd, action.reason) - InteractiveTxSigningSessionAction.WaitForTxSigs -> Pair(this@WaitForFundingSigned, listOf()) - is InteractiveTxSigningSessionAction.SendTxSigs -> sendTxSigs(action, cmd.message.channelData) + when (val res = signingSession.receiveTxSigs(channelParams.localParams.channelKeys(keyManager), cmd.message, currentBlockHeight.toLong())) { + is Either.Left -> { + val action: InteractiveTxSigningSessionAction.AbortFundingAttempt = res.value + handleLocalError(cmd, action.reason) + } + is Either.Right -> { + val action: InteractiveTxSigningSessionAction.SendTxSigs = res.value + sendTxSigs(action, cmd.message.channelData) + } } } is TxInitRbf -> {