mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-23 22:01:21 -05:00
De-couple state from Monero wallet
This commit is contained in:
parent
42b6368298
commit
fc175a3f53
@ -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()
|
||||
}
|
||||
|
@ -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?;
|
||||
|
Loading…
Reference in New Issue
Block a user