mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-12-24 06:59:36 -05:00
Swap-id as file name for generated Monero wallet
Instead of using the private view-key as wallet filename we use the swap-id, to be able to identify which wallet is associated with which swap.
This commit is contained in:
parent
548f057726
commit
489696ee08
@ -287,6 +287,7 @@ impl Client {
|
|||||||
|
|
||||||
pub async fn generate_from_keys(
|
pub async fn generate_from_keys(
|
||||||
&self,
|
&self,
|
||||||
|
filename: &str,
|
||||||
address: &str,
|
address: &str,
|
||||||
spend_key: &str,
|
spend_key: &str,
|
||||||
view_key: &str,
|
view_key: &str,
|
||||||
@ -294,7 +295,7 @@ impl Client {
|
|||||||
) -> Result<GenerateFromKeys> {
|
) -> Result<GenerateFromKeys> {
|
||||||
let params = GenerateFromKeysParams {
|
let params = GenerateFromKeysParams {
|
||||||
restore_height,
|
restore_height,
|
||||||
filename: view_key.into(),
|
filename: filename.into(),
|
||||||
address: address.into(),
|
address: address.into(),
|
||||||
spendkey: spend_key.into(),
|
spendkey: spend_key.into(),
|
||||||
viewkey: view_key.into(),
|
viewkey: view_key.into(),
|
||||||
|
@ -73,6 +73,7 @@ impl Wallet {
|
|||||||
/// keys. The generated wallet will remain loaded.
|
/// keys. The generated wallet will remain loaded.
|
||||||
pub async fn create_from_and_load(
|
pub async fn create_from_and_load(
|
||||||
&self,
|
&self,
|
||||||
|
file_name: &str,
|
||||||
private_spend_key: PrivateKey,
|
private_spend_key: PrivateKey,
|
||||||
private_view_key: PrivateViewKey,
|
private_view_key: PrivateViewKey,
|
||||||
restore_height: BlockHeight,
|
restore_height: BlockHeight,
|
||||||
@ -90,6 +91,7 @@ impl Wallet {
|
|||||||
|
|
||||||
let _ = wallet
|
let _ = wallet
|
||||||
.generate_from_keys(
|
.generate_from_keys(
|
||||||
|
file_name,
|
||||||
&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(),
|
||||||
@ -106,6 +108,7 @@ impl Wallet {
|
|||||||
/// stored name.
|
/// stored name.
|
||||||
pub async fn create_from(
|
pub async fn create_from(
|
||||||
&self,
|
&self,
|
||||||
|
file_name: &str,
|
||||||
private_spend_key: PrivateKey,
|
private_spend_key: PrivateKey,
|
||||||
private_view_key: PrivateViewKey,
|
private_view_key: PrivateViewKey,
|
||||||
restore_height: BlockHeight,
|
restore_height: BlockHeight,
|
||||||
@ -124,6 +127,7 @@ impl Wallet {
|
|||||||
|
|
||||||
let _ = wallet
|
let _ = wallet
|
||||||
.generate_from_keys(
|
.generate_from_keys(
|
||||||
|
file_name,
|
||||||
&temp_wallet_address.to_string(),
|
&temp_wallet_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(),
|
||||||
|
@ -11,6 +11,7 @@ use anyhow::{bail, Context, Result};
|
|||||||
use tokio::select;
|
use tokio::select;
|
||||||
use tokio::time::timeout;
|
use tokio::time::timeout;
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub async fn run(swap: alice::Swap) -> Result<AliceState> {
|
pub async fn run(swap: alice::Swap) -> Result<AliceState> {
|
||||||
run_until(swap, |_| false).await
|
run_until(swap, |_| false).await
|
||||||
@ -25,6 +26,7 @@ pub async fn run_until(
|
|||||||
|
|
||||||
while !is_complete(¤t_state) && !exit_early(¤t_state) {
|
while !is_complete(¤t_state) && !exit_early(¤t_state) {
|
||||||
current_state = next_state(
|
current_state = next_state(
|
||||||
|
swap.swap_id,
|
||||||
current_state,
|
current_state,
|
||||||
&mut swap.event_loop_handle,
|
&mut swap.event_loop_handle,
|
||||||
swap.bitcoin_wallet.as_ref(),
|
swap.bitcoin_wallet.as_ref(),
|
||||||
@ -43,6 +45,7 @@ pub async fn run_until(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn next_state(
|
async fn next_state(
|
||||||
|
swap_id: Uuid,
|
||||||
state: AliceState,
|
state: AliceState,
|
||||||
event_loop_handle: &mut EventLoopHandle,
|
event_loop_handle: &mut EventLoopHandle,
|
||||||
bitcoin_wallet: &bitcoin::Wallet,
|
bitcoin_wallet: &bitcoin::Wallet,
|
||||||
@ -296,7 +299,12 @@ async fn next_state(
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
monero_wallet
|
monero_wallet
|
||||||
.create_from(spend_key, view_key, monero_wallet_restore_blockheight)
|
.create_from(
|
||||||
|
&swap_id.to_string(),
|
||||||
|
spend_key,
|
||||||
|
view_key,
|
||||||
|
monero_wallet_restore_blockheight,
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
AliceState::XmrRefunded
|
AliceState::XmrRefunded
|
||||||
|
@ -8,6 +8,7 @@ use crate::{bitcoin, monero};
|
|||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
use tokio::select;
|
use tokio::select;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub fn is_complete(state: &BobState) -> bool {
|
pub fn is_complete(state: &BobState) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
@ -32,6 +33,7 @@ pub async fn run_until(
|
|||||||
|
|
||||||
while !is_target_state(¤t_state) {
|
while !is_target_state(¤t_state) {
|
||||||
current_state = next_state(
|
current_state = next_state(
|
||||||
|
swap.swap_id,
|
||||||
current_state,
|
current_state,
|
||||||
&mut swap.event_loop_handle,
|
&mut swap.event_loop_handle,
|
||||||
swap.bitcoin_wallet.as_ref(),
|
swap.bitcoin_wallet.as_ref(),
|
||||||
@ -51,6 +53,7 @@ pub async fn run_until(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn next_state(
|
async fn next_state(
|
||||||
|
swap_id: Uuid,
|
||||||
state: BobState,
|
state: BobState,
|
||||||
event_loop_handle: &mut EventLoopHandle,
|
event_loop_handle: &mut EventLoopHandle,
|
||||||
bitcoin_wallet: &bitcoin::Wallet,
|
bitcoin_wallet: &bitcoin::Wallet,
|
||||||
@ -193,17 +196,22 @@ async fn next_state(
|
|||||||
BobState::BtcRedeemed(state) => {
|
BobState::BtcRedeemed(state) => {
|
||||||
let (spend_key, view_key) = state.xmr_keys();
|
let (spend_key, view_key) = state.xmr_keys();
|
||||||
|
|
||||||
|
let generated_wallet_file_name = &swap_id.to_string();
|
||||||
if monero_wallet
|
if monero_wallet
|
||||||
.create_from_and_load(spend_key, view_key, state.monero_wallet_restore_blockheight)
|
.create_from_and_load(
|
||||||
|
generated_wallet_file_name,
|
||||||
|
spend_key,
|
||||||
|
view_key,
|
||||||
|
state.monero_wallet_restore_blockheight,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.is_err()
|
.is_err()
|
||||||
{
|
{
|
||||||
// In case we failed to refresh/sweep, when resuming the wallet might already
|
// In case we failed to refresh/sweep, when resuming the wallet might already
|
||||||
// exist! This is a very unlikely scenario, but if we don't take care of it we
|
// exist! This is a very unlikely scenario, but if we don't take care of it we
|
||||||
// might not be able to ever transfer the Monero.
|
// might not be able to ever transfer the Monero.
|
||||||
let wallet_name = &monero::PrivateKey::from(view_key).to_string();
|
tracing::warn!("Failed to generate monero wallet from keys, falling back to trying to open the the wallet if it already exists: {}", swap_id);
|
||||||
tracing::warn!("Failed to generate monero wallet from keys, falling back to trying to open the the wallet if it already exists: {}", wallet_name);
|
monero_wallet.open(generated_wallet_file_name).await?;
|
||||||
monero_wallet.open(wallet_name).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
|
||||||
|
Loading…
Reference in New Issue
Block a user