+ fn internal_funding_created(&self, their_node_id: &PublicKey, msg: &msgs::FundingCreated) -> Result<msgs::FundingSigned, MsgHandleErrInternal> {
+ let (chan, funding_msg, monitor_update) = {
+ let mut channel_state = self.channel_state.lock().unwrap();
+ match channel_state.by_id.entry(msg.temporary_channel_id.clone()) {
+ hash_map::Entry::Occupied(mut chan) => {
+ if chan.get().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.temporary_channel_id));
+ }
+ match chan.get_mut().funding_created(msg) {
+ Ok((funding_msg, monitor_update)) => {
+ (chan.remove(), funding_msg, monitor_update)
+ },
+ Err(e) => {
+ return Err(e).map_err(|e| MsgHandleErrInternal::from_maybe_close(e))
+ }
+ }
+ },
+ hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel", msg.temporary_channel_id))
+ }
+ }; // Release channel lock for install_watch_outpoint call,
+ // note that this means if the remote end is misbehaving and sends a message for the same
+ // channel back-to-back with funding_created, we'll end up thinking they sent a message
+ // for a bogus channel.
+ if let Err(_e) = self.monitor.add_update_monitor(monitor_update.get_funding_txo().unwrap(), monitor_update) {
+ unimplemented!();
+ }
+ let mut channel_state = self.channel_state.lock().unwrap();
+ match channel_state.by_id.entry(funding_msg.channel_id) {
+ hash_map::Entry::Occupied(_) => {
+ return Err(MsgHandleErrInternal::send_err_msg_no_close("Already had channel with the new channel_id", funding_msg.channel_id))
+ },
+ hash_map::Entry::Vacant(e) => {
+ e.insert(chan);
+ }
+ }
+ Ok(funding_msg)
+ }
+