mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2026-01-09 09:04:27 +01:00
Revert "Apply frb's file structure changes to ls-sdk-bindings"
This commit is contained in:
@@ -1 +1,81 @@
|
||||
pub mod uniffi_bindings;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{Error, Result};
|
||||
use ls_sdk::{
|
||||
error::PaymentError,
|
||||
model::{
|
||||
Network, PrepareReceiveRequest, PrepareReceiveResponse, PrepareSendResponse,
|
||||
ReceivePaymentResponse, SendPaymentResponse, WalletInfo,
|
||||
},
|
||||
wallet::Wallet,
|
||||
};
|
||||
|
||||
// TODO Unify error enum
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum LsSdkError {
|
||||
#[error("Error: {err}")]
|
||||
Generic { err: String },
|
||||
}
|
||||
|
||||
impl From<anyhow::Error> for LsSdkError {
|
||||
fn from(e: Error) -> Self {
|
||||
LsSdkError::Generic { err: e.to_string() }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init(
|
||||
mnemonic: String,
|
||||
data_dir: Option<String>,
|
||||
network: Network,
|
||||
) -> Result<Arc<BindingWallet>, LsSdkError> {
|
||||
let ln_sdk = Wallet::init(&mnemonic, data_dir, network)?;
|
||||
Ok(Arc::from(BindingWallet { ln_sdk }))
|
||||
}
|
||||
|
||||
pub struct BindingWallet {
|
||||
ln_sdk: Arc<Wallet>,
|
||||
}
|
||||
|
||||
impl BindingWallet {
|
||||
pub fn get_info(&self, with_scan: bool) -> Result<WalletInfo, LsSdkError> {
|
||||
self.ln_sdk.get_info(with_scan).map_err(Into::into)
|
||||
}
|
||||
|
||||
pub fn prepare_send_payment(
|
||||
&self,
|
||||
invoice: String,
|
||||
) -> Result<PrepareSendResponse, PaymentError> {
|
||||
self.ln_sdk.prepare_send_payment(&invoice)
|
||||
}
|
||||
|
||||
pub fn send_payment(
|
||||
&self,
|
||||
req: PrepareSendResponse,
|
||||
) -> Result<SendPaymentResponse, PaymentError> {
|
||||
self.ln_sdk.send_payment(&req)
|
||||
}
|
||||
|
||||
pub fn prepare_receive_payment(
|
||||
&self,
|
||||
req: PrepareReceiveRequest,
|
||||
) -> Result<PrepareReceiveResponse, PaymentError> {
|
||||
self.ln_sdk.prepare_receive_payment(&req)
|
||||
}
|
||||
|
||||
pub fn receive_payment(
|
||||
&self,
|
||||
req: PrepareReceiveResponse,
|
||||
) -> Result<ReceivePaymentResponse, PaymentError> {
|
||||
self.ln_sdk.receive_payment(&req)
|
||||
}
|
||||
|
||||
pub fn backup(&self) -> Result<(), LsSdkError> {
|
||||
self.ln_sdk.backup().map_err(Into::into)
|
||||
}
|
||||
|
||||
pub fn restore(&self, backup_path: Option<String>) -> Result<(), LsSdkError> {
|
||||
self.ln_sdk.restore(backup_path).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
uniffi::include_scaffolding!("ls_sdk");
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{Error, Result};
|
||||
use ls_sdk::{
|
||||
error::PaymentError,
|
||||
model::{
|
||||
Network, PrepareReceiveRequest, PrepareReceiveResponse, PrepareSendResponse,
|
||||
ReceivePaymentResponse, SendPaymentResponse, WalletInfo,
|
||||
},
|
||||
wallet::Wallet,
|
||||
};
|
||||
|
||||
// TODO Unify error enum
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum LsSdkError {
|
||||
#[error("Error: {err}")]
|
||||
Generic { err: String },
|
||||
}
|
||||
|
||||
impl From<anyhow::Error> for LsSdkError {
|
||||
fn from(e: Error) -> Self {
|
||||
LsSdkError::Generic { err: e.to_string() }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn connect(
|
||||
mnemonic: String,
|
||||
data_dir: Option<String>,
|
||||
network: Network,
|
||||
) -> Result<Arc<BindingWallet>, LsSdkError> {
|
||||
let ln_sdk = Wallet::connect(&mnemonic, data_dir, network)?;
|
||||
Ok(Arc::from(BindingWallet { ln_sdk }))
|
||||
}
|
||||
|
||||
pub struct BindingWallet {
|
||||
ln_sdk: Arc<Wallet>,
|
||||
}
|
||||
|
||||
impl BindingWallet {
|
||||
pub fn get_info(&self, with_scan: bool) -> Result<WalletInfo, LsSdkError> {
|
||||
self.ln_sdk.get_info(with_scan).map_err(Into::into)
|
||||
}
|
||||
|
||||
pub fn prepare_send_payment(
|
||||
&self,
|
||||
invoice: String,
|
||||
) -> Result<PrepareSendResponse, PaymentError> {
|
||||
self.ln_sdk.prepare_send_payment(&invoice)
|
||||
}
|
||||
|
||||
pub fn send_payment(
|
||||
&self,
|
||||
req: PrepareSendResponse,
|
||||
) -> Result<SendPaymentResponse, PaymentError> {
|
||||
self.ln_sdk.send_payment(&req)
|
||||
}
|
||||
|
||||
pub fn prepare_receive_payment(
|
||||
&self,
|
||||
req: PrepareReceiveRequest,
|
||||
) -> Result<PrepareReceiveResponse, PaymentError> {
|
||||
self.ln_sdk.prepare_receive_payment(&req)
|
||||
}
|
||||
|
||||
pub fn receive_payment(
|
||||
&self,
|
||||
req: PrepareReceiveResponse,
|
||||
) -> Result<ReceivePaymentResponse, PaymentError> {
|
||||
self.ln_sdk.receive_payment(&req)
|
||||
}
|
||||
|
||||
pub fn backup(&self) -> Result<(), LsSdkError> {
|
||||
self.ln_sdk.backup().map_err(Into::into)
|
||||
}
|
||||
|
||||
pub fn restore(&self, backup_path: Option<String>) -> Result<(), LsSdkError> {
|
||||
self.ln_sdk.restore(backup_path).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
uniffi::include_scaffolding!("ls_sdk");
|
||||
Reference in New Issue
Block a user