Skip to content

Commit

Permalink
Add a way to get a DomainId from a RuntimeId
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Dec 23, 2024
1 parent a42d135 commit a6e5b8b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2117,6 +2117,15 @@ impl<T: Config> Pallet<T> {
.map(|domain_object| domain_object.domain_config.runtime_id)
}

pub fn domain_id(runtime_id: RuntimeId) -> Option<DomainId> {
RuntimeRegistry::<T>::get(runtime_id).and_then(|runtime_object| {
runtime_object
.raw_genesis
.domain_id()
.expect("DomainId must be valid since domain is insantiated; qed")
})
}

pub fn domain_instance_data(
domain_id: DomainId,
) -> Option<(DomainInstanceData, BlockNumberFor<T>)> {
Expand Down
7 changes: 7 additions & 0 deletions crates/sp-domains/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ impl RawGenesis {
);
}

pub fn domain_id(&self) -> Result<Option<DomainId>, parity_scale_codec::Error> {
match self.top.get(&self_domain_id_storage_key()) {
Some(sd) => Ok(Some(DomainId::decode(&mut sd.0.as_slice())?)),
None => Ok(None),
}
}

pub fn set_evm_chain_id(&mut self, chain_id: EVMChainId) {
let _ = self
.top
Expand Down

0 comments on commit a6e5b8b

Please sign in to comment.