Skip to content

Commit

Permalink
Update to use new identifiers
Browse files Browse the repository at this point in the history
Signed-off-by: Shreevatsa N <[email protected]>
  • Loading branch information
vatsa287 authored and amarts committed Jan 18, 2025
1 parent ed1eb94 commit 6eba730
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
9 changes: 6 additions & 3 deletions pallets/entries/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,18 @@ pub fn generate_schema_id<T: Config>(digest: &SchemaHashOf<T>) -> SchemaIdOf {

/// Generates a Namespace ID
pub fn generate_namespace_id<T: Config>(digest: &NameSpaceCodeOf<T>) -> NameSpaceIdOf {
Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::Space).unwrap()
Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::NameSpace).unwrap()
}

/// Generates a Namespace Authorization ID
pub fn generate_namespace_authorization_id<T: Config>(
digest: &NameSpaceCodeOf<T>,
) -> NamespaceAuthorizationIdOf {
Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::Authorization)
.unwrap()
Ss58Identifier::create_identifier(
&(digest).encode()[..],
IdentifierType::NameSpaceAuthorization,
)
.unwrap()
}

pub(crate) const ACCOUNT_00: AccountId = AccountId::new([1u8; 32]);
Expand Down
18 changes: 11 additions & 7 deletions pallets/namespace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,11 @@ pub mod pallet {
&[&digest.encode()[..], &creator.encode()[..]].concat()[..],
);

let identifier =
Ss58Identifier::create_identifier(&id_digest.encode()[..], IdentifierType::Space)
.map_err(|_| Error::<T>::InvalidIdentifierLength)?;
let identifier = Ss58Identifier::create_identifier(
&id_digest.encode()[..],
IdentifierType::NameSpace,
)
.map_err(|_| Error::<T>::InvalidIdentifierLength)?;

ensure!(
!<NameSpaces<T>>::contains_key(&identifier),
Expand All @@ -541,7 +543,7 @@ pub mod pallet {

let authorization_id = Ss58Identifier::create_identifier(
&auth_id_digest.encode(),
IdentifierType::Authorization,
IdentifierType::NameSpaceAuthorization,
)
.map_err(|_| Error::<T>::InvalidIdentifierLength)?;

Expand Down Expand Up @@ -728,9 +730,11 @@ impl<T: Config> Pallet<T> {
&[&namespace_id.encode()[..], &delegate.encode()[..], &creator.encode()[..]].concat()[..],
);

let delegate_authorization_id =
Ss58Identifier::create_identifier(&id_digest.encode(), IdentifierType::Authorization)
.map_err(|_| Error::<T>::InvalidIdentifierLength)?;
let delegate_authorization_id = Ss58Identifier::create_identifier(
&id_digest.encode(),
IdentifierType::NameSpaceAuthorization,
)
.map_err(|_| Error::<T>::InvalidIdentifierLength)?;

ensure!(
!Authorizations::<T>::contains_key(&delegate_authorization_id),
Expand Down
9 changes: 6 additions & 3 deletions pallets/namespace/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ use sp_std::prelude::*;

/// Generate a namespace id from a digest.
pub fn generate_namespace_id<T: Config>(digest: &NameSpaceCodeOf<T>) -> NameSpaceIdOf {
Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::Space).unwrap()
Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::NameSpace).unwrap()
}

/// Generate an authorization id from a digest.
pub fn generate_authorization_id<T: Config>(digest: &NameSpaceCodeOf<T>) -> AuthorizationIdOf {
Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::Authorization)
.unwrap()
Ss58Identifier::create_identifier(
&(digest).encode()[..],
IdentifierType::NameSpaceAuthorization,
)
.unwrap()
}

pub(crate) const ACCOUNT_00: AccountId = AccountId::new([1u8; 32]);
Expand Down
9 changes: 6 additions & 3 deletions pallets/registries/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ pub fn generate_schema_id<T: Config>(digest: &SchemaHashOf<T>) -> SchemaIdOf {
}

pub fn generate_namespace_id<T: Config>(digest: &NameSpaceCodeOf<T>) -> NameSpaceIdOf {
Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::Space).unwrap()
Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::NameSpace).unwrap()
}

pub fn generate_namespace_authorization_id<T: Config>(
digest: &NameSpaceCodeOf<T>,
) -> NamespaceAuthorizationIdOf {
Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::Authorization)
.unwrap()
Ss58Identifier::create_identifier(
&(digest).encode()[..],
IdentifierType::NameSpaceAuthorization,
)
.unwrap()
}

const SEED: u32 = 0;
Expand Down
9 changes: 6 additions & 3 deletions pallets/registries/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ pub fn generate_schema_id<T: Config>(digest: &SchemaHashOf<T>) -> SchemaIdOf {
}

pub fn generate_namespace_id<T: Config>(digest: &NameSpaceCodeOf<T>) -> NameSpaceIdOf {
Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::Space).unwrap()
Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::NameSpace).unwrap()
}

pub fn generate_namespace_authorization_id<T: Config>(
digest: &NameSpaceCodeOf<T>,
) -> NamespaceAuthorizationIdOf {
Ss58Identifier::create_identifier(&(digest).encode()[..], IdentifierType::Authorization)
.unwrap()
Ss58Identifier::create_identifier(
&(digest).encode()[..],
IdentifierType::NameSpaceAuthorization,
)
.unwrap()
}

pub(crate) const ACCOUNT_00: AccountId = AccountId::new([1u8; 32]);
Expand Down

0 comments on commit 6eba730

Please sign in to comment.