From 18bf8f6e413d5f831e0a4ff2a307cbcc74cb7b00 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 6 Dec 2021 14:51:42 +1100 Subject: [PATCH] Sync before withdrawing from the wallet Implying `Sync` as part of withdraw allows us to remove the `Sync` from the startup of the application which avoids an error case in case we cannot find a particular transaction. --- daemon/src/maker.rs | 5 +---- daemon/src/taker.rs | 5 +---- daemon/src/wallet.rs | 4 ++++ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/daemon/src/maker.rs b/daemon/src/maker.rs index fb72c4c..b5bdc0f 100644 --- a/daemon/src/maker.rs +++ b/daemon/src/maker.rs @@ -168,9 +168,6 @@ async fn main() -> Result<()> { .run(); let _wallet_handle = wallet_fut.spawn_with_handle(); - // do this before withdraw to ensure the wallet is synced - let wallet_info = wallet.send(wallet::Sync).await??; - if let Some(Withdraw::Withdraw { amount, address, @@ -204,7 +201,7 @@ async fn main() -> Result<()> { "ddd4636845a90185991826be5a494cde9f4a6947b1727217afedc6292fa4caf7", )?; - let (wallet_feed_sender, wallet_feed_receiver) = watch::channel(Some(wallet_info)); + let (wallet_feed_sender, wallet_feed_receiver) = watch::channel(None); let figment = rocket::Config::figment() .merge(("address", opts.http_address.ip())) diff --git a/daemon/src/taker.rs b/daemon/src/taker.rs index c64cc2e..f77a5f0 100644 --- a/daemon/src/taker.rs +++ b/daemon/src/taker.rs @@ -179,9 +179,6 @@ async fn main() -> Result<()> { .run(); let _wallet_handle = wallet_fut.spawn_with_handle(); - // do this before withdraw to ensure the wallet is synced - let wallet_info = wallet.send(wallet::Sync).await??; - if let Some(Withdraw::Withdraw { amount, address, @@ -204,7 +201,7 @@ async fn main() -> Result<()> { "ddd4636845a90185991826be5a494cde9f4a6947b1727217afedc6292fa4caf7", )?; - let (wallet_feed_sender, wallet_feed_receiver) = watch::channel(Some(wallet_info)); + let (wallet_feed_sender, wallet_feed_receiver) = watch::channel(None); let mut tasks = Tasks::default(); diff --git a/daemon/src/wallet.rs b/daemon/src/wallet.rs index e149490..2fcf36d 100644 --- a/daemon/src/wallet.rs +++ b/daemon/src/wallet.rs @@ -178,6 +178,10 @@ impl Actor { } pub fn handle_withdraw(&mut self, msg: Withdraw) -> Result { + self.wallet + .sync(NoopProgress, None) + .context("Failed to sync wallet")?; + if msg.address.network != self.wallet.network() { bail!( "Address has invalid network. It was {} but the wallet is connected to {}",