ASB reloads the default wallet after generate_from_keys atomically

This commit is contained in:
Daniel Karzel 2021-02-24 18:00:07 +11:00
parent 684cbe4d0b
commit 947bcb6192
6 changed files with 61 additions and 8 deletions

View File

@ -156,7 +156,11 @@ async fn init_wallets(
bitcoin_balance
);
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,
DEFAULT_WALLET_NAME.to_string(),
);
// Setup the Monero wallet
let open_wallet_response = monero_wallet.open_wallet(DEFAULT_WALLET_NAME).await;

View File

@ -289,7 +289,11 @@ async fn init_wallets(
bitcoin_balance
);
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,
MONERO_BLOCKCHAIN_MONITORING_WALLET_NAME.to_string(),
);
// Setup the temporary Monero wallet necessary for monitoring the blockchain
let open_monitoring_wallet_response = monero_wallet

View File

@ -220,6 +220,16 @@ pub trait CreateWalletForOutput {
) -> Result<()>;
}
#[async_trait]
pub trait CreateWalletForOutputThenLoadDefaultWallet {
async fn create_and_load_wallet_for_output_then_load_default_wallet(
&self,
private_spend_key: PrivateKey,
private_view_key: PrivateViewKey,
restore_height: BlockHeight,
) -> Result<()>;
}
#[async_trait]
pub trait OpenWallet {
async fn open_wallet(&self, file_name: &str) -> Result<()>;

View File

@ -1,7 +1,7 @@
use crate::monero::{
Amount, CreateWallet, CreateWalletForOutput, GetAddress, InsufficientFunds, OpenWallet,
PrivateViewKey, PublicViewKey, Refresh, Transfer, TransferProof, TxHash, WalletBlockHeight,
WatchForTransfer,
Amount, CreateWallet, CreateWalletForOutput, CreateWalletForOutputThenLoadDefaultWallet,
GetAddress, InsufficientFunds, OpenWallet, PrivateViewKey, PublicViewKey, Refresh, Transfer,
TransferProof, TxHash, WalletBlockHeight, WatchForTransfer,
};
use ::monero::{Address, Network, PrivateKey, PublicKey};
use anyhow::Result;
@ -25,13 +25,15 @@ use url::Url;
pub struct Wallet {
pub inner: Mutex<wallet::Client>,
pub network: Network,
pub default_wallet_name: String,
}
impl Wallet {
pub fn new(url: Url, network: Network) -> Self {
pub fn new(url: Url, network: Network, default_wallet_name: String) -> Self {
Self {
inner: Mutex::new(wallet::Client::new(url)),
network,
default_wallet_name,
}
}
@ -103,6 +105,38 @@ impl CreateWalletForOutput for Wallet {
}
}
#[async_trait]
impl CreateWalletForOutputThenLoadDefaultWallet for Wallet {
async fn create_and_load_wallet_for_output_then_load_default_wallet(
&self,
private_spend_key: PrivateKey,
private_view_key: PrivateViewKey,
restore_height: BlockHeight,
) -> Result<()> {
let public_spend_key = PublicKey::from_private_key(&private_spend_key);
let public_view_key = PublicKey::from_private_key(&private_view_key.into());
let address = Address::standard(self.network, public_spend_key, public_view_key);
let wallet = self.inner.lock().await;
let _ = wallet
.generate_from_keys(
&address.to_string(),
&private_spend_key.to_string(),
&PrivateKey::from(private_view_key).to_string(),
restore_height.height,
)
.await?;
let _ = wallet
.open_wallet(self.default_wallet_name.as_str())
.await?;
Ok(())
}
}
#[async_trait]
impl OpenWallet for Wallet {
async fn open_wallet(&self, file_name: &str) -> Result<()> {

View File

@ -10,7 +10,7 @@ use crate::{
database::Database,
execution_params::ExecutionParams,
monero,
monero::{CreateWalletForOutput, WalletBlockHeight},
monero::{CreateWalletForOutputThenLoadDefaultWallet, WalletBlockHeight},
monero_ext::ScalarExt,
protocol::{
alice,
@ -402,7 +402,7 @@ async fn run_until_internal(
let view_key = state3.v;
monero_wallet
.create_and_load_wallet_for_output(
.create_and_load_wallet_for_output_then_load_default_wallet(
spend_key,
view_key,
monero_wallet_restore_blockheight,

View File

@ -592,6 +592,7 @@ async fn init_test_wallets(
let xmr_wallet = swap::monero::Wallet {
inner: Mutex::new(monero.wallet(name).unwrap().client()),
network: monero::Network::default(),
default_wallet_name: "irrelevant_for_tests".to_string(),
};
let electrum_rpc_url = {