mirror of
https://github.com/aljazceru/cdk.git
synced 2026-02-06 13:45:53 +01:00
bindings/cashu-js clippy
This commit is contained in:
@@ -7,3 +7,4 @@ mod nut05;
|
||||
mod nut06;
|
||||
mod nut07;
|
||||
mod nut08;
|
||||
mod nut09;
|
||||
|
||||
@@ -31,7 +31,7 @@ impl JsBlindedMessage {
|
||||
pub fn new(amount: JsAmount, b: JsPublicKey) -> Self {
|
||||
Self {
|
||||
inner: BlindedMessage {
|
||||
amount: amount.deref().clone(),
|
||||
amount: *amount.deref(),
|
||||
b: b.deref().clone(),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ impl JsBlindedSignature {
|
||||
pub fn new(id: JsId, amount: JsAmount, c: JsPublicKey) -> Self {
|
||||
Self {
|
||||
inner: BlindedSignature {
|
||||
id: id.deref().clone(),
|
||||
amount: amount.deref().clone(),
|
||||
id: *id.deref(),
|
||||
amount: *amount.deref(),
|
||||
c: c.deref().clone(),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ impl JsProof {
|
||||
pub fn new(amount: JsAmount, secret: JsSecret, c: JsPublicKey, id: Option<JsId>) -> JsProof {
|
||||
Self {
|
||||
inner: Proof {
|
||||
amount: amount.deref().clone(),
|
||||
amount: *amount.deref(),
|
||||
secret: secret.deref().clone(),
|
||||
c: c.deref().clone(),
|
||||
id: id.map(|i| *i.deref()),
|
||||
|
||||
@@ -52,7 +52,7 @@ impl JsToken {
|
||||
/// As String
|
||||
#[wasm_bindgen(js_name = asString)]
|
||||
pub fn as_string(&self) -> Result<String> {
|
||||
Ok(self.inner.convert_to_string().map_err(into_err)?)
|
||||
self.inner.convert_to_string().map_err(into_err)
|
||||
}
|
||||
|
||||
// TODO: Getter mint proofs
|
||||
|
||||
@@ -43,7 +43,7 @@ impl JsKeys {
|
||||
/// Keys
|
||||
#[wasm_bindgen(js_name = keys)]
|
||||
pub fn keys(&self) -> Result<String> {
|
||||
Ok(serde_json::to_string(&self.inner.keys()).map_err(into_err)?)
|
||||
serde_json::to_string(&self.inner.keys()).map_err(into_err)
|
||||
}
|
||||
|
||||
/// Amount Key
|
||||
|
||||
@@ -77,7 +77,7 @@ impl JsKeySet {
|
||||
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn id(&self) -> JsId {
|
||||
self.inner.id.clone().into()
|
||||
self.inner.id.into()
|
||||
}
|
||||
|
||||
#[wasm_bindgen(getter)]
|
||||
|
||||
@@ -39,7 +39,7 @@ impl JsMintRequest {
|
||||
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn outputs(&self) -> Result<String> {
|
||||
Ok(serde_json::to_string(&self.inner.outputs).map_err(into_err)?)
|
||||
serde_json::to_string(&self.inner.outputs).map_err(into_err)
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = totalAmount)]
|
||||
@@ -79,6 +79,6 @@ impl JsPostMintResponse {
|
||||
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn promises(&self) -> Result<String> {
|
||||
Ok(serde_json::to_string(&self.inner.promises).map_err(into_err)?)
|
||||
serde_json::to_string(&self.inner.promises).map_err(into_err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ impl JsCheckFeesRequest {
|
||||
pub fn new(invoice: JsBolt11Invoice) -> Result<JsCheckFeesRequest> {
|
||||
Ok(JsCheckFeesRequest {
|
||||
inner: CheckFeesRequest {
|
||||
pr: invoice.clone().into(),
|
||||
pr: invoice.clone(),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -45,13 +45,13 @@ impl JsSplitRequest {
|
||||
/// Get Proofs
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn proofs(&self) -> Result<String> {
|
||||
Ok(serde_json::to_string(&self.inner.proofs).map_err(into_err)?)
|
||||
serde_json::to_string(&self.inner.proofs).map_err(into_err)
|
||||
}
|
||||
|
||||
/// Get Outputs
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn outputs(&self) -> Result<String> {
|
||||
Ok(serde_json::to_string(&self.inner.outputs).map_err(into_err)?)
|
||||
serde_json::to_string(&self.inner.outputs).map_err(into_err)
|
||||
}
|
||||
|
||||
/// Proofs Amount
|
||||
@@ -103,7 +103,7 @@ impl JsSplitResponse {
|
||||
/// Get Promises
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn promises(&self) -> Result<String> {
|
||||
Ok(serde_json::to_string(&self.inner.promises).map_err(into_err)?)
|
||||
serde_json::to_string(&self.inner.promises).map_err(into_err)
|
||||
}
|
||||
|
||||
/// Promises Amount
|
||||
|
||||
@@ -39,7 +39,7 @@ impl JsCheckSpendableRequest {
|
||||
#[wasm_bindgen(getter)]
|
||||
// REVIEW: INTO Serde
|
||||
pub fn proofs(&self) -> Result<String> {
|
||||
Ok(serde_json::to_string(&self.inner.proofs).map_err(into_err)?)
|
||||
serde_json::to_string(&self.inner.proofs).map_err(into_err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ impl JsMeltRequest {
|
||||
/// Get Proofs
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn proofs(&self) -> Result<JsValue> {
|
||||
Ok(serde_wasm_bindgen::to_value(&self.inner.proofs).map_err(into_err)?)
|
||||
serde_wasm_bindgen::to_value(&self.inner.proofs).map_err(into_err)
|
||||
}
|
||||
|
||||
/// Get Invoice
|
||||
@@ -68,7 +68,7 @@ impl JsMeltRequest {
|
||||
/// Get outputs
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn outputs(&self) -> Result<JsValue> {
|
||||
Ok(serde_wasm_bindgen::to_value(&self.inner.outputs).map_err(into_err)?)
|
||||
serde_wasm_bindgen::to_value(&self.inner.outputs).map_err(into_err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,11 +124,11 @@ impl JsMeltResponse {
|
||||
/// Get Change
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn change(&self) -> Result<JsValue> {
|
||||
Ok(serde_wasm_bindgen::to_value(&self.inner.change).map_err(into_err)?)
|
||||
serde_wasm_bindgen::to_value(&self.inner.change).map_err(into_err)
|
||||
}
|
||||
|
||||
/// Change Amount
|
||||
#[wasm_bindgen(js_name = "cahngeAmount")]
|
||||
#[wasm_bindgen(js_name = "changeAmount")]
|
||||
pub fn change_amount(&self) -> JsAmount {
|
||||
self.inner.change_amount().into()
|
||||
}
|
||||
|
||||
143
bindings/cashu-js/src/nuts/nut09.rs
Normal file
143
bindings/cashu-js/src/nuts/nut09.rs
Normal file
@@ -0,0 +1,143 @@
|
||||
use std::ops::Deref;
|
||||
|
||||
use cashu::nuts::nut09::{MintInfo, MintVersion};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
use crate::error::{into_err, Result};
|
||||
|
||||
use super::nut01::JsPublicKey;
|
||||
|
||||
#[wasm_bindgen(js_name = MintVersion)]
|
||||
pub struct JsMintVersion {
|
||||
inner: MintVersion,
|
||||
}
|
||||
|
||||
impl Deref for JsMintVersion {
|
||||
type Target = MintVersion;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MintVersion> for JsMintVersion {
|
||||
fn from(inner: MintVersion) -> JsMintVersion {
|
||||
JsMintVersion { inner }
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_class = MintVersion)]
|
||||
impl JsMintVersion {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(name: String, version: String) -> Result<JsMintVersion> {
|
||||
Ok(JsMintVersion {
|
||||
inner: MintVersion { name, version },
|
||||
})
|
||||
}
|
||||
|
||||
/// Get Name
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn name(&self) -> String {
|
||||
self.inner.name.clone()
|
||||
}
|
||||
|
||||
/// Get Name
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn version(&self) -> String {
|
||||
self.inner.version.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = MintVersion)]
|
||||
pub struct JsMintInfo {
|
||||
inner: MintInfo,
|
||||
}
|
||||
|
||||
impl Deref for JsMintInfo {
|
||||
type Target = MintInfo;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MintInfo> for JsMintInfo {
|
||||
fn from(inner: MintInfo) -> JsMintInfo {
|
||||
JsMintInfo { inner }
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_class = MintVersion)]
|
||||
impl JsMintInfo {
|
||||
#[wasm_bindgen(constructor)]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
name: Option<String>,
|
||||
pubkey: Option<JsPublicKey>,
|
||||
version: Option<JsMintVersion>,
|
||||
description: Option<String>,
|
||||
description_long: Option<String>,
|
||||
contact: JsValue,
|
||||
nuts: JsValue,
|
||||
motd: Option<String>,
|
||||
) -> Result<JsMintInfo> {
|
||||
Ok(JsMintInfo {
|
||||
inner: MintInfo {
|
||||
name,
|
||||
pubkey: pubkey.map(|p| p.deref().clone()),
|
||||
version: version.map(|v| v.deref().clone()),
|
||||
description,
|
||||
description_long,
|
||||
contact: serde_wasm_bindgen::from_value(contact).map_err(into_err)?,
|
||||
nuts: serde_wasm_bindgen::from_value(nuts).map_err(into_err)?,
|
||||
motd,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/// Get Name
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn name(&self) -> Option<String> {
|
||||
self.inner.name.clone()
|
||||
}
|
||||
|
||||
/// Get Pubkey
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn pubkey(&self) -> Option<JsPublicKey> {
|
||||
self.inner.pubkey.clone().map(|p| p.into())
|
||||
}
|
||||
|
||||
/// Get Name
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn version(&self) -> Option<JsMintVersion> {
|
||||
self.inner.version.clone().map(|v| v.into())
|
||||
}
|
||||
|
||||
/// Get description
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn description(&self) -> Option<String> {
|
||||
self.inner.description.clone()
|
||||
}
|
||||
|
||||
/// Get description long
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn description_long(&self) -> Option<String> {
|
||||
self.inner.description_long.clone()
|
||||
}
|
||||
|
||||
/// Get contact
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn contact(&self) -> Result<JsValue> {
|
||||
serde_wasm_bindgen::to_value(&self.inner.contact).map_err(into_err)
|
||||
}
|
||||
|
||||
/// Get supported nuts
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn nuts(&self) -> Result<JsValue> {
|
||||
serde_wasm_bindgen::to_value(&self.inner.nuts).map_err(into_err)
|
||||
}
|
||||
|
||||
/// Get motd
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn motd(&self) -> Option<String> {
|
||||
self.inner.motd.clone()
|
||||
}
|
||||
}
|
||||
@@ -36,9 +36,7 @@ impl JsBolt11Invoice {
|
||||
/// Amount
|
||||
#[wasm_bindgen(getter)]
|
||||
pub fn amount(&self) -> Option<JsAmount> {
|
||||
self.inner
|
||||
.amount_milli_satoshis()
|
||||
.map(|a| JsAmount::from_msat(a))
|
||||
self.inner.amount_milli_satoshis().map(JsAmount::from_msat)
|
||||
}
|
||||
|
||||
/// Invoice as string
|
||||
|
||||
@@ -8,6 +8,12 @@ pub struct JsSecret {
|
||||
inner: Secret,
|
||||
}
|
||||
|
||||
impl Default for JsSecret {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for JsSecret {
|
||||
type Target = Secret;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
|
||||
Reference in New Issue
Block a user