From 6d97688b7e611b6e297309ec30fb82e8ee96a00d Mon Sep 17 00:00:00 2001 From: jjy Date: Mon, 16 Dec 2024 12:24:41 +0800 Subject: [PATCH] Fix store versioned value instead of changeset --- mutiny-core/src/storage.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/mutiny-core/src/storage.rs b/mutiny-core/src/storage.rs index 66bd01bb4..cdcbeaa55 100644 --- a/mutiny-core/src/storage.rs +++ b/mutiny-core/src/storage.rs @@ -522,22 +522,29 @@ pub trait MutinyStorage: Clone + Sized + Send + Sync + 'static { } let version = now().as_secs() as u32; - match self.get_data::(KEYCHAIN_STORE_KEY)? { + let value = match self.get_data::(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, MutinyError> { - self.get_data(KEYCHAIN_STORE_KEY) + match self.get_data::(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