Merge pull request #113 from comit-network/clippy

This commit is contained in:
Franck Royer 2021-01-04 10:10:19 +11:00 committed by GitHub
commit dd10e68db4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 423 additions and 366 deletions

View file

@ -376,11 +376,10 @@ pub async fn next_state<
state6.redeem_btc(bitcoin_wallet).await?;
Ok(state6.into())
}
State::State6(state6) => Ok(state6.into()),
State::State6(state6) => Ok((*state6).into()),
}
}
#[allow(clippy::large_enum_variant)]
#[derive(Debug, Deserialize, Serialize)]
pub enum State {
State0(State0),
@ -389,7 +388,7 @@ pub enum State {
State3(State3),
State4(State4),
State5(State5),
State6(State6),
State6(Box<State6>),
}
impl_try_from_parent_enum!(State0, State);
@ -398,7 +397,7 @@ impl_try_from_parent_enum!(State2, State);
impl_try_from_parent_enum!(State3, State);
impl_try_from_parent_enum!(State4, State);
impl_try_from_parent_enum!(State5, State);
impl_try_from_parent_enum!(State6, State);
impl_try_from_parent_enum_for_boxed!(State6, State);
impl_from_child_enum!(State0, State);
impl_from_child_enum!(State1, State);
@ -406,7 +405,7 @@ impl_from_child_enum!(State2, State);
impl_from_child_enum!(State3, State);
impl_from_child_enum!(State4, State);
impl_from_child_enum!(State5, State);
impl_from_child_enum!(State6, State);
impl_from_child_enum_for_boxed!(State6, State);
impl State {
pub fn new<R: RngCore + CryptoRng>(

View file

@ -50,6 +50,8 @@ impl TxLock {
}
pub fn as_outpoint(&self) -> OutPoint {
// This is fine because a transaction that has that many outputs is not
// realistic
#[allow(clippy::cast_possible_truncation)]
OutPoint::new(self.inner.txid(), self.lock_output_vout() as u32)
}

View file

@ -43,7 +43,6 @@ use crate::{
use ::bitcoin::{Transaction, Txid};
pub use message::{Message, Message0, Message1, Message2, Message3};
#[allow(clippy::large_enum_variant)]
#[derive(Debug)]
pub enum Action {
LockBtc(bitcoin::TxLock),

View file

@ -41,6 +41,24 @@ mod utils {
};
}
macro_rules! impl_try_from_parent_enum_for_boxed {
($type:ident, $parent:ident) => {
impl TryFrom<$parent> for $type {
type Error = anyhow::Error;
fn try_from(from: $parent) -> Result<Self> {
if let $parent::$type(inner) = from {
Ok(*inner)
} else {
Err(anyhow::anyhow!(
"Failed to convert parent state to child state"
))
}
}
}
};
}
macro_rules! impl_from_child_enum {
($type:ident, $parent:ident) => {
impl From<$type> for $parent {
@ -50,6 +68,16 @@ mod utils {
}
};
}
macro_rules! impl_from_child_enum_for_boxed {
($type:ident, $parent:ident) => {
impl From<$type> for $parent {
fn from(from: $type) -> Self {
$parent::$type(Box::new(from))
}
}
};
}
}
pub mod alice;