Skip to content

Commit

Permalink
Merge pull request #419 from UniqueNetwork/release-v924010
Browse files Browse the repository at this point in the history
Release v924010
  • Loading branch information
kozyrevdev authored Jul 6, 2022
2 parents 518e58f + 824b60f commit a458077
Show file tree
Hide file tree
Showing 73 changed files with 5,819 additions and 728 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ einstein_key_file

/.idea/
/.cargo/
/.vscode/

tests/.vscode
cumulus-parachain/
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ so that we can keep the builds stable.
1. Install Rust:

```bash
sudo apt-get install git curl libssl-dev llvm pkg-config libclang-dev clang make
sudo apt-get install git curl libssl-dev llvm pkg-config libclang-dev clang make cmake
curl https://sh.rustup.rs -sSf | sh
```

Expand Down Expand Up @@ -83,7 +83,8 @@ Note: checkout this project and all related projects (see below) in the sibling
### Polkadot launch utility

```
git clone https://github.com/paritytech/polkadot-launch
git clone https://github.com/UniqueNetwork/polkadot-launch.git
git checkout feature/runtime-upgrade-testing
```

### Build relay
Expand Down
21 changes: 20 additions & 1 deletion pallets/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,10 @@ pub trait CommonWeightInfo<CrossAccountId> {
}
}

pub trait RefungibleExtensionsWeightInfo {
fn repartition() -> Weight;
}

pub trait CommonCollectionOperations<T: Config> {
fn create_item(
&self,
Expand Down Expand Up @@ -1307,12 +1311,14 @@ pub trait CommonCollectionOperations<T: Config> {
sender: T::CrossAccountId,
token_id: TokenId,
property: Vec<Property>,
nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo;
fn delete_token_properties(
&self,
sender: T::CrossAccountId,
token_id: TokenId,
property_keys: Vec<PropertyKey>,
nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo;
fn set_token_property_permissions(
&self,
Expand Down Expand Up @@ -1357,7 +1363,7 @@ pub trait CommonCollectionOperations<T: Config> {
sender: T::CrossAccountId,
from: (CollectionId, TokenId),
under: TokenId,
budget: &dyn Budget,
nesting_budget: &dyn Budget,
) -> DispatchResult;

fn nest(&self, under: TokenId, to_nest: (CollectionId, TokenId));
Expand All @@ -1384,6 +1390,19 @@ pub trait CommonCollectionOperations<T: Config> {
spender: T::CrossAccountId,
token: TokenId,
) -> u128;
fn refungible_extensions(&self) -> Option<&dyn RefungibleExtensions<T>>;
}

pub trait RefungibleExtensions<T>
where
T: Config,
{
fn repartition(
&self,
owner: &T::CrossAccountId,
token: TokenId,
amount: u128,
) -> DispatchResultWithPostInfo;
}

// Flexible enough for implementing CommonCollectionOperations
Expand Down
10 changes: 8 additions & 2 deletions pallets/fungible/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use core::marker::PhantomData;

use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, traits::Get};
use up_data_structs::{TokenId, CollectionId, CreateItemExData, budget::Budget, CreateItemData};
use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
use pallet_common::{CommonCollectionOperations, CommonWeightInfo, RefungibleExtensions, with_weight};
use pallet_structure::Error as StructureError;
use sp_runtime::ArithmeticError;
use sp_std::{vec::Vec, vec};
Expand Down Expand Up @@ -298,6 +298,7 @@ impl<T: Config> CommonCollectionOperations<T> for FungibleHandle<T> {
_sender: T::CrossAccountId,
_token_id: TokenId,
_property: Vec<Property>,
_nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
fail!(<Error<T>>::SettingPropertiesNotAllowed)
}
Expand All @@ -315,6 +316,7 @@ impl<T: Config> CommonCollectionOperations<T> for FungibleHandle<T> {
_sender: T::CrossAccountId,
_token_id: TokenId,
_property_keys: Vec<PropertyKey>,
_nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
fail!(<Error<T>>::SettingPropertiesNotAllowed)
}
Expand All @@ -324,7 +326,7 @@ impl<T: Config> CommonCollectionOperations<T> for FungibleHandle<T> {
_sender: <T>::CrossAccountId,
_from: (CollectionId, TokenId),
_under: TokenId,
_budget: &dyn Budget,
_nesting_budget: &dyn Budget,
) -> sp_runtime::DispatchResult {
fail!(<Error<T>>::FungibleDisallowsNesting)
}
Expand Down Expand Up @@ -399,4 +401,8 @@ impl<T: Config> CommonCollectionOperations<T> for FungibleHandle<T> {
}
<Allowance<T>>::get((self.id, sender, spender))
}

fn refungible_extensions(&self) -> Option<&dyn RefungibleExtensions<T>> {
None
}
}
6 changes: 3 additions & 3 deletions pallets/nonfungible/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ benchmarks! {
value: property_value(),
}).collect::<Vec<_>>();
let item = create_max_item(&collection, &owner, owner.clone())?;
}: {<Pallet<T>>::set_token_properties(&collection, &owner, item, props, false)?}
}: {<Pallet<T>>::set_token_properties(&collection, &owner, item, props, false, &Unlimited)?}

delete_token_properties {
let b in 0..MAX_PROPERTIES_PER_ITEM;
Expand All @@ -205,7 +205,7 @@ benchmarks! {
value: property_value(),
}).collect::<Vec<_>>();
let item = create_max_item(&collection, &owner, owner.clone())?;
<Pallet<T>>::set_token_properties(&collection, &owner, item, props, false)?;
<Pallet<T>>::set_token_properties(&collection, &owner, item, props, false, &Unlimited)?;
let to_delete = (0..b).map(|k| property_key(k as usize)).collect::<Vec<_>>();
}: {<Pallet<T>>::delete_token_properties(&collection, &owner, item, to_delete)?}
}: {<Pallet<T>>::delete_token_properties(&collection, &owner, item, to_delete, &Unlimited)?}
}
30 changes: 25 additions & 5 deletions pallets/nonfungible/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use up_data_structs::{
PropertyKeyPermission, PropertyValue,
};
use pallet_common::{
CommonCollectionOperations, CommonWeightInfo, with_weight, weights::WeightInfo as _,
CommonCollectionOperations, CommonWeightInfo, RefungibleExtensions, with_weight,
weights::WeightInfo as _,
};
use sp_runtime::DispatchError;
use sp_std::vec::Vec;
Expand Down Expand Up @@ -219,11 +220,19 @@ impl<T: Config> CommonCollectionOperations<T> for NonfungibleHandle<T> {
sender: T::CrossAccountId,
token_id: TokenId,
properties: Vec<Property>,
nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
let weight = <CommonWeights<T>>::set_token_properties(properties.len() as u32);

with_weight(
<Pallet<T>>::set_token_properties(self, &sender, token_id, properties, false),
<Pallet<T>>::set_token_properties(
self,
&sender,
token_id,
properties.into_iter(),
false,
nesting_budget,
),
weight,
)
}
Expand All @@ -233,11 +242,18 @@ impl<T: Config> CommonCollectionOperations<T> for NonfungibleHandle<T> {
sender: T::CrossAccountId,
token_id: TokenId,
property_keys: Vec<PropertyKey>,
nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
let weight = <CommonWeights<T>>::delete_token_properties(property_keys.len() as u32);

with_weight(
<Pallet<T>>::delete_token_properties(self, &sender, token_id, property_keys),
<Pallet<T>>::delete_token_properties(
self,
&sender,
token_id,
property_keys.into_iter(),
nesting_budget,
),
weight,
)
}
Expand Down Expand Up @@ -367,9 +383,9 @@ impl<T: Config> CommonCollectionOperations<T> for NonfungibleHandle<T> {
sender: T::CrossAccountId,
from: (CollectionId, TokenId),
under: TokenId,
budget: &dyn Budget,
nesting_budget: &dyn Budget,
) -> sp_runtime::DispatchResult {
<Pallet<T>>::check_nesting(self, sender, from, under, budget)
<Pallet<T>>::check_nesting(self, sender, from, under, nesting_budget)
}

fn nest(&self, under: TokenId, to_nest: (CollectionId, TokenId)) {
Expand Down Expand Up @@ -467,4 +483,8 @@ impl<T: Config> CommonCollectionOperations<T> for NonfungibleHandle<T> {
0
}
}

fn refungible_extensions(&self) -> Option<&dyn RefungibleExtensions<T>> {
None
}
}
12 changes: 10 additions & 2 deletions pallets/nonfungible/src/erc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ impl<T: Config> NonfungibleHandle<T> {
.map_err(|_| "key too long")?;
let value = value.try_into().map_err(|_| "value too long")?;

let nesting_budget = self
.recorder
.weight_calls_budget(<StructureWeight<T>>::find_parent());

<Pallet<T>>::set_token_property(
self,
&caller,
TokenId(token_id),
Property { key, value },
false,
&nesting_budget,
)
.map_err(dispatch_to_evm::<T>)
}
Expand All @@ -99,7 +103,11 @@ impl<T: Config> NonfungibleHandle<T> {
.try_into()
.map_err(|_| "key too long")?;

<Pallet<T>>::delete_token_property(self, &caller, TokenId(token_id), key)
let nesting_budget = self
.recorder
.weight_calls_budget(<StructureWeight<T>>::find_parent());

<Pallet<T>>::delete_token_property(self, &caller, TokenId(token_id), key, &nesting_budget)
.map_err(dispatch_to_evm::<T>)
}

Expand Down
Loading

0 comments on commit a458077

Please sign in to comment.