refactor: remove RequestMint

This commit is contained in:
thesimplekid
2023-12-14 20:00:42 +00:00
parent 4191ea68d2
commit 66068e6a3d
8 changed files with 9 additions and 159 deletions

View File

@@ -1,44 +1,10 @@
use std::ops::Deref;
use std::str::FromStr;
use std::sync::Arc;
use cashu::nuts::nut03::RequestMintResponse as RequestMintResponseSdk;
use cashu::nuts::{SplitRequest as SplitRequestSdk, SplitResponse as SplitResponseSdk};
use cashu::Bolt11Invoice;
use crate::error::Result;
use crate::{Amount, BlindedMessage, BlindedSignature, Proof};
pub struct RequestMintResponse {
inner: RequestMintResponseSdk,
}
impl RequestMintResponse {
pub fn new(invoice: String, hash: String) -> Result<Self> {
let pr = Bolt11Invoice::from_str(&invoice)?;
Ok(Self {
inner: RequestMintResponseSdk { pr, hash },
})
}
pub fn invoice(&self) -> String {
self.inner.pr.to_string()
}
pub fn hash(&self) -> String {
self.inner.hash.to_string()
}
}
impl From<cashu::nuts::nut03::RequestMintResponse> for RequestMintResponse {
fn from(mint_response: cashu::nuts::nut03::RequestMintResponse) -> RequestMintResponse {
RequestMintResponse {
inner: mint_response,
}
}
}
pub struct SplitRequest {
inner: SplitRequestSdk,
}

View File

@@ -1,53 +1,10 @@
use std::ops::Deref;
use cashu::nuts::{RequestMintResponse, SplitRequest, SplitResponse};
use cashu::nuts::{SplitRequest, SplitResponse};
use wasm_bindgen::prelude::*;
use crate::error::{into_err, Result};
use crate::types::{JsAmount, JsBolt11Invoice};
#[wasm_bindgen(js_name = RequestMintResponse)]
pub struct JsRequestMintResponse {
inner: RequestMintResponse,
}
impl Deref for JsRequestMintResponse {
type Target = RequestMintResponse;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl From<RequestMintResponse> for JsRequestMintResponse {
fn from(inner: RequestMintResponse) -> JsRequestMintResponse {
JsRequestMintResponse { inner }
}
}
#[wasm_bindgen(js_class = RequestMintResponse)]
impl JsRequestMintResponse {
#[wasm_bindgen(constructor)]
pub fn new(pr: JsBolt11Invoice, hash: String) -> JsRequestMintResponse {
JsRequestMintResponse {
inner: RequestMintResponse {
pr: pr.deref().clone(),
hash,
},
}
}
/// Get Bolt11 Invoice
#[wasm_bindgen(getter)]
pub fn invoice(&self) -> JsBolt11Invoice {
self.inner.pr.clone().into()
}
/// Get Hash
#[wasm_bindgen(getter)]
pub fn hash(&self) -> String {
self.inner.hash.to_string()
}
}
use crate::types::JsAmount;
#[wasm_bindgen(js_name = SplitRequest)]
pub struct JsSplitRequest {

View File

@@ -5,11 +5,10 @@ use async_trait::async_trait;
use cashu::nuts::MintInfo;
use cashu::nuts::{
BlindedMessage, Keys, MeltBolt11Request, MeltBolt11Response, MintBolt11Request,
MintBolt11Response, PreMintSecrets, Proof, RequestMintResponse, SplitRequest, SplitResponse, *,
MintBolt11Response, PreMintSecrets, Proof, SplitRequest, SplitResponse, *,
};
#[cfg(feature = "nut07")]
use cashu::nuts::{CheckSpendableRequest, CheckSpendableResponse};
use cashu::Amount;
use gloo::net::http::Request;
use serde_json::Value;
use url::Url;
@@ -57,33 +56,6 @@ impl Client for HttpClient {
}
}
/// Request Mint [NUT-03]
async fn get_request_mint(
&self,
mint_url: Url,
amount: Amount,
) -> Result<RequestMintResponse, Error> {
let mut url = join_url(mint_url, "mint")?;
url.query_pairs_mut()
.append_pair("amount", &amount.to_sat().to_string());
let res = Request::get(url.as_str())
.send()
.await
.map_err(|err| Error::Gloo(err.to_string()))?
.json::<Value>()
.await
.map_err(|err| Error::Gloo(err.to_string()))?;
let response: Result<RequestMintResponse, serde_json::Error> =
serde_json::from_value(res.clone());
match response {
Ok(res) => Ok(res),
Err(_) => Err(Error::from_json(&res.to_string())?),
}
}
/// Mint Tokens [NUT-04]
async fn post_mint(
&self,

View File

@@ -7,11 +7,10 @@ use async_trait::async_trait;
use cashu::nuts::MintInfo;
use cashu::nuts::{
BlindedMessage, Keys, MeltBolt11Request, MeltBolt11Response, MintBolt11Request,
MintBolt11Response, PreMintSecrets, Proof, RequestMintResponse, SplitRequest, SplitResponse, *,
MintBolt11Response, PreMintSecrets, Proof, SplitRequest, SplitResponse, *,
};
#[cfg(feature = "nut07")]
use cashu::nuts::{CheckSpendableRequest, CheckSpendableResponse};
use cashu::Amount;
use serde_json::Value;
use url::Url;
@@ -46,27 +45,6 @@ impl Client for HttpClient {
}
}
/// Request Mint [NUT-03]
async fn get_request_mint(
&self,
mint_url: Url,
amount: Amount,
) -> Result<RequestMintResponse, Error> {
let mut url = join_url(mint_url, "mint")?;
url.query_pairs_mut()
.append_pair("amount", &amount.to_sat().to_string());
let res = minreq::get(url).send()?.json::<Value>()?;
let response: Result<RequestMintResponse, serde_json::Error> =
serde_json::from_value(res.clone());
match response {
Ok(res) => Ok(res),
Err(_) => Err(Error::from_json(&res.to_string())?),
}
}
/// Mint Tokens [NUT-04]
async fn post_mint(
&self,

View File

@@ -9,9 +9,9 @@ use cashu::nuts::CheckSpendableResponse;
use cashu::nuts::MintInfo;
use cashu::nuts::{
BlindedMessage, Keys, KeysetResponse, MeltBolt11Response, MintBolt11Response, PreMintSecrets,
Proof, RequestMintResponse, SplitRequest, SplitResponse,
Proof, SplitRequest, SplitResponse,
};
use cashu::{utils, Amount};
use cashu::utils;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use url::Url;
@@ -89,12 +89,6 @@ pub trait Client {
async fn get_mint_keysets(&self, mint_url: Url) -> Result<KeysetResponse, Error>;
async fn get_request_mint(
&self,
mint_url: Url,
amount: Amount,
) -> Result<RequestMintResponse, Error>;
// TODO: Hash should have a type
async fn post_mint(
&self,

View File

@@ -5,8 +5,8 @@ use cashu::dhke::{construct_proofs, unblind_message};
#[cfg(feature = "nut07")]
use cashu::nuts::nut00::mint;
use cashu::nuts::{
BlindedSignature, CurrencyUnit, Keys, PreMintSecrets, PreSplit, Proof, Proofs,
RequestMintResponse, SplitRequest, Token,
BlindedSignature, CurrencyUnit, Keys, PreMintSecrets, PreSplit, Proof, Proofs, SplitRequest,
Token,
};
#[cfg(feature = "nut07")]
use cashu::types::ProofsStatus;
@@ -81,14 +81,6 @@ impl<C: Client> Wallet<C> {
})
}
/// Request Token Mint
pub async fn request_mint(&self, amount: Amount) -> Result<RequestMintResponse, Error> {
Ok(self
.client
.get_request_mint(self.mint_url.clone().try_into()?, amount)
.await?)
}
// TODO: Need to use the unit, check keyset is of the same unit of attempting to
// mint
pub async fn mint_token(

View File

@@ -19,7 +19,7 @@ pub use nut02::mint::KeySet as MintKeySet;
pub use nut02::{Id, KeySet, KeySetInfo, KeysetResponse};
#[cfg(feature = "wallet")]
pub use nut03::PreSplit;
pub use nut03::{RequestMintResponse, SplitRequest, SplitResponse};
pub use nut03::{SplitRequest, SplitResponse};
pub use nut04::{
MintBolt11Request, MintBolt11Response, MintQuoteBolt11Request, MintQuoteBolt11Response,
};

View File

@@ -10,15 +10,6 @@ use crate::nuts::{BlindedMessage, Proofs};
use crate::Amount;
pub use crate::Bolt11Invoice;
/// Mint request response [NUT-03]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RequestMintResponse {
/// Bolt11 payment request
pub pr: Bolt11Invoice,
/// Random hash MUST not be the hash of invoice
pub hash: String,
}
#[cfg(feature = "wallet")]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct PreSplit {