diff --git a/packages/account_sdk/src/controller.rs b/packages/account_sdk/src/controller.rs index c742f8e5b..8647b40e0 100644 --- a/packages/account_sdk/src/controller.rs +++ b/packages/account_sdk/src/controller.rs @@ -99,6 +99,7 @@ impl Controller { .storage .set_controller( app_id.as_str(), + &chain_id, address, ControllerMetadata::from(&controller), ) diff --git a/packages/account_sdk/src/storage/mod.rs b/packages/account_sdk/src/storage/mod.rs index 78d5f6677..3ae57de49 100644 --- a/packages/account_sdk/src/storage/mod.rs +++ b/packages/account_sdk/src/storage/mod.rs @@ -223,6 +223,7 @@ pub struct Credentials { #[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)] pub struct ActiveMetadata { address: Felt, + chain_id: Felt, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -256,7 +257,10 @@ pub trait StorageBackend: Send + Sync { self.get(&selectors::Selectors::active(app_id)) .and_then(|value| match value { Some(StorageValue::Active(metadata)) => self - .get(&selectors::Selectors::account(&metadata.address)) + .get(&selectors::Selectors::account( + &metadata.address, + &metadata.chain_id, + )) .and_then(|value| match value { Some(StorageValue::Controller(metadata)) => Ok(Some(metadata)), Some(_) => Err(StorageError::TypeMismatch), @@ -270,15 +274,19 @@ pub trait StorageBackend: Send + Sync { fn set_controller( &mut self, app_id: &str, + chain_id: &Felt, address: Felt, metadata: ControllerMetadata, ) -> Result<(), StorageError> { self.set( &selectors::Selectors::active(app_id), - &StorageValue::Active(ActiveMetadata { address }), + &StorageValue::Active(ActiveMetadata { + address, + chain_id: *chain_id, + }), )?; self.set( - &selectors::Selectors::account(&address), + &selectors::Selectors::account(&address, chain_id), &StorageValue::Controller(metadata), ) } diff --git a/packages/account_sdk/src/storage/selectors.rs b/packages/account_sdk/src/storage/selectors.rs index 2808942b1..40d1f46cc 100644 --- a/packages/account_sdk/src/storage/selectors.rs +++ b/packages/account_sdk/src/storage/selectors.rs @@ -7,8 +7,8 @@ impl Selectors { format!("@cartridge/{}/active", app_id) } - pub fn account(address: &Felt) -> String { - format!("@cartridge/account/0x{:x}", address) + pub fn account(address: &Felt, chain_id: &Felt) -> String { + format!("@cartridge/account/0x{:x}/0x{:x}", address, chain_id) } pub fn deployment(address: &Felt, chain_id: &Felt) -> String {