mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 05:45:40 +00:00
Open or create temporary Monero wallet upon wallet initialization
This commit is contained in:
parent
dac4443bbd
commit
1e29433bd2
@ -18,6 +18,7 @@ use crate::{
|
|||||||
initial_setup, query_user_for_initial_testnet_config, read_config, ConfigNotInitialized,
|
initial_setup, query_user_for_initial_testnet_config, read_config, ConfigNotInitialized,
|
||||||
},
|
},
|
||||||
execution_params::GetExecutionParams,
|
execution_params::GetExecutionParams,
|
||||||
|
monero::{CreateWallet, OpenWallet},
|
||||||
protocol::bob::cancel::CancelError,
|
protocol::bob::cancel::CancelError,
|
||||||
};
|
};
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
@ -49,9 +50,11 @@ mod serde_peer_id;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate prettytable;
|
extern crate prettytable;
|
||||||
|
|
||||||
|
const MONERO_WATCH_ONLY_TEMP_WALLET_NAME: &str = "swap-tool-watch-only-tmp-wallet";
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
init_tracing(LevelFilter::Info).expect("initialize tracing");
|
init_tracing(LevelFilter::Debug).expect("initialize tracing");
|
||||||
|
|
||||||
let opt = Options::from_args();
|
let opt = Options::from_args();
|
||||||
|
|
||||||
@ -326,12 +329,35 @@ async fn init_wallets(
|
|||||||
bitcoin_balance
|
bitcoin_balance
|
||||||
);
|
);
|
||||||
|
|
||||||
let monero_wallet = monero::Wallet::new(config.monero.wallet_rpc_url, monero_network);
|
let monero_wallet = monero::Wallet::new(config.monero.wallet_rpc_url.clone(), monero_network);
|
||||||
let monero_balance = monero_wallet.get_balance().await?;
|
|
||||||
info!(
|
// Setup the temporary Monero wallet necessary for monitoring the blockchain
|
||||||
"Connection to Monero wallet succeeded, balance: {}",
|
let open_tmp_wallet_response = monero_wallet
|
||||||
monero_balance
|
.open_wallet(MONERO_WATCH_ONLY_TEMP_WALLET_NAME)
|
||||||
);
|
.await;
|
||||||
|
if open_tmp_wallet_response.is_err() {
|
||||||
|
monero_wallet
|
||||||
|
.create_wallet(MONERO_WATCH_ONLY_TEMP_WALLET_NAME)
|
||||||
|
.await
|
||||||
|
.context(format!(
|
||||||
|
"Unable to create temporary Monero wallet.\
|
||||||
|
Please ensure that the monero-wallet-rpc is available at {}",
|
||||||
|
config.monero.wallet_rpc_url
|
||||||
|
))?;
|
||||||
|
|
||||||
|
info!(
|
||||||
|
"Created temporary Monero wallet {}",
|
||||||
|
MONERO_WATCH_ONLY_TEMP_WALLET_NAME
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
info!(
|
||||||
|
"Opened temporary Monero wallet {}",
|
||||||
|
MONERO_WATCH_ONLY_TEMP_WALLET_NAME
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let _test_wallet_connection = monero_wallet.inner.block_height().await?;
|
||||||
|
info!("The Monero wallet RPC is set up correctly!");
|
||||||
|
|
||||||
Ok((bitcoin_wallet, monero_wallet))
|
Ok((bitcoin_wallet, monero_wallet))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user