mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-12-25 07:29:32 -05:00
Change monitoring to default wallet
The automated swap backend (asb) requires Monero funds, because Alice is selling Monero. We use a hardcoded default wallet named asb-wallet. This wallet is opened upon startup. If the default wallet does not exist it will be created.
This commit is contained in:
parent
b9b8d2ce1a
commit
b4ceee49df
@ -31,7 +31,7 @@ use swap::{
|
|||||||
execution_params::GetExecutionParams,
|
execution_params::GetExecutionParams,
|
||||||
fs::default_config_path,
|
fs::default_config_path,
|
||||||
monero,
|
monero,
|
||||||
monero::{CreateWallet, OpenWallet},
|
monero::{Amount, CreateWallet, OpenWallet},
|
||||||
protocol::alice::EventLoop,
|
protocol::alice::EventLoop,
|
||||||
seed::Seed,
|
seed::Seed,
|
||||||
trace::init_tracing,
|
trace::init_tracing,
|
||||||
@ -41,7 +41,7 @@ use tracing::{info, warn};
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate prettytable;
|
extern crate prettytable;
|
||||||
|
|
||||||
const MONERO_BLOCKCHAIN_MONITORING_WALLET_NAME: &str = "swap-tool-blockchain-monitoring-wallet";
|
const DEFAULT_WALLET_NAME: &str = "asb-wallet";
|
||||||
const BITCOIN_NETWORK: bitcoin::Network = bitcoin::Network::Testnet;
|
const BITCOIN_NETWORK: bitcoin::Network = bitcoin::Network::Testnet;
|
||||||
const MONERO_NETWORK: monero::Network = monero::Network::Stagenet;
|
const MONERO_NETWORK: monero::Network = monero::Network::Stagenet;
|
||||||
|
|
||||||
@ -154,33 +154,33 @@ async fn init_wallets(
|
|||||||
|
|
||||||
let monero_wallet = monero::Wallet::new(config.monero.wallet_rpc_url.clone(), MONERO_NETWORK);
|
let monero_wallet = monero::Wallet::new(config.monero.wallet_rpc_url.clone(), MONERO_NETWORK);
|
||||||
|
|
||||||
// Setup the temporary Monero wallet necessary for monitoring the blockchain
|
// Setup the Monero wallet
|
||||||
let open_monitoring_wallet_response = monero_wallet
|
let open_wallet_response = monero_wallet.open_wallet(DEFAULT_WALLET_NAME).await;
|
||||||
.open_wallet(MONERO_BLOCKCHAIN_MONITORING_WALLET_NAME)
|
if open_wallet_response.is_err() {
|
||||||
.await;
|
|
||||||
if open_monitoring_wallet_response.is_err() {
|
|
||||||
monero_wallet
|
monero_wallet
|
||||||
.create_wallet(MONERO_BLOCKCHAIN_MONITORING_WALLET_NAME)
|
.create_wallet(DEFAULT_WALLET_NAME)
|
||||||
.await
|
.await
|
||||||
.context(format!(
|
.context(format!(
|
||||||
"Unable to create Monero wallet for blockchain monitoring.\
|
"Unable to create Monero wallet.\
|
||||||
Please ensure that the monero-wallet-rpc is available at {}",
|
Please ensure that the monero-wallet-rpc is available at {}",
|
||||||
config.monero.wallet_rpc_url
|
config.monero.wallet_rpc_url
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
info!(
|
info!("Created Monero wallet {}", DEFAULT_WALLET_NAME);
|
||||||
"Created Monero wallet for blockchain monitoring with name {}",
|
|
||||||
MONERO_BLOCKCHAIN_MONITORING_WALLET_NAME
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
info!(
|
info!("Opened Monero wallet {}", DEFAULT_WALLET_NAME);
|
||||||
"Opened Monero wallet for blockchain monitoring with name {}",
|
|
||||||
MONERO_BLOCKCHAIN_MONITORING_WALLET_NAME
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let _test_wallet_connection = monero_wallet.inner.block_height().await?;
|
let balance = monero_wallet.get_balance().await?;
|
||||||
info!("The Monero wallet RPC is set up correctly!");
|
if balance == Amount::ZERO {
|
||||||
|
let deposit_address = monero_wallet.inner.get_address(0).await?.address;
|
||||||
|
warn!(
|
||||||
|
"The Monero balance is 0, make sure to deposit funds at: {}",
|
||||||
|
deposit_address
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
info!("Monero balance: {}", balance);
|
||||||
|
}
|
||||||
|
|
||||||
Ok((bitcoin_wallet, monero_wallet))
|
Ok((bitcoin_wallet, monero_wallet))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user