bindings/cashu-js nut03

This commit is contained in:
thesimplekid
2023-09-24 11:53:56 +01:00
parent a11bf599ff
commit 656ace3f50
2 changed files with 50 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
mod nut00;
mod nut01;
mod nut02;
mod nut03;

View File

@@ -0,0 +1,49 @@
use std::ops::Deref;
use cashu::nuts::nut03::RequestMintResponse;
use wasm_bindgen::prelude::*;
use crate::types::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()
}
}