-
Notifications
You must be signed in to change notification settings - Fork 45
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
Conversation
* 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)
There was a problem hiding this 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"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
12c45c6
to
3dff48b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
abort
command to mimic crash behaviors (useful for testing)