From 62605a318aaf7a72e72dc9b3e92441ede24d9b6b Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Tue, 9 Feb 2021 13:57:53 +1100 Subject: [PATCH] Add CreateWallet trait to expose create_wallet --- monero-harness/src/rpc/wallet.rs | 6 +++++- swap/src/monero.rs | 5 +++++ swap/src/monero/wallet.rs | 12 ++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/monero-harness/src/rpc/wallet.rs b/monero-harness/src/rpc/wallet.rs index d31a8b21..1f7920bc 100644 --- a/monero-harness/src/rpc/wallet.rs +++ b/monero-harness/src/rpc/wallet.rs @@ -1,6 +1,6 @@ use crate::rpc::{Request, Response}; -use anyhow::Result; +use anyhow::{bail, Result}; use reqwest::Url; use serde::{Deserialize, Serialize}; use tracing::debug; @@ -140,6 +140,10 @@ impl Client { debug!("create wallet RPC response: {}", response); + if response.contains("error") { + bail!("Failed to create wallet") + } + Ok(()) } diff --git a/swap/src/monero.rs b/swap/src/monero.rs index caec8864..3b33d2c4 100644 --- a/swap/src/monero.rs +++ b/swap/src/monero.rs @@ -207,6 +207,11 @@ pub trait CreateWalletForOutput { ) -> anyhow::Result<()>; } +#[async_trait] +pub trait CreateWallet { + async fn create_wallet(&self, file_name: &str) -> anyhow::Result<()>; +} + #[derive(thiserror::Error, Debug, Clone, PartialEq)] #[error("Overflow, cannot convert {0} to u64")] pub struct OverflowError(pub String); diff --git a/swap/src/monero/wallet.rs b/swap/src/monero/wallet.rs index d9d7ea73..b2d5d330 100644 --- a/swap/src/monero/wallet.rs +++ b/swap/src/monero/wallet.rs @@ -1,6 +1,6 @@ use crate::monero::{ - Amount, CreateWalletForOutput, InsufficientFunds, PrivateViewKey, PublicViewKey, Transfer, - TransferProof, TxHash, WatchForTransfer, + Amount, CreateWallet, CreateWalletForOutput, InsufficientFunds, PrivateViewKey, PublicViewKey, + Transfer, TransferProof, TxHash, WatchForTransfer, }; use ::monero::{Address, Network, PrivateKey, PublicKey}; use anyhow::Result; @@ -94,6 +94,14 @@ impl CreateWalletForOutput for Wallet { } } +#[async_trait] +impl CreateWallet for Wallet { + async fn create_wallet(&self, file_name: &str) -> Result<()> { + self.inner.create_wallet(file_name).await?; + Ok(()) + } +} + // TODO: For retry, use `backoff::ExponentialBackoff` in production as opposed // to `ConstantBackoff`. #[async_trait]