Add CreateWallet trait to expose create_wallet

This commit is contained in:
Daniel Karzel 2021-02-09 13:57:53 +11:00
parent 27bb9498d5
commit 62605a318a
3 changed files with 20 additions and 3 deletions

View File

@ -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(())
}

View File

@ -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);

View File

@ -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]