Skip to content

Commit

Permalink
Vault is unsaved (dirty) when created from a random seed
Browse files Browse the repository at this point in the history
  • Loading branch information
wigy-opensource-developer committed Jun 30, 2022
1 parent 7e753d7 commit 719a207
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions sdk-wasm/src/vault/serializer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Cannot use typetags in wasm_bindgen, because it depends on module constructors. So as a workaround
//! until the https://github.com/mmastrac/rust-ctor/issues/14 issue is resolved.
//! until the <https://github.com/mmastrac/rust-ctor/issues/14> issue is resolved.
use super::*;

Expand Down Expand Up @@ -31,6 +31,6 @@ pub struct VaultSerializer {
impl From<VaultSerializer> for Vault {
fn from(mut ser: VaultSerializer) -> Self {
let plugins = ser.plugins.drain(..).map(|p| p.into()).collect::<Vec<_>>();
Self::new(ser.encrypted_seed, plugins)
Self::new(ser.encrypted_seed, plugins, false)
}
}
10 changes: 5 additions & 5 deletions vault/src/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ struct VaultImpl {
}

impl VaultImpl {
fn new(encrypted_seed: String, plugins: Vec<Box<dyn VaultPlugin>>) -> Self {
let is_dirty = false;
fn new(encrypted_seed: String, plugins: Vec<Box<dyn VaultPlugin>>, is_dirty: bool) -> Self {
Self { encrypted_seed, plugins, is_dirty }
}
}
Expand All @@ -39,8 +38,8 @@ pub struct Vault {
}

impl Vault {
pub fn new(encrypted_seed: String, plugins: Vec<Box<dyn VaultPlugin>>) -> Self {
let imp = VaultImpl::new(encrypted_seed, plugins);
pub fn new(encrypted_seed: String, plugins: Vec<Box<dyn VaultPlugin>>, dirty: bool) -> Self {
let imp = VaultImpl::new(encrypted_seed, plugins, dirty);
let inner = Arc::new(RwLock::new(imp));
Self { inner }
}
Expand All @@ -55,7 +54,8 @@ impl Vault {
};
let seed = bip39.phrase(phrase)?.password(bip39_password);
let encrypted_seed = Self::encrypt_seed(&seed, unlock_password.as_ref())?;
Ok(Self::new(encrypted_seed, Vec::new()))
let vault = Self::new(encrypted_seed, Vec::new(), true);
Ok(vault)
}

pub fn unlock(&self, unlock_password: &str) -> Result<Seed> {
Expand Down

0 comments on commit 719a207

Please sign in to comment.