Skip to content

Refactor CLI app to handle BreezServices lifetime #1213

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

Merged
merged 1 commit into from
May 12, 2025

Conversation

andrei-21
Copy link
Collaborator

* Stop using the static variable since they are not dropped:
  https://doc.rust-lang.org/reference/items/static-items.html#r-items.static.lifetime
* Add an `abort` command to mimic crash behaviors (useful for testing)
Copy link
Member

@roeierez roeierez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just a few comments around connect/disconnect


async fn connect(&mut self, req: ConnectRequest) -> Result<()> {
let service = BreezServices::connect(req, Box::new(CliEventListener {})).await?;
ensure!(self.sdk.is_none(), "Breez Services already initialized");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps better to validate before we connect?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Ok(format!("Closing transaction ids:\n{tx_ids:?}"))
}
Commands::Disconnect {} => {
self.sdk()?.disconnect().await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that it is not static anymore I think it would be nice to nullify the sdk instance allowing the user to re-connect again.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@roeierez roeierez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@roeierez roeierez requested a review from JssDWt May 12, 2025 15:19
@JssDWt JssDWt requested a review from Copilot May 12, 2025 19:47
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the CLI app to remove the static BreezServices, replacing it with a properly scoped CommandHandler that manages the services’ lifecycle, and adds an abort command for testing crash behaviors.

  • Refactored the command handling by creating a CommandHandler struct and updating its associated methods.
  • Removed the static variable for BreezServices and added a new connect method to manage its lifecycle.
  • Introduced a new Abort command to simulate a crash for testing purposes.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tools/sdk-cli/src/main.rs Updated to instantiate and use CommandHandler instead of a static function.
tools/sdk-cli/src/commands.rs Added a new Abort command for immediate termination.
tools/sdk-cli/src/command_handlers.rs Refactored BreezServices usage by replacing static initialization with a CommandHandler struct and updated command handling logic.

Copy link
Contributor

@JssDWt JssDWt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@JssDWt JssDWt merged commit e4d9e68 into breez:main May 12, 2025
10 checks passed
@andrei-21 andrei-21 deleted the feature/drop-sdk branch May 13, 2025 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants