Skip to content

Commit

Permalink
chore: get v1 /info in wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Dec 9, 2023
1 parent 32e2d4a commit 27099a7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
11 changes: 9 additions & 2 deletions flutter/native/src/wasm_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use moksha_core::blind::BlindedMessage;
use moksha_core::keyset::Keysets;
use moksha_core::primitives::CashuErrorResponse;
use moksha_core::primitives::{
CheckFeesRequest, CheckFeesResponse, PaymentRequest, PostMeltRequest, PostMeltResponse,
PostMintRequest, PostMintResponse, PostSplitRequest, PostSplitResponse,
CheckFeesRequest, CheckFeesResponse, MintInfoResponse, PaymentRequest, PostMeltRequest,
PostMeltResponse, PostMintRequest, PostMintResponse, PostSplitRequest, PostSplitResponse,
};
use moksha_core::proof::Proofs;
use moksha_wallet::{client::Client, error::MokshaWalletError};
Expand Down Expand Up @@ -120,6 +120,13 @@ impl Client for WasmClient {
.await?;
extract_response_data::<PostMintResponse>(resp).await
}

async fn get_info(&self, mint_url: &Url) -> Result<MintInfoResponse, MokshaWalletError> {
let resp = Request::get(mint_url.join(&format!("info"))?.as_str())
.send()
.await?;
extract_response_data::<MintInfoResponse>(resp).await
}
}

async fn extract_response_data<T: serde::de::DeserializeOwned>(
Expand Down
5 changes: 4 additions & 1 deletion moksha-wallet/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use moksha_core::{
blind::BlindedMessage,
keyset::Keysets,
primitives::{
CheckFeesResponse, PaymentRequest, PostMeltResponse, PostMintResponse, PostSplitResponse,
CheckFeesResponse, MintInfoResponse, PaymentRequest, PostMeltResponse, PostMintResponse,
PostSplitResponse,
},
proof::Proofs,
};
Expand Down Expand Up @@ -59,4 +60,6 @@ pub trait Client {
mint_url: &Url,
amount: u64,
) -> Result<PaymentRequest, MokshaWalletError>;

async fn get_info(&self, mint_url: &Url) -> Result<MintInfoResponse, MokshaWalletError>;
}
14 changes: 12 additions & 2 deletions moksha-wallet/src/client/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use moksha_core::{
blind::BlindedMessage,
keyset::Keysets,
primitives::{
CashuErrorResponse, CheckFeesRequest, CheckFeesResponse, PaymentRequest, PostMeltRequest,
PostMeltResponse, PostMintRequest, PostMintResponse, PostSplitRequest, PostSplitResponse,
CashuErrorResponse, CheckFeesRequest, CheckFeesResponse, MintInfoResponse, PaymentRequest,
PostMeltRequest, PostMeltResponse, PostMintRequest, PostMintResponse, PostSplitRequest,
PostSplitResponse,
},
proof::Proofs,
};
Expand Down Expand Up @@ -150,6 +151,15 @@ impl Client for HttpClient {
.await?;
extract_response_data::<PostMintResponse>(resp).await
}

async fn get_info(&self, mint_url: &Url) -> Result<MintInfoResponse, MokshaWalletError> {
let resp = self
.request_client
.get(mint_url.join("info")?)
.send()
.await?;
extract_response_data::<MintInfoResponse>(resp).await
}
}

async fn extract_response_data<T: serde::de::DeserializeOwned>(
Expand Down
7 changes: 6 additions & 1 deletion moksha-wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ mod tests {
use moksha_core::fixture::{read_fixture, read_fixture_as};
use moksha_core::keyset::{Keysets, MintKeyset};
use moksha_core::primitives::{
CheckFeesResponse, PaymentRequest, PostMeltResponse, PostMintResponse, PostSplitResponse,
CheckFeesResponse, MintInfoResponse, PaymentRequest, PostMeltResponse, PostMintResponse,
PostSplitResponse,
};
use moksha_core::proof::Proofs;
use moksha_core::token::{Token, TokenV3};
Expand Down Expand Up @@ -616,6 +617,10 @@ mod tests {
) -> Result<PaymentRequest, MokshaWalletError> {
unimplemented!()
}

async fn get_info(&self, _mint_url: &Url) -> Result<MintInfoResponse, MokshaWalletError> {
unimplemented!()
}
}

#[tokio::test]
Expand Down
7 changes: 6 additions & 1 deletion moksha-wallet/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use moksha_core::blind::BlindedMessage;
use moksha_core::fixture::{read_fixture, read_fixture_as};
use moksha_core::keyset::{Keysets, MintKeyset};
use moksha_core::primitives::{
CheckFeesResponse, PaymentRequest, PostMeltResponse, PostMintResponse, PostSplitResponse,
CheckFeesResponse, MintInfoResponse, PaymentRequest, PostMeltResponse, PostMintResponse,
PostSplitResponse,
};
use moksha_core::proof::Proofs;
use moksha_core::token::TokenV3;
Expand Down Expand Up @@ -98,6 +99,10 @@ impl Client for MockClient {
) -> Result<PaymentRequest, MokshaWalletError> {
unimplemented!()
}

async fn get_info(&self, _mint_url: &Url) -> Result<MintInfoResponse, MokshaWalletError> {
unimplemented!()
}
}

/// tests if tokens get restored, if the lightning payment is not successful
Expand Down

0 comments on commit 27099a7

Please sign in to comment.