Skip to content

Commit

Permalink
improve: add missing derefs and from
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Oct 3, 2023
1 parent 17c6bc5 commit 449fe83
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 12 deletions.
5 changes: 5 additions & 0 deletions bindings/cashu-ffi/src/cashu.udl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ interface CashuError {
Generic(string err);
};

// Types

interface Bolt11Invoice {
[Throws=CashuError]
constructor(string bolt11);
Expand All @@ -27,6 +29,9 @@ interface Secret {
sequence<u8> as_bytes();
};


// NUT00

interface Id {
[Throws=CashuError]
constructor(string id);
Expand Down
1 change: 1 addition & 0 deletions bindings/cashu-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions bindings/cashu-ffi/src/types/bolt11_invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions bindings/cashu-ffi/src/types/proofs_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions bindings/cashu-sdk-ffi/src/cashu_sdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ interface CashuError {
};


// Types

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


interface Id {
[Throws=CashuError]
constructor(string id);
Expand Down
7 changes: 6 additions & 1 deletion bindings/cashu-sdk-ffi/src/types/melted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 12 additions & 2 deletions bindings/cashu-sdk-ffi/src/types/proofs_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 16 additions & 9 deletions bindings/cashu-sdk-ffi/src/types/send_proofs.rs
Original file line number Diff line number Diff line change
@@ -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())
Expand Down Expand Up @@ -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 }
}
}

0 comments on commit 449fe83

Please sign in to comment.