Skip to content

Commit

Permalink
feat: add backup and restore functionality (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
hydra-yse authored Apr 25, 2024
1 parent 8f35cee commit ecc211e
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 61 deletions.
20 changes: 10 additions & 10 deletions cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ pub(crate) enum Command {
GetInfo,
/// Empties the encrypted wallet transaction cache
EmptyCache,
/// Backs up the current pending swaps
Backup,
/// Retrieve a list of backups
Restore {
#[arg(short, long)]
backup_path: Option<String>,
},
}

#[derive(Helper, Completer, Hinter, Validator)]
Expand Down Expand Up @@ -146,6 +153,14 @@ pub(crate) fn handle_command(
wallet.empty_wallet_cache()?;
command_result!("Cache emptied successfully")
}
Command::Backup => {
wallet.backup()?;
command_result!("Backup created successfully!")
}
Command::Restore { backup_path } => {
wallet.restore(backup_path)?;
command_result!("Backup restored successfully!")
}
})
}

Expand Down
103 changes: 55 additions & 48 deletions lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ uniffi = "0.27.1"
uniffi_macros = "0.27.1"

[patch.crates-io]
secp256k1-zkp = {git = "https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git", rev = "60e631c24588a0c9e271badd61959294848c665d"}
secp256k1-zkp = {git = "https://github.com/BlockstreamResearch/rust-secp256k1-zkp.git", rev = "60e631c24588a0c9e271badd61959294848c665d"}
8 changes: 8 additions & 0 deletions lib/ls-sdk-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ impl BindingWallet {
) -> 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");
6 changes: 6 additions & 0 deletions lib/ls-sdk-bindings/src/ls_sdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,10 @@ interface BindingWallet {

[Throws=PaymentError]
ReceivePaymentResponse receive_payment(PrepareReceiveResponse req);

[Throws=LsSdkError]
void backup();

[Throws=LsSdkError]
void restore(string? backup_path);
};
Loading

0 comments on commit ecc211e

Please sign in to comment.