Skip to content

Commit

Permalink
impl: add restore_deterministic_wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
cilki committed Jun 9, 2024
1 parent 11f9de9 commit c303e8d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,30 @@ impl WalletClient {
.await
}

/// Restore a wallet from an existing mnemonic phrase. Requires the rpc
/// wallet to run with the `--wallet-dir` argument.
pub async fn restore_deterministic_wallet(
&self,
args: RestoreDeterministicWalletArgs,
) -> anyhow::Result<WalletRestoration> {
let params = empty()
.chain(args.restore_height.map(|v| ("restore_height", v.into())))
.chain(once(("filename", args.filename.into())))
.chain(once(("seed", args.seed.into())))
.chain(
args.seed_offset
.map(|v| ("seed_offset", v.to_string().into())),
)
.chain(once(("password", args.password.into())))
.chain(
args.autosave_current
.map(|v| ("autosave_current", v.into())),
);
self.inner
.request("restore_deterministic_wallet", RpcParams::map(params))
.await
}

/// Create a new wallet. You need to have set the argument `--wallet-dir` when launching
/// monero-wallet-rpc to make this work.
pub async fn create_wallet(
Expand Down
25 changes: 25 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,31 @@ pub struct GenerateFromKeysArgs {
pub autosave_current: Option<bool>,
}

/// Argument type of wallet `restore_deterministic_wallet`.
#[derive(Clone, Debug)]
pub struct RestoreDeterministicWalletArgs {
pub autosave_current: Option<bool>,
pub filename: String,
pub password: String,
pub restore_height: Option<u64>,
pub seed: String,
pub seed_offset: Option<String>,
}

/// Return type of wallet `restore_deterministic_wallet`.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct WalletRestoration {
/// Generated wallet address.
pub address: Address,
/// Info on generated wallet.
pub info: String,
/// The mnemonic seed phrase.
pub seed: String,
/// Indicates whether the seed provided to `restore_deterministic_wallet` has
/// been updated from a deprecated format.
pub was_deprecated: bool,
}

/// Return sub-type of wallet `get_accounts`.
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct GotAccount {
Expand Down

0 comments on commit c303e8d

Please sign in to comment.