@@ -4485,7 +4485,7 @@ where
4485
4485
4486
4486
/// Handles the generation of a funding transaction, optionally (for tests) with a function
4487
4487
/// which checks the correctness of the funding transaction given the associated channel.
4488
- fn funding_transaction_generated_intern<FundingOutput: FnMut(&OutboundV1Channel<SP>, &Transaction) -> Result<OutPoint, APIError >>(
4488
+ fn funding_transaction_generated_intern<FundingOutput: FnMut(&OutboundV1Channel<SP>, &Transaction) -> Result<OutPoint, &'static str >>(
4489
4489
&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, funding_transaction: Transaction, is_batch_funding: bool,
4490
4490
mut find_funding_output: FundingOutput,
4491
4491
) -> Result<(), APIError> {
@@ -4498,26 +4498,38 @@ where
4498
4498
let funding_txo;
4499
4499
let (mut chan, msg_opt) = match peer_state.channel_by_id.remove(temporary_channel_id) {
4500
4500
Some(ChannelPhase::UnfundedOutboundV1(mut chan)) => {
4501
- funding_txo = find_funding_output(&chan, &funding_transaction)?;
4501
+ macro_rules! close_chan { ($err: expr, $api_err: expr, $chan: expr) => { {
4502
+ let counterparty;
4503
+ let err = if let ChannelError::Close(msg) = $err {
4504
+ let channel_id = $chan.context.channel_id();
4505
+ counterparty = chan.context.get_counterparty_node_id();
4506
+ let reason = ClosureReason::ProcessingError { err: msg.clone() };
4507
+ let shutdown_res = $chan.context.force_shutdown(false, reason);
4508
+ MsgHandleErrInternal::from_finish_shutdown(msg, channel_id, shutdown_res, None)
4509
+ } else { unreachable!(); };
4510
+
4511
+ mem::drop(peer_state_lock);
4512
+ mem::drop(per_peer_state);
4513
+ let _: Result<(), _> = handle_error!(self, Err(err), counterparty);
4514
+ Err($api_err)
4515
+ } } }
4516
+ match find_funding_output(&chan, &funding_transaction) {
4517
+ Ok(found_funding_txo) => funding_txo = found_funding_txo,
4518
+ Err(err) => {
4519
+ let chan_err = ChannelError::Close(err.to_owned());
4520
+ let api_err = APIError::APIMisuseError { err: err.to_owned() };
4521
+ return close_chan!(chan_err, api_err, chan);
4522
+ },
4523
+ }
4502
4524
4503
4525
let logger = WithChannelContext::from(&self.logger, &chan.context);
4504
- let funding_res = chan.get_funding_created(funding_transaction, funding_txo, is_batch_funding, &&logger)
4505
- .map_err(|(mut chan, e)| if let ChannelError::Close(msg) = e {
4506
- let channel_id = chan.context.channel_id();
4507
- let reason = ClosureReason::ProcessingError { err: msg.clone() };
4508
- let shutdown_res = chan.context.force_shutdown(false, reason);
4509
- (chan, MsgHandleErrInternal::from_finish_shutdown(msg, channel_id, shutdown_res, None))
4510
- } else { unreachable!(); });
4526
+ let funding_res = chan.get_funding_created(funding_transaction, funding_txo, is_batch_funding, &&logger);
4511
4527
match funding_res {
4512
4528
Ok(funding_msg) => (chan, funding_msg),
4513
- Err((chan, err)) => {
4514
- mem::drop(peer_state_lock);
4515
- mem::drop(per_peer_state);
4516
- let _: Result<(), _> = handle_error!(self, Err(err), chan.context.get_counterparty_node_id());
4517
- return Err(APIError::ChannelUnavailable {
4518
- err: "Signer refused to sign the initial commitment transaction".to_owned()
4519
- });
4520
- },
4529
+ Err((mut chan, chan_err)) => {
4530
+ let api_err = APIError::ChannelUnavailable { err: "Signer refused to sign the initial commitment transaction".to_owned() };
4531
+ return close_chan!(chan_err, api_err, chan);
4532
+ }
4521
4533
}
4522
4534
},
4523
4535
Some(phase) => {
@@ -4682,17 +4694,14 @@ where
4682
4694
for (idx, outp) in tx.output.iter().enumerate() {
4683
4695
if outp.script_pubkey == expected_spk && outp.value == chan.context.get_value_satoshis() {
4684
4696
if output_index.is_some() {
4685
- return Err(APIError::APIMisuseError {
4686
- err: "Multiple outputs matched the expected script and value".to_owned()
4687
- });
4697
+ return Err("Multiple outputs matched the expected script and value");
4688
4698
}
4689
4699
output_index = Some(idx as u16);
4690
4700
}
4691
4701
}
4692
4702
if output_index.is_none() {
4693
- return Err(APIError::APIMisuseError {
4694
- err: "No output matched the script_pubkey and value in the FundingGenerationReady event".to_owned()
4695
- });
4703
+ eprintln!("FAILING HERE, setting result");
4704
+ return Err("No output matched the script_pubkey and value in the FundingGenerationReady event");
4696
4705
}
4697
4706
let outpoint = OutPoint { txid: tx.txid(), index: output_index.unwrap() };
4698
4707
if let Some(funding_batch_state) = funding_batch_state.as_mut() {
0 commit comments