]> git.bitcoin.ninja Git - rust-lightning/commitdiff
raise APIError from close_channel
authorYuntai Kyong <yuntai.kyong@gmail.com>
Tue, 25 Sep 2018 15:32:30 +0000 (00:32 +0900)
committerYuntai Kyong <yuntai.kyong@gmail.com>
Tue, 2 Oct 2018 23:36:39 +0000 (08:36 +0900)
src/ln/channel.rs
src/ln/channelmanager.rs

index 19c80f81e4d4494f98d2d79a4f20b7922e154c4e..1e28c6f463f3a348b198cd911efabc1ab87d5c82 100644 (file)
@@ -2879,18 +2879,18 @@ impl Channel {
 
        /// Begins the shutdown process, getting a message for the remote peer and returning all
        /// holding cell HTLCs for payment failure.
-       pub fn get_shutdown(&mut self) -> Result<(msgs::Shutdown, Vec<(HTLCSource, [u8; 32])>), HandleError> {
+       pub fn get_shutdown(&mut self) -> Result<(msgs::Shutdown, Vec<(HTLCSource, [u8; 32])>), APIError> {
                for htlc in self.pending_outbound_htlcs.iter() {
                        if htlc.state == OutboundHTLCState::LocalAnnounced {
-                               return Err(HandleError{err: "Cannot begin shutdown with pending HTLCs, call send_commitment first", action: None});
+                               return Err(APIError::APIMisuseError{err: "Cannot begin shutdown with pending HTLCs. Process pending events first"});
                        }
                }
                if self.channel_state & BOTH_SIDES_SHUTDOWN_MASK != 0 {
-                       return Err(HandleError{err: "Shutdown already in progress", action: None});
+                       return Err(APIError::APIMisuseError{err: "Shutdown already in progress"});
                }
                assert_eq!(self.channel_state & ChannelState::ShutdownComplete as u32, 0);
                if self.channel_state & (ChannelState::PeerDisconnected as u32) == ChannelState::PeerDisconnected as u32 {
-                       return Err(HandleError{err: "Cannot begin shutdown while peer is disconnected, maybe force-close instead?", action: None});
+                       return Err(APIError::APIMisuseError{err: "Cannot begin shutdown while peer is disconnected, maybe force-close instead?"});
                }
 
                let our_closing_script = self.get_closing_scriptpubkey();
index 42dcc6c77016fabac9e39ef8bad09a6c490194fb..50c1c0fa9d774139a2914138159d5f83ede315fd 100644 (file)
@@ -467,7 +467,7 @@ impl ChannelManager {
        /// pending HTLCs, the channel will be closed on chain.
        ///
        /// May generate a SendShutdown event on success, which should be relayed.
-       pub fn close_channel(&self, channel_id: &[u8; 32]) -> Result<(), HandleError> {
+       pub fn close_channel(&self, channel_id: &[u8; 32]) -> Result<(), APIError> {
                let (mut res, node_id, chan_option) = {
                        let mut channel_state_lock = self.channel_state.lock().unwrap();
                        let channel_state = channel_state_lock.borrow_parts();
@@ -481,7 +481,7 @@ impl ChannelManager {
                                                (res, chan_entry.get().get_their_node_id(), Some(chan_entry.remove_entry().1))
                                        } else { (res, chan_entry.get().get_their_node_id(), None) }
                                },
-                               hash_map::Entry::Vacant(_) => return Err(HandleError{err: "No such channel", action: None})
+                               hash_map::Entry::Vacant(_) => return Err(APIError::APIMisuseError{err: "No such channel"})
                        }
                };
                for htlc_source in res.1.drain(..) {