mirror of
https://github.com/aljazceru/cdk.git
synced 2026-02-10 15:45:59 +01:00
bindings/cashu-js nut04
This commit is contained in:
@@ -2,3 +2,4 @@ mod nut00;
|
||||
mod nut01;
|
||||
mod nut02;
|
||||
mod nut03;
|
||||
mod nut04;
|
||||
|
||||
84
bindings/cashu-js/src/nuts/nut04.rs
Normal file
84
bindings/cashu-js/src/nuts/nut04.rs
Normal file
@@ -0,0 +1,84 @@
|
||||
use std::ops::Deref;
|
||||
|
||||
use cashu::nuts::nut04::{MintRequest, PostMintResponse};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
use crate::{
|
||||
error::{into_err, Result},
|
||||
types::JsAmount,
|
||||
};
|
||||
|
||||
#[wasm_bindgen(js_name = MintRequest)]
|
||||
pub struct JsMintRequest {
|
||||
inner: MintRequest,
|
||||
}
|
||||
|
||||
impl Deref for JsMintRequest {
|
||||
type Target = MintRequest;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MintRequest> for JsMintRequest {
|
||||
fn from(inner: MintRequest) -> JsMintRequest {
|
||||
JsMintRequest { inner }
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_class = MintRequest)]
|
||||
impl JsMintRequest {
|
||||
/// Try From Base 64 String
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(outputs: String) -> Result<JsMintRequest> {
|
||||
let outputs = serde_json::from_str(&outputs).map_err(into_err)?;
|
||||
Ok(JsMintRequest {
|
||||
inner: MintRequest { outputs },
|
||||
})
|
||||
}
|
||||
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn outputs(&self) -> Result<String> {
|
||||
Ok(serde_json::to_string(&self.inner.outputs).map_err(into_err)?)
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = totalAmount)]
|
||||
pub fn totoal_amount(&self) -> JsAmount {
|
||||
self.inner.total_amount().into()
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = PostMintResponse)]
|
||||
pub struct JsPostMintResponse {
|
||||
inner: PostMintResponse,
|
||||
}
|
||||
|
||||
impl Deref for JsPostMintResponse {
|
||||
type Target = PostMintResponse;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PostMintResponse> for JsPostMintResponse {
|
||||
fn from(inner: PostMintResponse) -> JsPostMintResponse {
|
||||
JsPostMintResponse { inner }
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_class = PostMintResponse)]
|
||||
impl JsPostMintResponse {
|
||||
/// Try From Base 64 String
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(promises: String) -> Result<JsPostMintResponse> {
|
||||
let promises = serde_json::from_str(&promises).map_err(into_err)?;
|
||||
Ok(JsPostMintResponse {
|
||||
inner: PostMintResponse { promises },
|
||||
})
|
||||
}
|
||||
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn promises(&self) -> Result<String> {
|
||||
Ok(serde_json::to_string(&self.inner.promises).map_err(into_err)?)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user