Skip to content

Commit

Permalink
Fix store versioned value instead of changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyr committed Dec 16, 2024
1 parent f409a71 commit 6d97688
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions mutiny-core/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,22 +522,29 @@ pub trait MutinyStorage: Clone + Sized + Send + Sync + 'static {
}

let version = now().as_secs() as u32;
match self.get_data::<ChangeSet>(KEYCHAIN_STORE_KEY)? {
let value = match self.get_data::<ChangeSet>(KEYCHAIN_STORE_KEY)? {
Some(mut keychain_store) => {
keychain_store.merge(changeset.clone());
self.write_data(
KEYCHAIN_STORE_KEY.to_string(),
keychain_store,
Some(version),
)
let value = serde_json::to_value(keychain_store)?;
VersionedValue { value, version }
}
None => self.write_data(KEYCHAIN_STORE_KEY.to_string(), changeset, Some(version)),
}
None => {
let value = serde_json::to_value(changeset)?;
VersionedValue { value, version }
}
};
self.write_data(KEYCHAIN_STORE_KEY.to_string(), value, Some(version))
}

/// Read Wallet changeset
fn read_changes(&self) -> Result<Option<ChangeSet>, MutinyError> {
self.get_data(KEYCHAIN_STORE_KEY)
match self.get_data::<VersionedValue>(KEYCHAIN_STORE_KEY)? {
Some(versioned) => {
let changeset = serde_json::from_value(versioned.value)?;
Ok(Some(changeset))
}
None => Ok(None),
}
}

/// Spawn background task to run db tasks
Expand Down

0 comments on commit 6d97688

Please sign in to comment.