Browse Source

improve: add missing derefs and from

thesimplekid 1 year ago
parent
commit
449fe8330c

+ 5 - 0
bindings/cashu-ffi/src/cashu.udl

@@ -5,6 +5,8 @@ interface CashuError {
     Generic(string err);
 };
 
+// Types
+ 
 interface Bolt11Invoice {
     [Throws=CashuError]
     constructor(string bolt11);
@@ -27,6 +29,9 @@ interface Secret {
 	sequence<u8> as_bytes();	
 };
 
+
+// NUT00
+
 interface Id {
     [Throws=CashuError]
 	constructor(string id);

+ 1 - 0
bindings/cashu-ffi/src/lib.rs

@@ -28,6 +28,7 @@ mod ffi {
     pub use crate::types::amount::Amount;
     pub use crate::types::Bolt11Invoice;
     pub use crate::types::KeySetInfo;
+    pub use crate::types::ProofsStatus;
     pub use crate::types::Secret;
 
     pub use cashu::types::InvoiceStatus;

+ 6 - 0
bindings/cashu-ffi/src/types/bolt11_invoice.rs

@@ -15,6 +15,12 @@ impl Deref for Bolt11Invoice {
     }
 }
 
+impl From<Bolt11InvoiceSdk> for Bolt11Invoice {
+    fn from(inner: Bolt11InvoiceSdk) -> Bolt11Invoice {
+        Bolt11Invoice { inner }
+    }
+}
+
 impl Bolt11Invoice {
     pub fn new(bolt11: String) -> Result<Self> {
         Ok(Self {

+ 7 - 0
bindings/cashu-ffi/src/types/proofs_status.rs

@@ -8,6 +8,13 @@ pub struct ProofsStatus {
     inner: ProofsStatusSdk,
 }
 
+impl Deref for ProofsStatus {
+    type Target = ProofsStatusSdk;
+    fn deref(&self) -> &Self::Target {
+        &self.inner
+    }
+}
+
 impl ProofsStatus {
     pub fn new(spendable: Vec<Arc<MintProof>>, spent: Vec<Arc<MintProof>>) -> Self {
         Self {

+ 3 - 0
bindings/cashu-sdk-ffi/src/cashu_sdk.udl

@@ -8,6 +8,8 @@ interface CashuError {
 };
 
 
+// Types 
+
 interface Bolt11Invoice {
     [Throws=CashuError]
     constructor(string bolt11);
@@ -31,6 +33,7 @@ interface Secret {
 	sequence<u8> as_bytes();	
 };
 
+
 interface Id {
     [Throws=CashuError]
 	constructor(string id);

+ 6 - 1
bindings/cashu-sdk-ffi/src/types/melted.rs

@@ -8,7 +8,12 @@ pub struct Melted {
     inner: MeltedSdk,
 }
 
-// TODO: Deref
+impl Deref for Melted {
+    type Target = MeltedSdk;
+    fn deref(&self) -> &Self::Target {
+        &self.inner
+    }
+}
 
 impl From<cashu_sdk::types::Melted> for Melted {
     fn from(inner: cashu_sdk::types::Melted) -> Melted {

+ 12 - 2
bindings/cashu-sdk-ffi/src/types/proofs_status.rs

@@ -8,8 +8,18 @@ pub struct ProofsStatus {
     inner: ProofsStatusSdk,
 }
 
-// TODO: Into
-// TODO: Deref
+impl Deref for ProofsStatus {
+    type Target = ProofsStatusSdk;
+    fn deref(&self) -> &Self::Target {
+        &self.inner
+    }
+}
+
+impl From<ProofsStatusSdk> for ProofsStatus {
+    fn from(inner: ProofsStatusSdk) -> ProofsStatus {
+        ProofsStatus { inner }
+    }
+}
 
 impl ProofsStatus {
     pub fn new(spendable: Vec<Arc<MintProof>>, spent: Vec<Arc<MintProof>>) -> Self {

+ 16 - 9
bindings/cashu-sdk-ffi/src/types/send_proofs.rs

@@ -1,17 +1,30 @@
 use std::{ops::Deref, sync::Arc};
 
-use cashu_sdk::types::SendProofs as SendProofSdk;
+use cashu_sdk::types::SendProofs as SendProofsSdk;
 
 use cashu_ffi::Proof;
 
 pub struct SendProofs {
-    inner: SendProofSdk,
+    inner: SendProofsSdk,
+}
+
+impl Deref for SendProofs {
+    type Target = SendProofsSdk;
+    fn deref(&self) -> &Self::Target {
+        &self.inner
+    }
+}
+
+impl From<SendProofsSdk> for SendProofs {
+    fn from(inner: SendProofsSdk) -> SendProofs {
+        SendProofs { inner }
+    }
 }
 
 impl SendProofs {
     pub fn new(change_proofs: Vec<Arc<Proof>>, send_proofs: Vec<Arc<Proof>>) -> Self {
         Self {
-            inner: SendProofSdk {
+            inner: SendProofsSdk {
                 change_proofs: change_proofs
                     .iter()
                     .map(|p| p.as_ref().deref().clone())
@@ -42,9 +55,3 @@ impl SendProofs {
             .collect()
     }
 }
-
-impl From<cashu_sdk::types::SendProofs> for SendProofs {
-    fn from(inner: cashu_sdk::types::SendProofs) -> SendProofs {
-        SendProofs { inner }
-    }
-}