From 176b2195e3a5b387b8905c3789260ec015483e9d Mon Sep 17 00:00:00 2001 From: Lucas Soriano del Pino Date: Fri, 16 Oct 2020 10:49:34 +1100 Subject: [PATCH] Make ReceiveTransferProof async and take &mut self --- xmr-btc/src/lib.rs | 7 ++++--- xmr-btc/tests/on_chain.rs | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/xmr-btc/src/lib.rs b/xmr-btc/src/lib.rs index 3d6e80dc..0430b567 100644 --- a/xmr-btc/src/lib.rs +++ b/xmr-btc/src/lib.rs @@ -76,8 +76,9 @@ pub enum Action { } // TODO: This could be moved to the monero module +#[async_trait] pub trait ReceiveTransferProof { - fn receive_transfer_proof(&self) -> monero::TransferProof; + async fn receive_transfer_proof(&mut self) -> monero::TransferProof; } #[async_trait] @@ -90,7 +91,7 @@ pub trait MedianTime { /// This is called post handshake, after all the keys, addresses and most of the /// signatures have been exchanged. pub fn action_generator_bob( - network: &'static N, + network: &'static mut N, monero_ledger: &'static M, bitcoin_ledger: &'static B, // TODO: Replace this with a new, slimmer struct? @@ -150,7 +151,7 @@ where futures::pin_mut!(poll_until_btc_has_expired); // the source of this could be the database, this layer doesn't care - let transfer_proof = network.receive_transfer_proof(); + let transfer_proof = network.receive_transfer_proof().await; let S_b_monero = monero::PublicKey::from_private_key(&monero::PrivateKey::from_scalar( s_b.into_ed25519(), diff --git a/xmr-btc/tests/on_chain.rs b/xmr-btc/tests/on_chain.rs index 20e937b7..a5781189 100644 --- a/xmr-btc/tests/on_chain.rs +++ b/xmr-btc/tests/on_chain.rs @@ -1,6 +1,7 @@ pub mod harness; use anyhow::Result; +use async_trait::async_trait; use genawaiter::GeneratorState; use harness::wallet::{bitcoin, monero}; use xmr_btc::{ @@ -13,14 +14,15 @@ use xmr_btc::{ struct Network; +#[async_trait] impl ReceiveTransferProof for Network { - fn receive_transfer_proof(&self) -> xmr_btc::monero::TransferProof { + async fn receive_transfer_proof(&mut self) -> xmr_btc::monero::TransferProof { todo!("use libp2p") } } async fn swap_as_bob( - network: &'static Network, + network: &'static mut Network, monero_wallet: &'static monero::BobWallet<'static>, bitcoin_wallet: &'static bitcoin::Wallet, state: bob::State2,