improve: add missing derefs and from

This commit is contained in:
thesimplekid
2023-10-03 07:15:45 +01:00
parent 17c6bc5f4b
commit 449fe8330c
8 changed files with 56 additions and 12 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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);

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 }
}
}