@@ -4480,7 +4480,7 @@ where
44804480
44814481 /// Handles the generation of a funding transaction, optionally (for tests) with a function
44824482 /// which checks the correctness of the funding transaction given the associated channel.
4483- fn funding_transaction_generated_intern<FundingOutput: FnMut(&OutboundV1Channel<SP>, &Transaction) -> Result<OutPoint, APIError >>(
4483+ fn funding_transaction_generated_intern<FundingOutput: FnMut(&OutboundV1Channel<SP>, &Transaction) -> Result<OutPoint, &'static str >>(
44844484 &self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, funding_transaction: Transaction, is_batch_funding: bool,
44854485 mut find_funding_output: FundingOutput,
44864486 ) -> Result<(), APIError> {
@@ -4493,26 +4493,38 @@ where
44934493 let funding_txo;
44944494 let (mut chan, msg_opt) = match peer_state.channel_by_id.remove(temporary_channel_id) {
44954495 Some(ChannelPhase::UnfundedOutboundV1(mut chan)) => {
4496- funding_txo = find_funding_output(&chan, &funding_transaction)?;
4496+ macro_rules! close_chan { ($err: expr, $api_err: expr, $chan: expr) => { {
4497+ let counterparty;
4498+ let err = if let ChannelError::Close(msg) = $err {
4499+ let channel_id = $chan.context.channel_id();
4500+ counterparty = chan.context.get_counterparty_node_id();
4501+ let reason = ClosureReason::ProcessingError { err: msg.clone() };
4502+ let shutdown_res = $chan.context.force_shutdown(false, reason);
4503+ MsgHandleErrInternal::from_finish_shutdown(msg, channel_id, shutdown_res, None)
4504+ } else { unreachable!(); };
4505+
4506+ mem::drop(peer_state_lock);
4507+ mem::drop(per_peer_state);
4508+ let _: Result<(), _> = handle_error!(self, Err(err), counterparty);
4509+ Err($api_err)
4510+ } } }
4511+ match find_funding_output(&chan, &funding_transaction) {
4512+ Ok(found_funding_txo) => funding_txo = found_funding_txo,
4513+ Err(err) => {
4514+ let chan_err = ChannelError::Close(err.to_owned());
4515+ let api_err = APIError::APIMisuseError { err: err.to_owned() };
4516+ return close_chan!(chan_err, api_err, chan);
4517+ },
4518+ }
44974519
44984520 let logger = WithChannelContext::from(&self.logger, &chan.context);
4499- let funding_res = chan.get_funding_created(funding_transaction, funding_txo, is_batch_funding, &&logger)
4500- .map_err(|(mut chan, e)| if let ChannelError::Close(msg) = e {
4501- let channel_id = chan.context.channel_id();
4502- let reason = ClosureReason::ProcessingError { err: msg.clone() };
4503- let shutdown_res = chan.context.force_shutdown(false, reason);
4504- (chan, MsgHandleErrInternal::from_finish_shutdown(msg, channel_id, shutdown_res, None))
4505- } else { unreachable!(); });
4521+ let funding_res = chan.get_funding_created(funding_transaction, funding_txo, is_batch_funding, &&logger);
45064522 match funding_res {
45074523 Ok(funding_msg) => (chan, funding_msg),
4508- Err((chan, err)) => {
4509- mem::drop(peer_state_lock);
4510- mem::drop(per_peer_state);
4511- let _: Result<(), _> = handle_error!(self, Err(err), chan.context.get_counterparty_node_id());
4512- return Err(APIError::ChannelUnavailable {
4513- err: "Signer refused to sign the initial commitment transaction".to_owned()
4514- });
4515- },
4524+ Err((mut chan, chan_err)) => {
4525+ let api_err = APIError::ChannelUnavailable { err: "Signer refused to sign the initial commitment transaction".to_owned() };
4526+ return close_chan!(chan_err, api_err, chan);
4527+ }
45164528 }
45174529 },
45184530 Some(phase) => {
@@ -4677,17 +4689,13 @@ where
46774689 for (idx, outp) in tx.output.iter().enumerate() {
46784690 if outp.script_pubkey == expected_spk && outp.value == chan.context.get_value_satoshis() {
46794691 if output_index.is_some() {
4680- return Err(APIError::APIMisuseError {
4681- err: "Multiple outputs matched the expected script and value".to_owned()
4682- });
4692+ return Err("Multiple outputs matched the expected script and value");
46834693 }
46844694 output_index = Some(idx as u16);
46854695 }
46864696 }
46874697 if output_index.is_none() {
4688- return Err(APIError::APIMisuseError {
4689- err: "No output matched the script_pubkey and value in the FundingGenerationReady event".to_owned()
4690- });
4698+ return Err("No output matched the script_pubkey and value in the FundingGenerationReady event");
46914699 }
46924700 let outpoint = OutPoint { txid: tx.txid(), index: output_index.unwrap() };
46934701 if let Some(funding_batch_state) = funding_batch_state.as_mut() {
0 commit comments