From c303e8d8495857b161aa8e68b49494a32645b4d3 Mon Sep 17 00:00:00 2001 From: Tyler Cook <10459406+cilki@users.noreply.github.com> Date: Sun, 9 Jun 2024 15:23:31 -0500 Subject: [PATCH] impl: add restore_deterministic_wallet --- src/lib.rs | 24 ++++++++++++++++++++++++ src/models.rs | 25 +++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index f3c3b00..eab522b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { + 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( diff --git a/src/models.rs b/src/models.rs index 3d98065..58722e9 100644 --- a/src/models.rs +++ b/src/models.rs @@ -374,6 +374,31 @@ pub struct GenerateFromKeysArgs { pub autosave_current: Option, } +/// Argument type of wallet `restore_deterministic_wallet`. +#[derive(Clone, Debug)] +pub struct RestoreDeterministicWalletArgs { + pub autosave_current: Option, + pub filename: String, + pub password: String, + pub restore_height: Option, + pub seed: String, + pub seed_offset: Option, +} + +/// 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 {