Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrap breez services with replaceable variant #1112

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
wrap breez services with replaceable variant
If an app hibernates, the breez sdk may still run. However, any
connections to the outside world, like grpc connections will (may) stop
functioning. This means after hibernation the sdk needs to reconnect.
Hibernation is detected by awaiting a 'sleep' in a loop. If the sleep
has taken a long time, that means the app has been in hibernation.
Because many services have references to the node api, and other
services than the greenlight client may have been affected by
hibernation, the entire breezservices instance is recreated,
reconnected. In order to allow this, an internal variant of
breezservices was made. This internal instance can be replaced at any
time.

Because the breezservices code was moved to another file, with edits, I
took the liberty of putting all functions inside breezservices in
alphabetical order.
JssDWt committed Oct 26, 2024
commit f380049ee826898d203cee452e861c6077faefd9
6 changes: 3 additions & 3 deletions libs/sdk-bindings/src/uniffi_binding.rs
Original file line number Diff line number Diff line change
@@ -152,11 +152,11 @@ impl BlockingBreezServices {
}

pub fn node_credentials(&self) -> SdkResult<Option<NodeCredentials>> {
self.breez_services.node_credentials()
rt().block_on(self.breez_services.node_credentials())
}

pub fn node_info(&self) -> SdkResult<NodeState> {
self.breez_services.node_info()
rt().block_on(self.breez_services.node_info())
}

pub fn sign_message(&self, req: SignMessageRequest) -> SdkResult<SignMessageResponse> {
@@ -168,7 +168,7 @@ impl BlockingBreezServices {
}

pub fn backup_status(&self) -> SdkResult<BackupStatus> {
self.breez_services.backup_status()
rt().block_on(self.breez_services.backup_status())
}

pub fn backup(&self) -> SdkResult<()> {
2 changes: 1 addition & 1 deletion libs/sdk-core/src/backup.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
breez_services::BackupFailedData,
error::SdkResult,
internal_breez_services::BackupFailedData,
persist::db::{HookEvent, SqliteStorage},
BreezEvent, Config,
};
21 changes: 7 additions & 14 deletions libs/sdk-core/src/binding.rs
Original file line number Diff line number Diff line change
@@ -28,12 +28,13 @@ pub use sdk_common::prelude::{
};
use tokio::sync::Mutex;

use crate::breez_services::{self, BreezEvent, BreezServices, EventListener};
use crate::breez_services::{self, BreezServices};
use crate::chain::RecommendedFees;
use crate::error::{
ConnectError, ReceiveOnchainError, ReceivePaymentError, RedeemOnchainError, SdkError,
SendOnchainError, SendPaymentError,
};
use crate::internal_breez_services::{BreezEvent, EventListener};
use crate::lsp::LspInformation;
use crate::models::{Config, LogEntry, NodeState, Payment, SwapInfo};
use crate::{
@@ -332,22 +333,14 @@ pub fn sync() -> Result<()> {

/// See [BreezServices::node_credentials]
pub fn node_credentials() -> Result<Option<NodeCredentials>> {
block_on(async {
get_breez_services()
.await?
.node_credentials()
.map_err(anyhow::Error::new::<SdkError>)
})
block_on(async { get_breez_services().await?.node_credentials().await })
.map_err(anyhow::Error::new::<SdkError>)
}

/// See [BreezServices::node_info]
pub fn node_info() -> Result<NodeState> {
block_on(async {
get_breez_services()
.await?
.node_info()
.map_err(anyhow::Error::new::<SdkError>)
})
block_on(async { get_breez_services().await?.node_info().await })
.map_err(anyhow::Error::new::<SdkError>)
}

/// See [BreezServices::configure_node]
@@ -497,7 +490,7 @@ pub fn backup() -> Result<()> {

/// See [BreezServices::backup_status]
pub fn backup_status() -> Result<BackupStatus> {
block_on(async { get_breez_services().await?.backup_status() })
block_on(async { get_breez_services().await?.backup_status().await })
.map_err(anyhow::Error::new::<SdkError>)
}

Loading