Skip to content

Commit

Permalink
Use dyn HttpClientMethods in Wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcaseria committed Oct 30, 2024
1 parent 24dbfde commit ba643ff
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 15 deletions.
4 changes: 3 additions & 1 deletion crates/cdk/src/wallet/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Wallet client
use std::fmt::Debug;

use async_trait::async_trait;
use reqwest::Client;
use serde_json::Value;
Expand Down Expand Up @@ -374,7 +376,7 @@ impl HttpClientMethods for HttpClient {

/// Http Client Methods
#[async_trait]
pub trait HttpClientMethods {
pub trait HttpClientMethods: Debug {
/// Get Active Mint Keys [NUT-01]
async fn get_mint_keys(&self, mint_url: MintUrl) -> Result<Vec<KeySet>, Error>;

Expand Down
2 changes: 0 additions & 2 deletions crates/cdk/src/wallet/keysets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use crate::nuts::Keys;
use crate::Error;
use crate::Wallet;

use super::client::HttpClientMethods;

impl Wallet {
/// Get keys for mint keyset
///
Expand Down
1 change: 0 additions & 1 deletion crates/cdk/src/wallet/melt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::{
Amount, Error, Wallet,
};

use super::client::HttpClientMethods;
use super::MeltQuote;

impl Wallet {
Expand Down
1 change: 0 additions & 1 deletion crates/cdk/src/wallet/mint.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use tracing::instrument;

use super::client::HttpClientMethods;
use super::MintQuote;
use crate::nuts::nut00::ProofsMethods;
use crate::{
Expand Down
8 changes: 4 additions & 4 deletions crates/cdk/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct Wallet {
/// The targeted amount of proofs to have at each size
pub target_proof_count: usize,
xpriv: Xpriv,
client: HttpClient,
client: Arc<dyn HttpClientMethods>,
}

impl Wallet {
Expand Down Expand Up @@ -89,16 +89,16 @@ impl Wallet {
Ok(Self {
mint_url: MintUrl::from_str(mint_url)?,
unit,
client: HttpClient::new(),
client: Arc::new(HttpClient::new()),
localstore,
xpriv,
target_proof_count: target_proof_count.unwrap_or(3),
})
}

/// Change HTTP client
pub fn set_client(&mut self, client: HttpClient) {
self.client = client;
pub fn set_client<C: HttpClientMethods + 'static>(&mut self, client: C) {
self.client = Arc::new(client);
}

/// Fee required for proof set
Expand Down
2 changes: 0 additions & 2 deletions crates/cdk/src/wallet/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use crate::{
Amount, Error, Wallet,
};

use super::client::HttpClientMethods;

impl Wallet {
/// Get unspent proofs for mint
#[instrument(skip(self))]
Expand Down
2 changes: 0 additions & 2 deletions crates/cdk/src/wallet/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ use crate::{
Amount, Error, Wallet, SECP256K1,
};

use super::client::HttpClientMethods;

impl Wallet {
/// Receive proofs
#[instrument(skip_all)]
Expand Down
2 changes: 0 additions & 2 deletions crates/cdk/src/wallet/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ use crate::Amount;
use crate::Error;
use crate::Wallet;

use super::client::HttpClientMethods;

impl Wallet {
/// Swap
#[instrument(skip(self, input_proofs))]
Expand Down

0 comments on commit ba643ff

Please sign in to comment.