|
@@ -1,9 +1,10 @@
|
|
use std::ops::Deref;
|
|
use std::ops::Deref;
|
|
|
|
|
|
-use cashu::nuts::nut03::RequestMintResponse;
|
|
|
|
|
|
+use cashu::nuts::{RequestMintResponse, SplitRequest, SplitResponse};
|
|
use wasm_bindgen::prelude::*;
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
|
|
-use crate::types::JsBolt11Invoice;
|
|
|
|
|
|
+use crate::error::{into_err, Result};
|
|
|
|
+use crate::types::{JsAmount, JsBolt11Invoice};
|
|
|
|
|
|
#[wasm_bindgen(js_name = RequestMintResponse)]
|
|
#[wasm_bindgen(js_name = RequestMintResponse)]
|
|
pub struct JsRequestMintResponse {
|
|
pub struct JsRequestMintResponse {
|
|
@@ -47,3 +48,102 @@ impl JsRequestMintResponse {
|
|
self.inner.hash.to_string()
|
|
self.inner.hash.to_string()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+#[wasm_bindgen(js_name = SplitRequest)]
|
|
|
|
+pub struct JsSplitRequest {
|
|
|
|
+ inner: SplitRequest,
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+impl Deref for JsSplitRequest {
|
|
|
|
+ type Target = SplitRequest;
|
|
|
|
+ fn deref(&self) -> &Self::Target {
|
|
|
|
+ &self.inner
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+impl From<SplitRequest> for JsSplitRequest {
|
|
|
|
+ fn from(inner: SplitRequest) -> JsSplitRequest {
|
|
|
|
+ JsSplitRequest { inner }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#[wasm_bindgen(js_class = SplitRequest)]
|
|
|
|
+impl JsSplitRequest {
|
|
|
|
+ #[wasm_bindgen(constructor)]
|
|
|
|
+ pub fn new(inputs: JsValue, outputs: JsValue) -> Result<JsSplitRequest> {
|
|
|
|
+ let inputs = serde_wasm_bindgen::from_value(inputs).map_err(into_err)?;
|
|
|
|
+ let outputs = serde_wasm_bindgen::from_value(outputs).map_err(into_err)?;
|
|
|
|
+
|
|
|
|
+ Ok(JsSplitRequest {
|
|
|
|
+ inner: SplitRequest { inputs, outputs },
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// Get Proofs
|
|
|
|
+ #[wasm_bindgen(getter)]
|
|
|
|
+ pub fn proofs(&self) -> Result<JsValue> {
|
|
|
|
+ serde_wasm_bindgen::to_value(&self.inner.inputs).map_err(into_err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// Get Outputs
|
|
|
|
+ #[wasm_bindgen(getter)]
|
|
|
|
+ pub fn outputs(&self) -> Result<JsValue> {
|
|
|
|
+ serde_wasm_bindgen::to_value(&self.inner.outputs).map_err(into_err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// Proofs Amount
|
|
|
|
+ #[wasm_bindgen(js_name = proofsAmount)]
|
|
|
|
+ pub fn proofs_amount(&self) -> JsAmount {
|
|
|
|
+ self.inner.input_amount().into()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// Output Amount
|
|
|
|
+ #[wasm_bindgen(js_name = outputAmount)]
|
|
|
|
+ pub fn output_amount(&self) -> JsAmount {
|
|
|
|
+ self.inner.output_amount().into()
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#[wasm_bindgen(js_name = SplitResponse)]
|
|
|
|
+pub struct JsSplitResponse {
|
|
|
|
+ inner: SplitResponse,
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+impl Deref for JsSplitResponse {
|
|
|
|
+ type Target = SplitResponse;
|
|
|
|
+ fn deref(&self) -> &Self::Target {
|
|
|
|
+ &self.inner
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+impl From<SplitResponse> for JsSplitResponse {
|
|
|
|
+ fn from(inner: SplitResponse) -> JsSplitResponse {
|
|
|
|
+ JsSplitResponse { inner }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#[wasm_bindgen(js_class = SplitResponse)]
|
|
|
|
+impl JsSplitResponse {
|
|
|
|
+ #[wasm_bindgen(constructor)]
|
|
|
|
+ pub fn new(promises: JsValue) -> Result<JsSplitResponse> {
|
|
|
|
+ let promises = serde_wasm_bindgen::from_value(promises).map_err(into_err)?;
|
|
|
|
+
|
|
|
|
+ Ok(JsSplitResponse {
|
|
|
|
+ inner: SplitResponse {
|
|
|
|
+ promises: Some(promises),
|
|
|
|
+ },
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// Get Promises
|
|
|
|
+ #[wasm_bindgen(getter)]
|
|
|
|
+ pub fn promises(&self) -> Result<JsValue> {
|
|
|
|
+ serde_wasm_bindgen::to_value(&self.inner.promises).map_err(into_err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// Promises Amount
|
|
|
|
+ #[wasm_bindgen(js_name = promisesAmount)]
|
|
|
|
+ pub fn promises_amount(&self) -> Option<JsAmount> {
|
|
|
|
+ self.inner.promises_amount().map(|a| a.into())
|
|
|
|
+ }
|
|
|
|
+}
|