Merge pull request #163 from ariard/claim_revoked_htlc_tx
[rust-lightning] / src / util / errors.rs
1 use std::fmt;
2
3 /// Indicates an error on the client's part (usually some variant of attempting to use too-low or
4 /// too-high values)
5 pub enum APIError {
6         /// Indicates the API was wholly misused (see err for more). Cases where these can be returned
7         /// are documented, but generally indicates some precondition of a function was violated.
8         APIMisuseError {err: &'static str},
9         /// Due to a high feerate, we were unable to complete the request.
10         /// For example, this may be returned if the feerate implies we cannot open a channel at the
11         /// requested value, but opening a larger channel would succeed.
12         FeeRateTooHigh {err: String, feerate: u64},
13
14         /// Invalid route or parameters (cltv_delta, fee, pubkey) was specified
15         RouteError {err: &'static str},
16 }
17
18 impl fmt::Debug for APIError {
19         fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20                 match *self {
21                         APIError::APIMisuseError {ref err} => f.write_str(err),
22                         APIError::FeeRateTooHigh {ref err, ref feerate} => write!(f, "{} feerate: {}", err, feerate),
23                         APIError::RouteError {ref err} => f.write_str(err),
24                 }
25         }
26 }