mirror of
https://github.com/aljazceru/cdk.git
synced 2026-01-09 16:05:40 +01:00
bindings/cashu Bolt11Invoice ffi type
This commit is contained in:
@@ -5,6 +5,13 @@ interface CashuError {
|
||||
Generic(string err);
|
||||
};
|
||||
|
||||
interface Bolt11Invoice {
|
||||
[Throws=CashuError]
|
||||
constructor(string bolt11);
|
||||
string as_string();
|
||||
Amount? amount();
|
||||
};
|
||||
|
||||
interface Amount {
|
||||
u64 to_sat();
|
||||
u64 to_msat();
|
||||
|
||||
@@ -26,6 +26,7 @@ mod ffi {
|
||||
pub use crate::nuts::nut08::{MeltRequest, MeltResponse};
|
||||
pub use crate::nuts::nut09::{MintInfo, MintVersion};
|
||||
pub use crate::types::amount::Amount;
|
||||
pub use crate::types::Bolt11Invoice;
|
||||
pub use cashu::types::InvoiceStatus;
|
||||
|
||||
// UDL
|
||||
|
||||
34
bindings/cashu-ffi/src/types/bolt11_invoice.rs
Normal file
34
bindings/cashu-ffi/src/types/bolt11_invoice.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use std::{ops::Deref, str::FromStr, sync::Arc};
|
||||
|
||||
use cashu::Bolt11Invoice as Bolt11InvoiceSdk;
|
||||
|
||||
use crate::{error::Result, Amount};
|
||||
|
||||
pub struct Bolt11Invoice {
|
||||
inner: Bolt11InvoiceSdk,
|
||||
}
|
||||
|
||||
impl Deref for Bolt11Invoice {
|
||||
type Target = Bolt11InvoiceSdk;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl Bolt11Invoice {
|
||||
pub fn new(bolt11: String) -> Result<Self> {
|
||||
Ok(Self {
|
||||
inner: Bolt11InvoiceSdk::from_str(&bolt11)?,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn as_string(&self) -> String {
|
||||
self.inner.to_string()
|
||||
}
|
||||
|
||||
pub fn amount(&self) -> Option<Arc<Amount>> {
|
||||
self.inner
|
||||
.amount_milli_satoshis()
|
||||
.map(|a| Arc::new(Amount::from_msat(a)))
|
||||
}
|
||||
}
|
||||
@@ -1 +1,4 @@
|
||||
pub mod amount;
|
||||
pub mod bolt11_invoice;
|
||||
|
||||
pub use bolt11_invoice::Bolt11Invoice;
|
||||
|
||||
Reference in New Issue
Block a user