From fc175a3f53732d4087c0fadae55c37840f1dd746 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 29 Mar 2021 12:08:12 +1100 Subject: [PATCH] De-couple state from Monero wallet --- swap/src/protocol/bob/state.rs | 14 ++++---------- swap/src/protocol/bob/swap.rs | 9 +++++++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/swap/src/protocol/bob/state.rs b/swap/src/protocol/bob/state.rs index 6a7c8d95..1ccfc476 100644 --- a/swap/src/protocol/bob/state.rs +++ b/swap/src/protocol/bob/state.rs @@ -485,23 +485,17 @@ pub struct State5 { s_b: monero::Scalar, v: monero::PrivateViewKey, tx_lock: bitcoin::TxLock, - monero_wallet_restore_blockheight: BlockHeight, + pub monero_wallet_restore_blockheight: BlockHeight, } impl State5 { - pub async fn claim_xmr(&self, monero_wallet: &monero::Wallet) -> Result<()> { + pub fn xmr_keys(&self) -> (monero::PrivateKey, monero::PrivateViewKey) { let s_b = monero::PrivateKey { scalar: self.s_b }; - let s = self.s_a + s_b; - // NOTE: This actually generates and opens a new wallet, closing the currently - // open one. - monero_wallet - .create_from_and_load(s, self.v, self.monero_wallet_restore_blockheight) - .await?; - - Ok(()) + (s, self.v) } + pub fn tx_lock_id(&self) -> bitcoin::Txid { self.tx_lock.txid() } diff --git a/swap/src/protocol/bob/swap.rs b/swap/src/protocol/bob/swap.rs index cb264750..0241c703 100644 --- a/swap/src/protocol/bob/swap.rs +++ b/swap/src/protocol/bob/swap.rs @@ -188,8 +188,13 @@ async fn run_until_internal( } } BobState::BtcRedeemed(state) => { - // Bob redeems XMR using revealed s_a - state.claim_xmr(monero_wallet.as_ref()).await?; + let (spend_key, view_key) = state.xmr_keys(); + + // NOTE: This actually generates and opens a new wallet, closing the currently + // open one. + monero_wallet + .create_from_and_load(spend_key, view_key, state.monero_wallet_restore_blockheight) + .await?; // Ensure that the generated wallet is synced so we have a proper balance monero_wallet.refresh().await?;