diff --git a/pallets/asset/src/lib.rs b/pallets/asset/src/lib.rs index 924f8325c..b35abd73c 100644 --- a/pallets/asset/src/lib.rs +++ b/pallets/asset/src/lib.rs @@ -166,6 +166,13 @@ pub mod pallet { from: AssetCreatorOf, to: AssetCreatorOf, }, + /// An asset (or instance) entry has a new Status now + /// \[asset entry identifier, optional instance identifier, new status\] + StatusChange { + identifier: AssetIdOf, + instance: Option, + status: AssetStatusOf, + }, } #[pallet::error] @@ -196,6 +203,8 @@ pub mod pallet { DistributionLimitExceeded, /// asset instance not found AssetInstanceNotFound, + /// Asset is in same status as asked for + AssetInSameState, } #[pallet::call] @@ -383,6 +392,57 @@ pub mod pallet { Ok(()) } + + #[pallet::call_index(3)] + #[pallet::weight({0})] + pub fn status_change( + origin: OriginFor, + asset_id: AssetIdOf, + instance_id: Option, + new_status: AssetStatusOf, + ) -> DispatchResult { + let issuer = ::EnsureOrigin::ensure_origin(origin)?.subject(); + + let asset = >::get(&asset_id).ok_or(Error::::AssetIdNotFound)?; + + ensure!(asset.asset_issuer == issuer, Error::::UnauthorizedOperation); + + /* If instance ID is provided, only revoke the instance, not the asset */ + if let Some(ref inst_id) = instance_id { + let instance = >::get(&asset_id, &inst_id) + .ok_or(Error::::AssetInstanceNotFound)?; + ensure!( + new_status.clone() == instance.asset_instance_status, + Error::::AssetInSameState + ); + + /* update the storage with new status */ + >::insert( + &asset_id, + &inst_id, + AssetDistributionEntryOf:: { + asset_instance_status: new_status.clone(), + ..instance + }, + ); + + Self::update_activity(&inst_id, CallTypeOf::Update).map_err(>::from)?; + } else { + ensure!(new_status.clone() != asset.asset_status, Error::::AssetInSameState); + >::insert( + &asset_id, + AssetEntryOf:: { asset_status: new_status.clone(), ..asset }, + ); + Self::update_activity(&asset_id, CallTypeOf::Update).map_err(>::from)?; + } + Self::deposit_event(Event::StatusChange { + identifier: asset_id, + instance: instance_id, + status: new_status, + }); + + Ok(()) + } } } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 85a882769..02711e54a 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -48,8 +48,12 @@ use frame_support::{ }; use frame_system::{ limits::{BlockLength, BlockWeights}, - EnsureRoot, EnsureSigned, + EnsureRoot, }; + +#[cfg(feature = "runtime-benchmarks")] +use frame_system::EnsureSigned; + use sp_consensus_grandpa::AuthorityId as GrandpaId; use pallet_identity::simple::IdentityInfo; @@ -123,7 +127,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("cord"), impl_name: create_runtime_str!("dhiway-cord"), authoring_version: 0, - spec_version: 9010, + spec_version: 9012, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2,