From 0960ec1ce953af14eb2c0a4e5553a17939b8f29b Mon Sep 17 00:00:00 2001 From: pokkst Date: Sat, 12 Aug 2023 21:38:12 -0500 Subject: [PATCH 1/4] Add store method to RPC (cherry picked from commit 4398fa5300c06032070c17e69c102c81a2ff945e) --- monero-rpc/src/wallet.rs | 1 + swap/src/monero/wallet.rs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/monero-rpc/src/wallet.rs b/monero-rpc/src/wallet.rs index bc78e7a6..061a0d2a 100644 --- a/monero-rpc/src/wallet.rs +++ b/monero-rpc/src/wallet.rs @@ -36,6 +36,7 @@ pub trait MoneroWalletRpc { async fn refresh(&self) -> Refreshed; async fn sweep_all(&self, address: String) -> SweepAll; async fn get_version(&self) -> Version; + async fn store(&self); } #[jsonrpc_client::implement(MoneroWalletRpc)] diff --git a/swap/src/monero/wallet.rs b/swap/src/monero/wallet.rs index 3f548c41..c8110b02 100644 --- a/swap/src/monero/wallet.rs +++ b/swap/src/monero/wallet.rs @@ -69,6 +69,11 @@ impl Wallet { Ok(()) } + pub async fn store(&self) -> Result<()> { + self.inner.lock().await.store().await?; + Ok(()) + } + /// Close the wallet and open (load) another wallet by generating it from /// keys. The generated wallet will remain loaded. pub async fn create_from_and_load( From 6023dc27d218d91a46ddb910642f683bcb94530d Mon Sep 17 00:00:00 2001 From: pokkst Date: Sat, 12 Aug 2023 22:06:08 -0500 Subject: [PATCH 2/4] Refresh and store wallet upon asb startup --- swap/src/bin/asb.rs | 3 ++- swap/src/protocol/alice/swap.rs | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/swap/src/bin/asb.rs b/swap/src/bin/asb.rs index ff3b0e4c..df2e58ff 100644 --- a/swap/src/bin/asb.rs +++ b/swap/src/bin/asb.rs @@ -361,7 +361,8 @@ async fn init_monero_wallet( env_config, ) .await?; - + let _ = wallet.refresh().await?; + let _ = wallet.store().await?; Ok(wallet) } diff --git a/swap/src/protocol/alice/swap.rs b/swap/src/protocol/alice/swap.rs index 941e5a43..28e2c54c 100644 --- a/swap/src/protocol/alice/swap.rs +++ b/swap/src/protocol/alice/swap.rs @@ -45,6 +45,8 @@ where .await?; } + swap.monero_wallet.store().await?; + Ok(current_state) } From e4410bcf440946750a9c7d3cbba667ece68a92ce Mon Sep 17 00:00:00 2001 From: pokkst Date: Sun, 13 Aug 2023 14:31:14 -0500 Subject: [PATCH 3/4] Remove binding --- swap/src/bin/asb.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swap/src/bin/asb.rs b/swap/src/bin/asb.rs index df2e58ff..6865eb10 100644 --- a/swap/src/bin/asb.rs +++ b/swap/src/bin/asb.rs @@ -362,7 +362,7 @@ async fn init_monero_wallet( ) .await?; let _ = wallet.refresh().await?; - let _ = wallet.store().await?; + wallet.store().await?; Ok(wallet) } From d73dd56974926fab851a42e7b069ef5817b5b41d Mon Sep 17 00:00:00 2001 From: pokkst Date: Fri, 29 Sep 2023 11:04:21 -0500 Subject: [PATCH 4/4] Store monero wallet at certain states --- swap/src/protocol/alice/swap.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/swap/src/protocol/alice/swap.rs b/swap/src/protocol/alice/swap.rs index 28e2c54c..8675dda4 100644 --- a/swap/src/protocol/alice/swap.rs +++ b/swap/src/protocol/alice/swap.rs @@ -45,8 +45,6 @@ where .await?; } - swap.monero_wallet.store().await?; - Ok(current_state) } @@ -148,6 +146,8 @@ where ) })?; + monero_wallet.store().await?; + AliceState::XmrLocked { monero_wallet_restore_blockheight, transfer_proof, @@ -354,6 +354,8 @@ where ) .await?; + monero_wallet.store().await?; + AliceState::XmrRefunded } AliceState::BtcPunishable {