mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-05 04:54:36 -04:00
Merge pull request #113 from comit-network/clippy
This commit is contained in:
commit
dd10e68db4
30 changed files with 423 additions and 366 deletions
|
@ -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>(
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue