Skip to content

Commit

Permalink
Add a new runtime_upgrades() runtime API
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Jan 7, 2025
1 parent ab5af82 commit 56dccec
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2102,11 +2102,17 @@ impl<T: Config> Pallet<T> {
Ok(HeadDomainNumber::<T>::get(domain_id) + missed_upgrade.into())
}

/// Returns the runtime ID for the supplied `domain_id`, if that domain exists.
pub fn runtime_id(domain_id: DomainId) -> Option<RuntimeId> {
DomainRegistry::<T>::get(domain_id)
.map(|domain_object| domain_object.domain_config.runtime_id)
}

/// Returns the list of runtime upgrades in the current block.
pub fn runtime_upgrades() -> Vec<RuntimeId> {
DomainRuntimeUpgrades::<T>::get()
}

pub fn domain_instance_data(
domain_id: DomainId,
) -> Option<(DomainInstanceData, BlockNumberFor<T>)> {
Expand Down
7 changes: 5 additions & 2 deletions crates/sp-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1496,10 +1496,13 @@ sp_api::decl_runtime_apis! {
/// Returns the WASM bundle for given `domain_id`.
fn domain_runtime_code(domain_id: DomainId) -> Option<Vec<u8>>;

/// Returns the runtime id for given `domain_id`.
/// Returns the runtime id for the given `domain_id`.
fn runtime_id(domain_id: DomainId) -> Option<RuntimeId>;

/// Returns the domain instance data for given `domain_id`.
/// Returns the list of runtime upgrades in the current block.
fn runtime_upgrades() -> Vec<RuntimeId>;

/// Returns the domain instance data for the given `domain_id`.
fn domain_instance_data(domain_id: DomainId) -> Option<(DomainInstanceData, NumberFor<Block>)>;

/// Returns the current timestamp at given height.
Expand Down
4 changes: 4 additions & 0 deletions crates/subspace-fake-runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ sp_api::impl_runtime_apis! {
unreachable!()
}

fn runtime_upgrades() -> Vec<sp_domains::RuntimeId> {
unreachable!()
}

fn domain_instance_data(_domain_id: DomainId) -> Option<(DomainInstanceData, NumberFor<Block>)> {
unreachable!()
}
Expand Down
4 changes: 4 additions & 0 deletions crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,10 @@ impl_runtime_apis! {
Domains::runtime_id(domain_id)
}

fn runtime_upgrades() -> Vec<sp_domains::RuntimeId> {
Domains::runtime_upgrades()
}

fn domain_instance_data(domain_id: DomainId) -> Option<(DomainInstanceData, NumberFor<Block>)> {
Domains::domain_instance_data(domain_id)
}
Expand Down
4 changes: 4 additions & 0 deletions test/subspace-test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,10 @@ impl_runtime_apis! {
Domains::runtime_id(domain_id)
}

fn runtime_upgrades() -> Vec<sp_domains::RuntimeId> {
Domains::runtime_upgrades()
}

fn domain_instance_data(domain_id: DomainId) -> Option<(DomainInstanceData, NumberFor<Block>)> {
Domains::domain_instance_data(domain_id)
}
Expand Down

0 comments on commit 56dccec

Please sign in to comment.