mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Remember monero wallet-height for Alice's refund scenario
This commit is contained in:
parent
fa04775188
commit
684cbe4d0b
@ -268,14 +268,8 @@ impl Client {
|
|||||||
address: &str,
|
address: &str,
|
||||||
spend_key: &str,
|
spend_key: &str,
|
||||||
view_key: &str,
|
view_key: &str,
|
||||||
restore_height: Option<u32>,
|
restore_height: u32,
|
||||||
) -> Result<GenerateFromKeys> {
|
) -> Result<GenerateFromKeys> {
|
||||||
let restore_height = if let Some(restore_height) = restore_height {
|
|
||||||
restore_height
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
let params = GenerateFromKeysParams {
|
let params = GenerateFromKeysParams {
|
||||||
restore_height,
|
restore_height,
|
||||||
filename: view_key.into(),
|
filename: view_key.into(),
|
||||||
|
@ -6,6 +6,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use ::bitcoin::hashes::core::fmt::Display;
|
use ::bitcoin::hashes::core::fmt::Display;
|
||||||
use libp2p::PeerId;
|
use libp2p::PeerId;
|
||||||
|
use monero_rpc::wallet::BlockHeight;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
// Large enum variant is fine because this is only used for database
|
// Large enum variant is fine because this is only used for database
|
||||||
@ -23,15 +24,29 @@ pub enum Alice {
|
|||||||
#[serde(with = "crate::serde_peer_id")]
|
#[serde(with = "crate::serde_peer_id")]
|
||||||
bob_peer_id: PeerId,
|
bob_peer_id: PeerId,
|
||||||
},
|
},
|
||||||
XmrLocked(alice::State3),
|
XmrLocked {
|
||||||
|
monero_wallet_restore_blockheight: BlockHeight,
|
||||||
|
state3: alice::State3,
|
||||||
|
},
|
||||||
EncSigLearned {
|
EncSigLearned {
|
||||||
|
monero_wallet_restore_blockheight: BlockHeight,
|
||||||
encrypted_signature: EncryptedSignature,
|
encrypted_signature: EncryptedSignature,
|
||||||
state3: alice::State3,
|
state3: alice::State3,
|
||||||
},
|
},
|
||||||
CancelTimelockExpired(alice::State3),
|
CancelTimelockExpired {
|
||||||
BtcCancelled(alice::State3),
|
monero_wallet_restore_blockheight: BlockHeight,
|
||||||
BtcPunishable(alice::State3),
|
state3: alice::State3,
|
||||||
|
},
|
||||||
|
BtcCancelled {
|
||||||
|
monero_wallet_restore_blockheight: BlockHeight,
|
||||||
|
state3: alice::State3,
|
||||||
|
},
|
||||||
|
BtcPunishable {
|
||||||
|
monero_wallet_restore_blockheight: BlockHeight,
|
||||||
|
state3: alice::State3,
|
||||||
|
},
|
||||||
BtcRefunded {
|
BtcRefunded {
|
||||||
|
monero_wallet_restore_blockheight: BlockHeight,
|
||||||
state3: alice::State3,
|
state3: alice::State3,
|
||||||
#[serde(with = "monero_private_key")]
|
#[serde(with = "monero_private_key")]
|
||||||
spend_key: monero::PrivateKey,
|
spend_key: monero::PrivateKey,
|
||||||
@ -53,7 +68,6 @@ impl From<&AliceState> for Alice {
|
|||||||
AliceState::Started {
|
AliceState::Started {
|
||||||
state3,
|
state3,
|
||||||
bob_peer_id,
|
bob_peer_id,
|
||||||
..
|
|
||||||
} => Alice::Started {
|
} => Alice::Started {
|
||||||
state3: state3.as_ref().clone(),
|
state3: state3.as_ref().clone(),
|
||||||
bob_peer_id: *bob_peer_id,
|
bob_peer_id: *bob_peer_id,
|
||||||
@ -61,32 +75,60 @@ impl From<&AliceState> for Alice {
|
|||||||
AliceState::BtcLocked {
|
AliceState::BtcLocked {
|
||||||
state3,
|
state3,
|
||||||
bob_peer_id,
|
bob_peer_id,
|
||||||
..
|
|
||||||
} => Alice::BtcLocked {
|
} => Alice::BtcLocked {
|
||||||
state3: state3.as_ref().clone(),
|
state3: state3.as_ref().clone(),
|
||||||
bob_peer_id: *bob_peer_id,
|
bob_peer_id: *bob_peer_id,
|
||||||
},
|
},
|
||||||
AliceState::XmrLocked { state3 } => Alice::XmrLocked(state3.as_ref().clone()),
|
AliceState::XmrLocked {
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
state3,
|
||||||
|
} => Alice::XmrLocked {
|
||||||
|
monero_wallet_restore_blockheight: *monero_wallet_restore_blockheight,
|
||||||
|
state3: state3.as_ref().clone(),
|
||||||
|
},
|
||||||
AliceState::EncSigLearned {
|
AliceState::EncSigLearned {
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
state3,
|
state3,
|
||||||
encrypted_signature,
|
encrypted_signature,
|
||||||
} => Alice::EncSigLearned {
|
} => Alice::EncSigLearned {
|
||||||
|
monero_wallet_restore_blockheight: *monero_wallet_restore_blockheight,
|
||||||
state3: state3.as_ref().clone(),
|
state3: state3.as_ref().clone(),
|
||||||
encrypted_signature: *encrypted_signature.clone(),
|
encrypted_signature: *encrypted_signature.clone(),
|
||||||
},
|
},
|
||||||
AliceState::BtcRedeemed => Alice::Done(AliceEndState::BtcRedeemed),
|
AliceState::BtcRedeemed => Alice::Done(AliceEndState::BtcRedeemed),
|
||||||
AliceState::BtcCancelled { state3, .. } => Alice::BtcCancelled(state3.as_ref().clone()),
|
AliceState::BtcCancelled {
|
||||||
AliceState::BtcRefunded { spend_key, state3 } => Alice::BtcRefunded {
|
monero_wallet_restore_blockheight,
|
||||||
|
state3,
|
||||||
|
..
|
||||||
|
} => Alice::BtcCancelled {
|
||||||
|
monero_wallet_restore_blockheight: *monero_wallet_restore_blockheight,
|
||||||
|
state3: state3.as_ref().clone(),
|
||||||
|
},
|
||||||
|
AliceState::BtcRefunded {
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
spend_key,
|
||||||
|
state3,
|
||||||
|
} => Alice::BtcRefunded {
|
||||||
|
monero_wallet_restore_blockheight: *monero_wallet_restore_blockheight,
|
||||||
spend_key: *spend_key,
|
spend_key: *spend_key,
|
||||||
state3: state3.as_ref().clone(),
|
state3: state3.as_ref().clone(),
|
||||||
},
|
},
|
||||||
AliceState::BtcPunishable { state3, .. } => {
|
AliceState::BtcPunishable {
|
||||||
Alice::BtcPunishable(state3.as_ref().clone())
|
monero_wallet_restore_blockheight,
|
||||||
}
|
state3,
|
||||||
|
..
|
||||||
|
} => Alice::BtcPunishable {
|
||||||
|
monero_wallet_restore_blockheight: *monero_wallet_restore_blockheight,
|
||||||
|
state3: state3.as_ref().clone(),
|
||||||
|
},
|
||||||
AliceState::XmrRefunded => Alice::Done(AliceEndState::XmrRefunded),
|
AliceState::XmrRefunded => Alice::Done(AliceEndState::XmrRefunded),
|
||||||
AliceState::CancelTimelockExpired { state3 } => {
|
AliceState::CancelTimelockExpired {
|
||||||
Alice::CancelTimelockExpired(state3.as_ref().clone())
|
monero_wallet_restore_blockheight,
|
||||||
}
|
state3,
|
||||||
|
} => Alice::CancelTimelockExpired {
|
||||||
|
monero_wallet_restore_blockheight: *monero_wallet_restore_blockheight,
|
||||||
|
state3: state3.as_ref().clone(),
|
||||||
|
},
|
||||||
AliceState::BtcPunished => Alice::Done(AliceEndState::BtcPunished),
|
AliceState::BtcPunished => Alice::Done(AliceEndState::BtcPunished),
|
||||||
AliceState::SafelyAborted => Alice::Done(AliceEndState::SafelyAborted),
|
AliceState::SafelyAborted => Alice::Done(AliceEndState::SafelyAborted),
|
||||||
}
|
}
|
||||||
@ -110,33 +152,50 @@ impl From<Alice> for AliceState {
|
|||||||
bob_peer_id,
|
bob_peer_id,
|
||||||
state3: Box::new(state3),
|
state3: Box::new(state3),
|
||||||
},
|
},
|
||||||
Alice::XmrLocked(state3) => AliceState::XmrLocked {
|
Alice::XmrLocked {
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
state3,
|
||||||
|
} => AliceState::XmrLocked {
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
state3: Box::new(state3),
|
state3: Box::new(state3),
|
||||||
},
|
},
|
||||||
Alice::EncSigLearned {
|
Alice::EncSigLearned {
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
state3: state,
|
state3: state,
|
||||||
encrypted_signature,
|
encrypted_signature,
|
||||||
} => AliceState::EncSigLearned {
|
} => AliceState::EncSigLearned {
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
state3: Box::new(state),
|
state3: Box::new(state),
|
||||||
encrypted_signature: Box::new(encrypted_signature),
|
encrypted_signature: Box::new(encrypted_signature),
|
||||||
},
|
},
|
||||||
Alice::CancelTimelockExpired(state3) => AliceState::CancelTimelockExpired {
|
Alice::CancelTimelockExpired {
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
state3,
|
||||||
|
} => AliceState::CancelTimelockExpired {
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
state3: Box::new(state3),
|
state3: Box::new(state3),
|
||||||
},
|
},
|
||||||
Alice::BtcCancelled(state) => {
|
Alice::BtcCancelled {
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
state3,
|
||||||
|
} => {
|
||||||
let tx_cancel = TxCancel::new(
|
let tx_cancel = TxCancel::new(
|
||||||
&state.tx_lock,
|
&state3.tx_lock,
|
||||||
state.cancel_timelock,
|
state3.cancel_timelock,
|
||||||
state.a.public(),
|
state3.a.public(),
|
||||||
state.B,
|
state3.B,
|
||||||
);
|
);
|
||||||
|
|
||||||
AliceState::BtcCancelled {
|
AliceState::BtcCancelled {
|
||||||
state3: Box::new(state),
|
monero_wallet_restore_blockheight,
|
||||||
|
state3: Box::new(state3),
|
||||||
tx_cancel: Box::new(tx_cancel),
|
tx_cancel: Box::new(tx_cancel),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Alice::BtcPunishable(state3) => {
|
Alice::BtcPunishable {
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
state3,
|
||||||
|
} => {
|
||||||
let tx_cancel = TxCancel::new(
|
let tx_cancel = TxCancel::new(
|
||||||
&state3.tx_lock,
|
&state3.tx_lock,
|
||||||
state3.cancel_timelock,
|
state3.cancel_timelock,
|
||||||
@ -145,13 +204,17 @@ impl From<Alice> for AliceState {
|
|||||||
);
|
);
|
||||||
let tx_refund = TxRefund::new(&tx_cancel, &state3.refund_address);
|
let tx_refund = TxRefund::new(&tx_cancel, &state3.refund_address);
|
||||||
AliceState::BtcPunishable {
|
AliceState::BtcPunishable {
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
tx_refund,
|
tx_refund,
|
||||||
state3: Box::new(state3),
|
state3: Box::new(state3),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Alice::BtcRefunded {
|
Alice::BtcRefunded {
|
||||||
state3, spend_key, ..
|
monero_wallet_restore_blockheight,
|
||||||
|
state3,
|
||||||
|
spend_key,
|
||||||
} => AliceState::BtcRefunded {
|
} => AliceState::BtcRefunded {
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
spend_key,
|
spend_key,
|
||||||
state3: Box::new(state3),
|
state3: Box::new(state3),
|
||||||
},
|
},
|
||||||
@ -170,10 +233,10 @@ impl Display for Alice {
|
|||||||
match self {
|
match self {
|
||||||
Alice::Started { .. } => write!(f, "Started"),
|
Alice::Started { .. } => write!(f, "Started"),
|
||||||
Alice::BtcLocked { .. } => f.write_str("Bitcoin locked"),
|
Alice::BtcLocked { .. } => f.write_str("Bitcoin locked"),
|
||||||
Alice::XmrLocked(_) => f.write_str("Monero locked"),
|
Alice::XmrLocked { .. } => f.write_str("Monero locked"),
|
||||||
Alice::CancelTimelockExpired(_) => f.write_str("Cancel timelock is expired"),
|
Alice::CancelTimelockExpired { .. } => f.write_str("Cancel timelock is expired"),
|
||||||
Alice::BtcCancelled(_) => f.write_str("Bitcoin cancel transaction published"),
|
Alice::BtcCancelled { .. } => f.write_str("Bitcoin cancel transaction published"),
|
||||||
Alice::BtcPunishable(_) => f.write_str("Bitcoin punishable"),
|
Alice::BtcPunishable { .. } => f.write_str("Bitcoin punishable"),
|
||||||
Alice::BtcRefunded { .. } => f.write_str("Monero refundable"),
|
Alice::BtcRefunded { .. } => f.write_str("Monero refundable"),
|
||||||
Alice::Done(end_state) => write!(f, "Done: {}", end_state),
|
Alice::Done(end_state) => write!(f, "Done: {}", end_state),
|
||||||
Alice::EncSigLearned { .. } => f.write_str("Encrypted signature learned"),
|
Alice::EncSigLearned { .. } => f.write_str("Encrypted signature learned"),
|
||||||
|
@ -216,7 +216,7 @@ pub trait CreateWalletForOutput {
|
|||||||
&self,
|
&self,
|
||||||
private_spend_key: PrivateKey,
|
private_spend_key: PrivateKey,
|
||||||
private_view_key: PrivateViewKey,
|
private_view_key: PrivateViewKey,
|
||||||
restore_height: Option<u32>,
|
restore_height: BlockHeight,
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ impl CreateWalletForOutput for Wallet {
|
|||||||
&self,
|
&self,
|
||||||
private_spend_key: PrivateKey,
|
private_spend_key: PrivateKey,
|
||||||
private_view_key: PrivateViewKey,
|
private_view_key: PrivateViewKey,
|
||||||
restore_height: Option<u32>,
|
restore_height: BlockHeight,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let public_spend_key = PublicKey::from_private_key(&private_spend_key);
|
let public_spend_key = PublicKey::from_private_key(&private_spend_key);
|
||||||
let public_view_key = PublicKey::from_private_key(&private_view_key.into());
|
let public_view_key = PublicKey::from_private_key(&private_view_key.into());
|
||||||
@ -95,7 +95,7 @@ impl CreateWalletForOutput for Wallet {
|
|||||||
&address.to_string(),
|
&address.to_string(),
|
||||||
&private_spend_key.to_string(),
|
&private_spend_key.to_string(),
|
||||||
&PrivateKey::from(private_view_key).to_string(),
|
&PrivateKey::from(private_view_key).to_string(),
|
||||||
restore_height,
|
restore_height.height,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use anyhow::{anyhow, bail, Context, Result};
|
use anyhow::{anyhow, bail, Context, Result};
|
||||||
use libp2p::PeerId;
|
use libp2p::PeerId;
|
||||||
|
use monero_rpc::wallet::BlockHeight;
|
||||||
use rand::{CryptoRng, RngCore};
|
use rand::{CryptoRng, RngCore};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sigma_fun::ext::dl_secp256k1_ed25519_eq::CrossCurveDLEQProof;
|
use sigma_fun::ext::dl_secp256k1_ed25519_eq::CrossCurveDLEQProof;
|
||||||
@ -31,27 +32,33 @@ pub enum AliceState {
|
|||||||
state3: Box<State3>,
|
state3: Box<State3>,
|
||||||
},
|
},
|
||||||
XmrLocked {
|
XmrLocked {
|
||||||
|
monero_wallet_restore_blockheight: BlockHeight,
|
||||||
state3: Box<State3>,
|
state3: Box<State3>,
|
||||||
},
|
},
|
||||||
EncSigLearned {
|
EncSigLearned {
|
||||||
|
monero_wallet_restore_blockheight: BlockHeight,
|
||||||
encrypted_signature: Box<bitcoin::EncryptedSignature>,
|
encrypted_signature: Box<bitcoin::EncryptedSignature>,
|
||||||
state3: Box<State3>,
|
state3: Box<State3>,
|
||||||
},
|
},
|
||||||
BtcRedeemed,
|
BtcRedeemed,
|
||||||
BtcCancelled {
|
BtcCancelled {
|
||||||
|
monero_wallet_restore_blockheight: BlockHeight,
|
||||||
tx_cancel: Box<TxCancel>,
|
tx_cancel: Box<TxCancel>,
|
||||||
state3: Box<State3>,
|
state3: Box<State3>,
|
||||||
},
|
},
|
||||||
BtcRefunded {
|
BtcRefunded {
|
||||||
|
monero_wallet_restore_blockheight: BlockHeight,
|
||||||
spend_key: monero::PrivateKey,
|
spend_key: monero::PrivateKey,
|
||||||
state3: Box<State3>,
|
state3: Box<State3>,
|
||||||
},
|
},
|
||||||
BtcPunishable {
|
BtcPunishable {
|
||||||
|
monero_wallet_restore_blockheight: BlockHeight,
|
||||||
tx_refund: TxRefund,
|
tx_refund: TxRefund,
|
||||||
state3: Box<State3>,
|
state3: Box<State3>,
|
||||||
},
|
},
|
||||||
XmrRefunded,
|
XmrRefunded,
|
||||||
CancelTimelockExpired {
|
CancelTimelockExpired {
|
||||||
|
monero_wallet_restore_blockheight: BlockHeight,
|
||||||
state3: Box<State3>,
|
state3: Box<State3>,
|
||||||
},
|
},
|
||||||
BtcPunished,
|
BtcPunished,
|
||||||
|
@ -10,7 +10,7 @@ use crate::{
|
|||||||
database::Database,
|
database::Database,
|
||||||
execution_params::ExecutionParams,
|
execution_params::ExecutionParams,
|
||||||
monero,
|
monero,
|
||||||
monero::CreateWalletForOutput,
|
monero::{CreateWalletForOutput, WalletBlockHeight},
|
||||||
monero_ext::ScalarExt,
|
monero_ext::ScalarExt,
|
||||||
protocol::{
|
protocol::{
|
||||||
alice,
|
alice,
|
||||||
@ -127,6 +127,10 @@ async fn run_until_internal(
|
|||||||
bob_peer_id,
|
bob_peer_id,
|
||||||
state3,
|
state3,
|
||||||
} => {
|
} => {
|
||||||
|
// Record the current monero wallet block height so we don't have to scan from
|
||||||
|
// block 0 for scenarios where we create a refund wallet.
|
||||||
|
let monero_wallet_restore_blockheight = monero_wallet.block_height().await?;
|
||||||
|
|
||||||
lock_xmr(
|
lock_xmr(
|
||||||
bob_peer_id,
|
bob_peer_id,
|
||||||
*state3.clone(),
|
*state3.clone(),
|
||||||
@ -135,7 +139,10 @@ async fn run_until_internal(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let state = AliceState::XmrLocked { state3 };
|
let state = AliceState::XmrLocked {
|
||||||
|
state3,
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
};
|
||||||
|
|
||||||
let db_state = (&state).into();
|
let db_state = (&state).into();
|
||||||
db.insert_latest_state(swap_id, database::Swap::Alice(db_state))
|
db.insert_latest_state(swap_id, database::Swap::Alice(db_state))
|
||||||
@ -152,7 +159,10 @@ async fn run_until_internal(
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
AliceState::XmrLocked { state3 } => {
|
AliceState::XmrLocked {
|
||||||
|
state3,
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
} => {
|
||||||
let state = match state3.expired_timelocks(bitcoin_wallet.as_ref()).await? {
|
let state = match state3.expired_timelocks(bitcoin_wallet.as_ref()).await? {
|
||||||
ExpiredTimelocks::None => {
|
ExpiredTimelocks::None => {
|
||||||
let wait_for_enc_sig =
|
let wait_for_enc_sig =
|
||||||
@ -165,14 +175,21 @@ async fn run_until_internal(
|
|||||||
pin_mut!(cancel_timelock_expires);
|
pin_mut!(cancel_timelock_expires);
|
||||||
|
|
||||||
match select(cancel_timelock_expires, wait_for_enc_sig).await {
|
match select(cancel_timelock_expires, wait_for_enc_sig).await {
|
||||||
Either::Left(_) => AliceState::CancelTimelockExpired { state3 },
|
Either::Left(_) => AliceState::CancelTimelockExpired {
|
||||||
|
state3,
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
},
|
||||||
Either::Right((enc_sig, _)) => AliceState::EncSigLearned {
|
Either::Right((enc_sig, _)) => AliceState::EncSigLearned {
|
||||||
state3,
|
state3,
|
||||||
encrypted_signature: Box::new(enc_sig?),
|
encrypted_signature: Box::new(enc_sig?),
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => AliceState::CancelTimelockExpired { state3 },
|
_ => AliceState::CancelTimelockExpired {
|
||||||
|
state3,
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let db_state = (&state).into();
|
let db_state = (&state).into();
|
||||||
@ -193,6 +210,7 @@ async fn run_until_internal(
|
|||||||
AliceState::EncSigLearned {
|
AliceState::EncSigLearned {
|
||||||
state3,
|
state3,
|
||||||
encrypted_signature,
|
encrypted_signature,
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
} => {
|
} => {
|
||||||
let state = match state3.expired_timelocks(bitcoin_wallet.as_ref()).await? {
|
let state = match state3.expired_timelocks(bitcoin_wallet.as_ref()).await? {
|
||||||
ExpiredTimelocks::None => {
|
ExpiredTimelocks::None => {
|
||||||
@ -228,7 +246,10 @@ async fn run_until_internal(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
AliceState::CancelTimelockExpired { state3 }
|
AliceState::CancelTimelockExpired {
|
||||||
|
state3,
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,11 +259,17 @@ async fn run_until_internal(
|
|||||||
.wait_for_cancel_timelock_to_expire(bitcoin_wallet.as_ref())
|
.wait_for_cancel_timelock_to_expire(bitcoin_wallet.as_ref())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
AliceState::CancelTimelockExpired { state3 }
|
AliceState::CancelTimelockExpired {
|
||||||
|
state3,
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => AliceState::CancelTimelockExpired { state3 },
|
_ => AliceState::CancelTimelockExpired {
|
||||||
|
state3,
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let db_state = (&state).into();
|
let db_state = (&state).into();
|
||||||
@ -260,7 +287,10 @@ async fn run_until_internal(
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
AliceState::CancelTimelockExpired { state3 } => {
|
AliceState::CancelTimelockExpired {
|
||||||
|
state3,
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
} => {
|
||||||
let tx_cancel = publish_cancel_transaction(
|
let tx_cancel = publish_cancel_transaction(
|
||||||
state3.tx_lock.clone(),
|
state3.tx_lock.clone(),
|
||||||
state3.a.clone(),
|
state3.a.clone(),
|
||||||
@ -274,6 +304,7 @@ async fn run_until_internal(
|
|||||||
let state = AliceState::BtcCancelled {
|
let state = AliceState::BtcCancelled {
|
||||||
state3,
|
state3,
|
||||||
tx_cancel: Box::new(tx_cancel),
|
tx_cancel: Box::new(tx_cancel),
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
};
|
};
|
||||||
let db_state = (&state).into();
|
let db_state = (&state).into();
|
||||||
db.insert_latest_state(swap_id, database::Swap::Alice(db_state))
|
db.insert_latest_state(swap_id, database::Swap::Alice(db_state))
|
||||||
@ -290,7 +321,11 @@ async fn run_until_internal(
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
AliceState::BtcCancelled { state3, tx_cancel } => {
|
AliceState::BtcCancelled {
|
||||||
|
state3,
|
||||||
|
tx_cancel,
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
} => {
|
||||||
let tx_cancel_height = bitcoin_wallet
|
let tx_cancel_height = bitcoin_wallet
|
||||||
.transaction_block_height(tx_cancel.txid())
|
.transaction_block_height(tx_cancel.txid())
|
||||||
.await?;
|
.await?;
|
||||||
@ -307,7 +342,11 @@ async fn run_until_internal(
|
|||||||
// TODO(Franck): Review error handling
|
// TODO(Franck): Review error handling
|
||||||
match published_refund_tx {
|
match published_refund_tx {
|
||||||
None => {
|
None => {
|
||||||
let state = AliceState::BtcPunishable { tx_refund, state3 };
|
let state = AliceState::BtcPunishable {
|
||||||
|
tx_refund,
|
||||||
|
state3,
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
};
|
||||||
let db_state = (&state).into();
|
let db_state = (&state).into();
|
||||||
db.insert_latest_state(swap_id, database::Swap::Alice(db_state))
|
db.insert_latest_state(swap_id, database::Swap::Alice(db_state))
|
||||||
.await?;
|
.await?;
|
||||||
@ -333,7 +372,11 @@ async fn run_until_internal(
|
|||||||
state3.S_b_bitcoin,
|
state3.S_b_bitcoin,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let state = AliceState::BtcRefunded { spend_key, state3 };
|
let state = AliceState::BtcRefunded {
|
||||||
|
spend_key,
|
||||||
|
state3,
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
};
|
||||||
let db_state = (&state).into();
|
let db_state = (&state).into();
|
||||||
db.insert_latest_state(swap_id, database::Swap::Alice(db_state))
|
db.insert_latest_state(swap_id, database::Swap::Alice(db_state))
|
||||||
.await?;
|
.await?;
|
||||||
@ -351,11 +394,19 @@ async fn run_until_internal(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AliceState::BtcRefunded { spend_key, state3 } => {
|
AliceState::BtcRefunded {
|
||||||
|
spend_key,
|
||||||
|
state3,
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
} => {
|
||||||
let view_key = state3.v;
|
let view_key = state3.v;
|
||||||
|
|
||||||
monero_wallet
|
monero_wallet
|
||||||
.create_and_load_wallet_for_output(spend_key, view_key, None)
|
.create_and_load_wallet_for_output(
|
||||||
|
spend_key,
|
||||||
|
view_key,
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let state = AliceState::XmrRefunded;
|
let state = AliceState::XmrRefunded;
|
||||||
@ -364,7 +415,11 @@ async fn run_until_internal(
|
|||||||
.await?;
|
.await?;
|
||||||
Ok(state)
|
Ok(state)
|
||||||
}
|
}
|
||||||
AliceState::BtcPunishable { tx_refund, state3 } => {
|
AliceState::BtcPunishable {
|
||||||
|
tx_refund,
|
||||||
|
state3,
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
} => {
|
||||||
let signed_tx_punish = build_bitcoin_punish_transaction(
|
let signed_tx_punish = build_bitcoin_punish_transaction(
|
||||||
&state3.tx_lock,
|
&state3.tx_lock,
|
||||||
state3.cancel_timelock,
|
state3.cancel_timelock,
|
||||||
@ -395,7 +450,11 @@ async fn run_until_internal(
|
|||||||
state3.a.clone(),
|
state3.a.clone(),
|
||||||
state3.S_b_bitcoin,
|
state3.S_b_bitcoin,
|
||||||
)?;
|
)?;
|
||||||
let state = AliceState::BtcRefunded { spend_key, state3 };
|
let state = AliceState::BtcRefunded {
|
||||||
|
spend_key,
|
||||||
|
state3,
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
};
|
||||||
let db_state = (&state).into();
|
let db_state = (&state).into();
|
||||||
db.insert_latest_state(swap_id, database::Swap::Alice(db_state))
|
db.insert_latest_state(swap_id, database::Swap::Alice(db_state))
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -328,7 +328,7 @@ impl State3 {
|
|||||||
self,
|
self,
|
||||||
xmr_wallet: &W,
|
xmr_wallet: &W,
|
||||||
transfer_proof: TransferProof,
|
transfer_proof: TransferProof,
|
||||||
monero_wallet_restore_blockheight: u32,
|
monero_wallet_restore_blockheight: BlockHeight,
|
||||||
) -> Result<Result<State4, InsufficientFunds>>
|
) -> Result<Result<State4, InsufficientFunds>>
|
||||||
where
|
where
|
||||||
W: monero::WatchForTransfer,
|
W: monero::WatchForTransfer,
|
||||||
@ -393,7 +393,9 @@ impl State3 {
|
|||||||
tx_lock: self.tx_lock.clone(),
|
tx_lock: self.tx_lock.clone(),
|
||||||
tx_cancel_sig_a: self.tx_cancel_sig_a.clone(),
|
tx_cancel_sig_a: self.tx_cancel_sig_a.clone(),
|
||||||
tx_refund_encsig: self.tx_refund_encsig.clone(),
|
tx_refund_encsig: self.tx_refund_encsig.clone(),
|
||||||
monero_wallet_restore_blockheight: 0u32,
|
// For cancel scenarios the monero wallet rescan blockchain height is irrelevant for
|
||||||
|
// Bob, because Bob's cancel can only lead to refunding on Bitcoin
|
||||||
|
monero_wallet_restore_blockheight: BlockHeight { height: 0 },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,7 +431,7 @@ pub struct State4 {
|
|||||||
tx_lock: bitcoin::TxLock,
|
tx_lock: bitcoin::TxLock,
|
||||||
tx_cancel_sig_a: Signature,
|
tx_cancel_sig_a: Signature,
|
||||||
tx_refund_encsig: bitcoin::EncryptedSignature,
|
tx_refund_encsig: bitcoin::EncryptedSignature,
|
||||||
monero_wallet_restore_blockheight: u32,
|
monero_wallet_restore_blockheight: BlockHeight,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State4 {
|
impl State4 {
|
||||||
@ -589,7 +591,7 @@ 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: u32,
|
monero_wallet_restore_blockheight: BlockHeight,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State5 {
|
impl State5 {
|
||||||
@ -604,11 +606,7 @@ impl State5 {
|
|||||||
// NOTE: This actually generates and opens a new wallet, closing the currently
|
// NOTE: This actually generates and opens a new wallet, closing the currently
|
||||||
// open one.
|
// open one.
|
||||||
monero_wallet
|
monero_wallet
|
||||||
.create_and_load_wallet_for_output(
|
.create_and_load_wallet_for_output(s, self.v, self.monero_wallet_restore_blockheight)
|
||||||
s,
|
|
||||||
self.v,
|
|
||||||
Some(self.monero_wallet_restore_blockheight),
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -176,7 +176,7 @@ async fn run_until_internal(
|
|||||||
let xmr_lock_watcher = state.clone().watch_for_lock_xmr(
|
let xmr_lock_watcher = state.clone().watch_for_lock_xmr(
|
||||||
monero_wallet.as_ref(),
|
monero_wallet.as_ref(),
|
||||||
lock_transfer_proof,
|
lock_transfer_proof,
|
||||||
monero_wallet_restore_blockheight.height,
|
monero_wallet_restore_blockheight,
|
||||||
);
|
);
|
||||||
let cancel_timelock_expires =
|
let cancel_timelock_expires =
|
||||||
state.wait_for_cancel_timelock_to_expire(bitcoin_wallet.as_ref());
|
state.wait_for_cancel_timelock_to_expire(bitcoin_wallet.as_ref());
|
||||||
|
Loading…
Reference in New Issue
Block a user