Skip to content

Commit

Permalink
Registries: Remove registry-id as a argument for create (#559)
Browse files Browse the repository at this point in the history
Signed-off-by: Shreevatsa N <[email protected]>
  • Loading branch information
vatsa287 authored Jan 6, 2025
1 parent 6fa1f04 commit 8351245
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 90 deletions.
14 changes: 0 additions & 14 deletions pallets/entries/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ fn create_registry_entry_should_work() {
/* Test creation of a Registry */
assert_ok!(Registries::create(
frame_system::RawOrigin::Signed(creator.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id),
Some(blob),
Expand Down Expand Up @@ -206,7 +205,6 @@ fn update_registry_entry_should_work() {
/* Test creation of a Registry */
assert_ok!(Registries::create(
frame_system::RawOrigin::Signed(creator.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id),
Some(blob),
Expand Down Expand Up @@ -358,7 +356,6 @@ fn revoke_registry_entry_should_work() {
/* Test creation of a Registry */
assert_ok!(Registries::create(
frame_system::RawOrigin::Signed(creator.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id),
Some(blob),
Expand Down Expand Up @@ -471,7 +468,6 @@ fn reinstating_revoked_registry_entry_should_work() {
/* Test creation of a Registry */
assert_ok!(Registries::create(
frame_system::RawOrigin::Signed(creator.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id),
Some(blob),
Expand Down Expand Up @@ -605,7 +601,6 @@ fn update_registry_entry_should_work_for_valid_creator() {
/* Test creation of a Registry */
assert_ok!(Registries::create(
frame_system::RawOrigin::Signed(admin.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id),
Some(blob),
Expand Down Expand Up @@ -766,7 +761,6 @@ fn update_registry_entry_should_work_for_valid_admin() {
/* Test creation of a Registry */
assert_ok!(Registries::create(
frame_system::RawOrigin::Signed(creator.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id),
Some(blob),
Expand Down Expand Up @@ -935,7 +929,6 @@ fn update_registry_entry_should_fail_for_non_registry_entry_creator() {
/* Test creation of a Registry */
assert_ok!(Registries::create(
frame_system::RawOrigin::Signed(admin.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id),
Some(blob),
Expand Down Expand Up @@ -1117,7 +1110,6 @@ fn update_registry_entry_should_fail_for_non_registry_admin() {
/* Test creation of a Registry */
assert_ok!(Registries::create(
frame_system::RawOrigin::Signed(admin.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id.clone()),
Some(blob.clone()),
Expand All @@ -1133,7 +1125,6 @@ fn update_registry_entry_should_fail_for_non_registry_admin() {

assert_ok!(Registries::create(
frame_system::RawOrigin::Signed(invalid_admin.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id),
Some(blob),
Expand Down Expand Up @@ -1289,7 +1280,6 @@ fn update_ownership_of_registry_entry_creator_should_work_for_creator() {
/* Test creation of a Registry */
assert_ok!(Registries::create(
frame_system::RawOrigin::Signed(admin.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id),
Some(blob),
Expand Down Expand Up @@ -1452,7 +1442,6 @@ fn update_ownership_of_registry_entry_creator_should_work_for_admin() {
/* Test creation of a Registry */
assert_ok!(Registries::create(
frame_system::RawOrigin::Signed(admin.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id),
Some(blob),
Expand Down Expand Up @@ -1615,7 +1604,6 @@ fn new_owner_should_be_able_to_perform_registry_entry_operations_after_ownership
/* Test creation of a Registry */
assert_ok!(Registries::create(
frame_system::RawOrigin::Signed(admin.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id),
Some(blob),
Expand Down Expand Up @@ -1830,7 +1818,6 @@ fn old_owner_should_not_be_able_to_perform_registry_entry_operations_after_owner
/* Test creation of a Registry */
assert_ok!(Registries::create(
frame_system::RawOrigin::Signed(admin.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id),
Some(blob),
Expand Down Expand Up @@ -2033,7 +2020,6 @@ fn update_ownership_should_fail_for_updating_themselves() {
/* Test creation of a Registry */
assert_ok!(Registries::create(
frame_system::RawOrigin::Signed(admin.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id),
Some(blob),
Expand Down
10 changes: 0 additions & 10 deletions pallets/registries/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ benchmarks! {

Pallet::<T>::create(
RawOrigin::Signed(creator.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id.clone()),
Some(blob),
Expand Down Expand Up @@ -135,7 +134,6 @@ benchmarks! {

Pallet::<T>::create(
RawOrigin::Signed(creator.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id.clone()),
Some(blob),
Expand Down Expand Up @@ -194,7 +192,6 @@ benchmarks! {

Pallet::<T>::create(
RawOrigin::Signed(creator.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id.clone()),
Some(blob),
Expand Down Expand Up @@ -255,7 +252,6 @@ benchmarks! {

Pallet::<T>::create(
RawOrigin::Signed(creator.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id.clone()),
Some(blob),
Expand Down Expand Up @@ -315,7 +311,6 @@ benchmarks! {

}: _<T::RuntimeOrigin>(
RawOrigin::Signed(creator.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id.clone()),
Some(blob)
Expand Down Expand Up @@ -369,7 +364,6 @@ benchmarks! {

Pallet::<T>::create(
RawOrigin::Signed(creator.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id.clone()),
Some(blob),
Expand Down Expand Up @@ -424,7 +418,6 @@ benchmarks! {

Pallet::<T>::create(
RawOrigin::Signed(creator.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id.clone()),
Some(blob),
Expand Down Expand Up @@ -476,7 +469,6 @@ benchmarks! {

Pallet::<T>::create(
RawOrigin::Signed(creator.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id.clone()),
Some(blob),
Expand Down Expand Up @@ -534,7 +526,6 @@ benchmarks! {

Pallet::<T>::create(
RawOrigin::Signed(creator.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id.clone()),
Some(blob),
Expand Down Expand Up @@ -586,7 +577,6 @@ benchmarks! {

Pallet::<T>::create(
RawOrigin::Signed(creator.clone()).into(),
registry_id.clone(),
registry_digest,
Some(schema_id.clone()),
Some(blob),
Expand Down
30 changes: 0 additions & 30 deletions pallets/registries/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ pub mod pallet {
///
/// # Parameters
/// - `origin`: The origin of the transaction, signed by the creator.
/// - `registry_id`: A unique code created to identify the registry.
/// - `digest`: The digest representing the registry data to be created.
/// - `schema_id`: (Optional) A unique code represnting the Schema.
/// - `blob`: (Optional) Metadata or data associated with the registry.
Expand All @@ -540,28 +539,18 @@ pub mod pallet {
#[pallet::weight({0})]
pub fn create(
origin: OriginFor<T>,
_registry_id: RegistryIdOf,
digest: RegistryHashOf<T>,
schema_id: Option<SchemaIdOf>,
_blob: Option<RegistryBlobOf<T>>,
) -> DispatchResult {
let creator = ensure_signed(origin)?;

// TODO: Create the identifier at SDK level & validate at chain level.
// Id Digest = concat (H(<scale_encoded_registry_input_digest>,
// <scale_encoded_creator_identifier>))
let id_digest = <T as frame_system::Config>::Hashing::hash(
&[&digest.encode()[..], &creator.encode()[..]].concat()[..],
);

// /* Ensure that registry_id is of valid ss58 format,
// * and also the type matches to be of `Registries`.
// */
// ensure!(
// Self::is_valid_ss58_format(&registry_id),
// Error::<T>::InvalidRegistryIdentifier
// );

let identifier = Ss58Identifier::create_identifier(
&id_digest.encode()[..],
IdentifierType::Registries,
Expand Down Expand Up @@ -1284,23 +1273,4 @@ impl<T: Config> Pallet<T> {
index: frame_system::Pallet::<T>::extrinsic_index().unwrap_or_default(),
}
}

/// Method to check if the input identifier calculated from sdk
/// is actually a valid SS58 Identifier Format and of valid type `Registries`.
pub fn is_valid_ss58_format(identifier: &Ss58Identifier) -> bool {
match identifier.get_type() {
Ok(id_type) =>
if id_type == IdentifierType::Registries {
log::debug!("The SS58 identifier is of type Registries.");
true
} else {
log::debug!("The SS58 identifier is not of type Registries.");
false
},
Err(e) => {
log::debug!("Invalid SS58 identifier. Error: {:?}", e);
false
},
}
}
}
Loading

0 comments on commit 8351245

Please sign in to comment.