mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-25 15:20:24 +01:00
Refactor handle_funding_signed to wrapper error handling function
This commit is contained in:
parent
6132a8e648
commit
cdbd7ce71d
1 changed files with 27 additions and 22 deletions
|
@ -1511,6 +1511,32 @@ impl ChannelManager {
|
||||||
Ok(funding_msg)
|
Ok(funding_msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn internal_funding_signed(&self, their_node_id: &PublicKey, msg: &msgs::FundingSigned) -> Result<(), MsgHandleErrInternal> {
|
||||||
|
let (funding_txo, user_id, monitor) = {
|
||||||
|
let mut channel_state = self.channel_state.lock().unwrap();
|
||||||
|
match channel_state.by_id.get_mut(&msg.channel_id) {
|
||||||
|
Some(chan) => {
|
||||||
|
if chan.get_their_node_id() != *their_node_id {
|
||||||
|
//TODO: here and below MsgHandleErrInternal, #153 case
|
||||||
|
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!", msg.channel_id));
|
||||||
|
}
|
||||||
|
let chan_monitor = chan.funding_signed(&msg).map_err(|e| MsgHandleErrInternal::from_maybe_close(e))?;
|
||||||
|
(chan.get_funding_txo().unwrap(), chan.get_user_id(), chan_monitor)
|
||||||
|
},
|
||||||
|
None => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel", msg.channel_id))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if let Err(_e) = self.monitor.add_update_monitor(monitor.get_funding_txo().unwrap(), monitor) {
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
|
let mut pending_events = self.pending_events.lock().unwrap();
|
||||||
|
pending_events.push(events::Event::FundingBroadcastSafe {
|
||||||
|
funding_txo: funding_txo,
|
||||||
|
user_channel_id: user_id,
|
||||||
|
});
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn internal_announcement_signatures(&self, their_node_id: &PublicKey, msg: &msgs::AnnouncementSignatures) -> Result<(), MsgHandleErrInternal> {
|
fn internal_announcement_signatures(&self, their_node_id: &PublicKey, msg: &msgs::AnnouncementSignatures) -> Result<(), MsgHandleErrInternal> {
|
||||||
let (chan_announcement, chan_update) = {
|
let (chan_announcement, chan_update) = {
|
||||||
let mut channel_state = self.channel_state.lock().unwrap();
|
let mut channel_state = self.channel_state.lock().unwrap();
|
||||||
|
@ -1725,28 +1751,7 @@ impl ChannelMessageHandler for ChannelManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_funding_signed(&self, their_node_id: &PublicKey, msg: &msgs::FundingSigned) -> Result<(), HandleError> {
|
fn handle_funding_signed(&self, their_node_id: &PublicKey, msg: &msgs::FundingSigned) -> Result<(), HandleError> {
|
||||||
let (funding_txo, user_id, monitor) = {
|
handle_error!(self, self.internal_funding_signed(their_node_id, msg), their_node_id)
|
||||||
let mut channel_state = self.channel_state.lock().unwrap();
|
|
||||||
match channel_state.by_id.get_mut(&msg.channel_id) {
|
|
||||||
Some(chan) => {
|
|
||||||
if chan.get_their_node_id() != *their_node_id {
|
|
||||||
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
|
|
||||||
}
|
|
||||||
let chan_monitor = chan.funding_signed(&msg)?;
|
|
||||||
(chan.get_funding_txo().unwrap(), chan.get_user_id(), chan_monitor)
|
|
||||||
},
|
|
||||||
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if let Err(_e) = self.monitor.add_update_monitor(monitor.get_funding_txo().unwrap(), monitor) {
|
|
||||||
unimplemented!();
|
|
||||||
}
|
|
||||||
let mut pending_events = self.pending_events.lock().unwrap();
|
|
||||||
pending_events.push(events::Event::FundingBroadcastSafe {
|
|
||||||
funding_txo: funding_txo,
|
|
||||||
user_channel_id: user_id,
|
|
||||||
});
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_funding_locked(&self, their_node_id: &PublicKey, msg: &msgs::FundingLocked) -> Result<Option<msgs::AnnouncementSignatures>, HandleError> {
|
fn handle_funding_locked(&self, their_node_id: &PublicKey, msg: &msgs::FundingLocked) -> Result<Option<msgs::AnnouncementSignatures>, HandleError> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue