Split SendReceive into seperate traits

This commit is contained in:
rishflab 2020-10-08 17:00:31 +11:00
parent 6b7193b974
commit 154b3edcf9
4 changed files with 21 additions and 8 deletions

View File

@ -3,7 +3,7 @@ use crate::{
bitcoin::{BroadcastSignedTransaction, WatchForRawTransaction},
bob, monero,
monero::{CreateWalletForOutput, Transfer},
transport::SendReceive,
transport::{Receive, Send},
};
use anyhow::{anyhow, Result};
use ecdsa_fun::{
@ -21,7 +21,7 @@ pub async fn next_state<
R: RngCore + CryptoRng,
B: WatchForRawTransaction + BroadcastSignedTransaction,
M: CreateWalletForOutput + Transfer,
T: SendReceive<Message, bob::Message>,
T: Send<Message> + Receive<bob::Message>,
>(
bitcoin_wallet: &B,
monero_wallet: &M,

View File

@ -6,7 +6,7 @@ use crate::{
},
monero,
monero::{CheckTransfer, CreateWalletForOutput},
transport::SendReceive,
transport::{Receive, Send},
};
use anyhow::{anyhow, Result};
use ecdsa_fun::{
@ -25,7 +25,7 @@ pub async fn next_state<
R: RngCore + CryptoRng,
B: WatchForRawTransaction + SignTxLock + BuildTxLockPsbt + BroadcastSignedTransaction,
M: CreateWalletForOutput + CheckTransfer,
T: SendReceive<Message, alice::Message>,
T: Send<Message> + Receive<alice::Message>,
>(
bitcoin_wallet: &B,
monero_wallet: &M,

View File

@ -2,7 +2,11 @@ use anyhow::Result;
use async_trait::async_trait;
#[async_trait]
pub trait SendReceive<SendMsg, RecvMsg> {
pub trait Send<SendMsg> {
async fn send_message(&mut self, message: SendMsg) -> Result<()>;
}
#[async_trait]
pub trait Receive<RecvMsg> {
async fn receive_message(&mut self) -> Result<RecvMsg>;
}

View File

@ -4,7 +4,10 @@ use tokio::{
stream::StreamExt,
sync::mpsc::{Receiver, Sender},
};
use xmr_btc::{alice, bob, transport::SendReceive};
use xmr_btc::{
alice, bob,
transport::{Receive, Send},
};
#[derive(Debug)]
pub struct Transport<SendMsg, RecvMsg> {
@ -13,7 +16,7 @@ pub struct Transport<SendMsg, RecvMsg> {
}
#[async_trait]
impl SendReceive<alice::Message, bob::Message> for Transport<alice::Message, bob::Message> {
impl Send<alice::Message> for Transport<alice::Message, bob::Message> {
async fn send_message(&mut self, message: alice::Message) -> Result<()> {
let _ = self
.sender
@ -22,7 +25,10 @@ impl SendReceive<alice::Message, bob::Message> for Transport<alice::Message, bob
.map_err(|_| anyhow!("failed to send message"))?;
Ok(())
}
}
#[async_trait]
impl Receive<bob::Message> for Transport<alice::Message, bob::Message> {
async fn receive_message(&mut self) -> Result<bob::Message> {
let message = self
.receiver
@ -34,7 +40,7 @@ impl SendReceive<alice::Message, bob::Message> for Transport<alice::Message, bob
}
#[async_trait]
impl SendReceive<bob::Message, alice::Message> for Transport<bob::Message, alice::Message> {
impl Send<bob::Message> for Transport<bob::Message, alice::Message> {
async fn send_message(&mut self, message: bob::Message) -> Result<()> {
let _ = self
.sender
@ -43,7 +49,10 @@ impl SendReceive<bob::Message, alice::Message> for Transport<bob::Message, alice
.map_err(|_| anyhow!("failed to send message"))?;
Ok(())
}
}
#[async_trait]
impl Receive<alice::Message> for Transport<bob::Message, alice::Message> {
async fn receive_message(&mut self) -> Result<alice::Message> {
let message = self
.receiver