mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-12-23 14:39:37 -05:00
Add functionality to open monero wallet through rpc
This commit is contained in:
parent
62605a318a
commit
dac4443bbd
@ -121,6 +121,33 @@ impl Client {
|
||||
Ok(r.result)
|
||||
}
|
||||
|
||||
/// Opens a wallet using `filename`.
|
||||
pub async fn open_wallet(&self, filename: &str) -> Result<()> {
|
||||
let params = OpenWalletParams {
|
||||
filename: filename.to_owned(),
|
||||
};
|
||||
let request = Request::new("open_wallet", params);
|
||||
|
||||
let response = self
|
||||
.inner
|
||||
.post(self.url.clone())
|
||||
.json(&request)
|
||||
.send()
|
||||
.await?
|
||||
.text()
|
||||
.await?;
|
||||
|
||||
debug!("open wallet RPC response: {}", response);
|
||||
|
||||
// TODO: Proper error handling once switching to https://github.com/thomaseizinger/rust-jsonrpc-client/
|
||||
// Currently blocked by https://github.com/thomaseizinger/rust-jsonrpc-client/issues/20
|
||||
if response.contains("error") {
|
||||
bail!("Failed to open wallet")
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Creates a wallet using `filename`.
|
||||
pub async fn create_wallet(&self, filename: &str) -> Result<()> {
|
||||
let params = CreateWalletParams {
|
||||
@ -352,6 +379,11 @@ pub struct SubAddressAccount {
|
||||
pub unlocked_balance: u64,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug, Clone)]
|
||||
struct OpenWalletParams {
|
||||
filename: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug, Clone)]
|
||||
struct CreateWalletParams {
|
||||
filename: String,
|
||||
|
@ -207,6 +207,11 @@ pub trait CreateWalletForOutput {
|
||||
) -> anyhow::Result<()>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait OpenWallet {
|
||||
async fn open_wallet(&self, file_name: &str) -> anyhow::Result<()>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait CreateWallet {
|
||||
async fn create_wallet(&self, file_name: &str) -> anyhow::Result<()>;
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::monero::{
|
||||
Amount, CreateWallet, CreateWalletForOutput, InsufficientFunds, PrivateViewKey, PublicViewKey,
|
||||
Transfer, TransferProof, TxHash, WatchForTransfer,
|
||||
Amount, CreateWallet, CreateWalletForOutput, InsufficientFunds, OpenWallet, 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 OpenWallet for Wallet {
|
||||
async fn open_wallet(&self, file_name: &str) -> Result<()> {
|
||||
self.inner.open_wallet(file_name).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl CreateWallet for Wallet {
|
||||
async fn create_wallet(&self, file_name: &str) -> Result<()> {
|
||||
|
Loading…
Reference in New Issue
Block a user