Bläddra i källkod

`bindings/cashu-js` `nut03`

thesimplekid 1 år sedan
förälder
incheckning
656ace3f50
2 ändrade filer med 50 tillägg och 0 borttagningar
  1. 1 0
      bindings/cashu-js/src/nuts/mod.rs
  2. 49 0
      bindings/cashu-js/src/nuts/nut03.rs

+ 1 - 0
bindings/cashu-js/src/nuts/mod.rs

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

+ 49 - 0
bindings/cashu-js/src/nuts/nut03.rs

@@ -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()
+    }
+}