diff --git a/pallets/asset/src/benchmarking.rs b/pallets/asset/src/benchmarking.rs index 775e1089..80f7e70c 100644 --- a/pallets/asset/src/benchmarking.rs +++ b/pallets/asset/src/benchmarking.rs @@ -175,7 +175,7 @@ benchmarks! { pallet_chain_space::Pallet::::approve(chain_space_origin, space_id, capacity).expect("Approval should not fail."); Pallet::::create(origin.clone(), entry, digest, authorization_id.clone())?; - }: _(origin, issue_entry, issue_entry_digest, authorization_id) + }: _(origin, issue_entry, issue_entry_digest, authorization_id, None) verify { assert_last_event::(Event::Issue { identifier: asset_id, instance: instance_id }.into()); } @@ -265,7 +265,7 @@ benchmarks! { pallet_chain_space::Pallet::::create(origin.clone(), space_digest )?; pallet_chain_space::Pallet::::approve(chain_space_origin, space_id, capacity).expect("Approval should not fail."); Pallet::::create(origin.clone(), entry, digest, authorization_id.clone())?; - Pallet::::issue(origin.clone(), issue_entry, issue_entry_digest, authorization_id)?; + Pallet::::issue(origin.clone(), issue_entry, issue_entry_digest, authorization_id, None)?; }: _(origin, transfer_entry, transfer_entry_digest) verify { @@ -346,7 +346,7 @@ benchmarks! { pallet_chain_space::Pallet::::create(origin.clone(), space_digest )?; pallet_chain_space::Pallet::::approve(chain_space_origin, space_id, capacity).expect("Approval should not fail."); Pallet::::create(origin.clone(), entry, digest, authorization_id.clone())?; - Pallet::::issue(origin.clone(), issue_entry, issue_entry_digest, authorization_id)?; + Pallet::::issue(origin.clone(), issue_entry, issue_entry_digest, authorization_id, None)?; }: _(origin, asset_id.clone(), Some(instance_id.clone()), new_status.clone()) verify { diff --git a/pallets/asset/src/lib.rs b/pallets/asset/src/lib.rs index e8445d21..02c30ae7 100644 --- a/pallets/asset/src/lib.rs +++ b/pallets/asset/src/lib.rs @@ -72,6 +72,9 @@ pub mod pallet { pub type AssetTagOf = BoundedVec::MaxEncodedValueLength>; pub type AssetMetadataOf = BoundedVec::MaxEncodedValueLength>; + pub type AssetKeyOf = BoundedVec::MaxEncodedValueLength>; + pub type AssetValueOf = BoundedVec::MaxEncodedValueLength>; + pub type AssetInputEntryOf = AssetInputEntry, AssetTypeOf, AssetTagOf, AssetMetadataOf>; @@ -128,6 +131,9 @@ pub mod pallet { #[pallet::constant] type MaxAssetDistribution: Get; + #[pallet::constant] + type MaxMetaPairLength: Get; + /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; } @@ -185,6 +191,17 @@ pub mod pallet { pub type AssetLookup = StorageMap<_, Blake2_128Concat, EntryHashOf, AssetIdOf, OptionQuery>; + #[pallet::storage] + pub type AssetMeta = StorageDoubleMap< + _, + Twox64Concat, + AssetIdOf, + Blake2_128Concat, + AssetKeyOf, + AssetValueOf, + OptionQuery, + >; + #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { @@ -308,6 +325,9 @@ pub mod pallet { entry: AssetIssuanceEntryOf, digest: EntryHashOf, authorization: AuthorizationIdOf, + meta: Option< + BoundedVec<(AssetKeyOf, AssetValueOf), ::MaxMetaPairLength>, + >, ) -> DispatchResult { let issuer = ::EnsureOrigin::ensure_origin(origin)?.subject(); let space_id = pallet_chain_space::Pallet::::ensure_authorization_origin( @@ -320,6 +340,11 @@ pub mod pallet { ensure!(asset.asset_issuer == issuer, Error::::UnauthorizedOperation); + // ensure!( + // meta.as_ref().map_or(true, |m| m.len() <= T::MaxMetaPairLength as usize), + // Error::::UnauthorizedOperation + // ); + ensure!(AssetStatusOf::ACTIVE == asset.asset_status, Error::::AssetNotActive); let issuance_qty = entry.asset_issuance_qty.unwrap_or(1); @@ -357,6 +382,12 @@ pub mod pallet { .map_err(|_| Error::::DistributionLimitExceeded) })?; + if let Some(meta) = meta { + for (key, value) in meta.iter() { + >::insert(&entry.asset_id, &key, &value); + } + } + >::insert(digest, &entry.asset_id); >::insert( diff --git a/pallets/asset/src/mock.rs b/pallets/asset/src/mock.rs index 8ab85881..e6719ed0 100644 --- a/pallets/asset/src/mock.rs +++ b/pallets/asset/src/mock.rs @@ -65,6 +65,7 @@ impl mock_origin::Config for Test { parameter_types! { pub const MaxEncodedValueLength: u32 = 1_024; pub const MaxAssetDistribution: u32 = u32::MAX; + pub const MaxMetaPairLength: u32 = 5; } impl Config for Test { @@ -73,6 +74,7 @@ impl Config for Test { type OriginSuccess = mock_origin::DoubleOrigin; type MaxEncodedValueLength = MaxEncodedValueLength; type MaxAssetDistribution = MaxAssetDistribution; + type MaxMetaPairLength = MaxMetaPairLength; type WeightInfo = (); } diff --git a/pallets/asset/src/tests.rs b/pallets/asset/src/tests.rs index 72541425..1aa105de 100644 --- a/pallets/asset/src/tests.rs +++ b/pallets/asset/src/tests.rs @@ -158,7 +158,8 @@ fn asset_issue_should_succeed() { DoubleOrigin(author.clone(), creator.clone()).into(), issue_entry.clone(), issue_entry_digest, - authorization_id + authorization_id, + None )); }); } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 3ea9a13f..154bc77b 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -798,6 +798,7 @@ impl pallet_network_score::Config for Runtime { parameter_types! { pub const MaxEncodedValueLength: u32 = 1_024; pub const MaxAssetDistribution: u32 = u32::MAX; + pub const MaxMetaPairLength: u32 = 5; } impl pallet_asset::Config for Runtime { @@ -806,6 +807,7 @@ impl pallet_asset::Config for Runtime { type OriginSuccess = pallet_did::DidRawOrigin; type MaxEncodedValueLength = MaxEncodedValueLength; type MaxAssetDistribution = MaxAssetDistribution; + type MaxMetaPairLength = MaxMetaPairLength; type WeightInfo = weights::pallet_asset::WeightInfo; }