mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-24 14:22:35 -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,
|
s_b: monero::Scalar,
|
||||||
v: monero::PrivateViewKey,
|
v: monero::PrivateViewKey,
|
||||||
tx_lock: bitcoin::TxLock,
|
tx_lock: bitcoin::TxLock,
|
||||||
monero_wallet_restore_blockheight: BlockHeight,
|
pub monero_wallet_restore_blockheight: BlockHeight,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State5 {
|
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_b = monero::PrivateKey { scalar: self.s_b };
|
||||||
|
|
||||||
let s = self.s_a + s_b;
|
let s = self.s_a + s_b;
|
||||||
|
|
||||||
// NOTE: This actually generates and opens a new wallet, closing the currently
|
(s, self.v)
|
||||||
// open one.
|
|
||||||
monero_wallet
|
|
||||||
.create_from_and_load(s, self.v, self.monero_wallet_restore_blockheight)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tx_lock_id(&self) -> bitcoin::Txid {
|
pub fn tx_lock_id(&self) -> bitcoin::Txid {
|
||||||
self.tx_lock.txid()
|
self.tx_lock.txid()
|
||||||
}
|
}
|
||||||
|
@ -188,8 +188,13 @@ async fn run_until_internal(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
BobState::BtcRedeemed(state) => {
|
BobState::BtcRedeemed(state) => {
|
||||||
// Bob redeems XMR using revealed s_a
|
let (spend_key, view_key) = state.xmr_keys();
|
||||||
state.claim_xmr(monero_wallet.as_ref()).await?;
|
|
||||||
|
// 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
|
// Ensure that the generated wallet is synced so we have a proper balance
|
||||||
monero_wallet.refresh().await?;
|
monero_wallet.refresh().await?;
|
||||||
|
Loading…
Reference in New Issue
Block a user