git.delta.rocks / unique-network / refs/commits / 251ea62d352e

difftreelog

fix unbroke ink contract build substrate v0.9.8

Yaroslav Bolyukin2021-08-06parent: #d49b9b4.patch.diff
in: master

7 files changed

modifiedCargo.lockdiffbeforeafterboth
4935name = "nft-data-structs"4935name = "nft-data-structs"
4936version = "0.9.0"4936version = "0.9.0"
4937dependencies = [4937dependencies = [
4938 "derivative",
4938 "frame-support",4939 "frame-support",
4939 "frame-system",4940 "frame-system",
4941 "max-encoded-len",
4940 "parity-scale-codec",4942 "parity-scale-codec",
4941 "serde",4943 "serde",
4942 "sp-core",4944 "sp-core",
4943 "sp-runtime",4945 "sp-runtime",
4946 "sp-std",
4944]4947]
49454948
4946[[package]]4949[[package]]
4999 "cumulus-primitives-core",5002 "cumulus-primitives-core",
5000 "cumulus-primitives-timestamp",5003 "cumulus-primitives-timestamp",
5001 "cumulus-primitives-utility",5004 "cumulus-primitives-utility",
5005 "derivative",
5002 "fp-rpc",5006 "fp-rpc",
5003 "frame-benchmarking",5007 "frame-benchmarking",
5004 "frame-executive",5008 "frame-executive",
5007 "frame-system-benchmarking",5011 "frame-system-benchmarking",
5008 "frame-system-rpc-runtime-api",5012 "frame-system-rpc-runtime-api",
5009 "hex-literal",5013 "hex-literal",
5014 "max-encoded-len",
5010 "nft-data-structs",5015 "nft-data-structs",
5011 "pallet-aura",5016 "pallet-aura",
5012 "pallet-balances",5017 "pallet-balances",
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
1675 CreateItemData::NFT(data) => {1675 CreateItemData::NFT(data) => {
1676 let item = NftItemType {1676 let item = NftItemType {
1677 owner: owner.clone(),1677 owner: owner.clone(),
1678 const_data: data.const_data,1678 const_data: data.const_data.into_inner(),
1679 variable_data: data.variable_data,1679 variable_data: data.variable_data.into_inner(),
1680 };1680 };
16811681
1682 Self::add_nft_item(collection, item)?;1682 Self::add_nft_item(collection, item)?;
16921692
1693 let item = ReFungibleItemType {1693 let item = ReFungibleItemType {
1694 owner: owner_list,1694 owner: owner_list,
1695 const_data: data.const_data,1695 const_data: data.const_data.into_inner(),
1696 variable_data: data.variable_data,1696 variable_data: data.variable_data.into_inner(),
1697 };1697 };
16981698
1699 Self::add_refungible_item(collection, item)?;1699 Self::add_refungible_item(collection, item)?;
modifiedprimitives/nft/Cargo.tomldiffbeforeafterboth
9version = '0.9.0'9version = '0.9.0'
1010
11[dependencies]11[dependencies]
12codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ['derive'] }12codec = { package = "parity-scale-codec", version = "2.2.0", default-features = false, features = ['derive'] }
13serde = { version = "1.0.119", features = ['derive'], default-features = false }13serde = { version = "1.0.119", features = ['derive'], default-features = false }
14max-encoded-len = { default-features = false, features = ['derive'], version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }
14frame-support = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }15frame-support = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }
15frame-system = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }16frame-system = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }
16sp-core = { version = "3.0.0", default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }17sp-core = { version = "3.0.0", default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }
18sp-std = { version = "3.0.0", default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }
17sp-runtime = { version = "3.0.0", default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }19sp-runtime = { version = "3.0.0", default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }
20derivative = "2.2.0"
1821
19[features]22[features]
20default = ["std"]23default = ["std"]
21std = [24std = [
22 "serde/std",25 "serde/std",
23 "codec/std",26 "codec/std",
27 "max-encoded-len/std",
24 "frame-system/std",28 "frame-system/std",
25 "frame-support/std",29 "frame-support/std",
26 "sp-runtime/std",30 "sp-runtime/std",
27 "sp-core/std",31 "sp-core/std",
32 "sp-std/std",
28]33]
modifiedprimitives/nft/src/lib.rsdiffbeforeafterboth
44
5use sp_runtime::sp_std::prelude::Vec;5use sp_runtime::sp_std::prelude::Vec;
6use codec::{Decode, Encode};6use codec::{Decode, Encode};
7use max_encoded_len::MaxEncodedLen;
7pub use frame_support::{8pub use frame_support::{
8 construct_runtime, decl_event, decl_module, decl_storage, decl_error,9 BoundedVec, construct_runtime, decl_event, decl_module, decl_storage, decl_error,
9 dispatch::DispatchResult,10 dispatch::DispatchResult,
10 ensure, fail, parameter_types,11 ensure, fail, parameter_types,
11 traits::{12 traits::{
19 },20 },
20 StorageValue, transactional,21 StorageValue, transactional,
21};22};
23use derivative::Derivative;
2224
23pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;25pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;
24pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;26pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;
25pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;27pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;
26pub const MAX_TOKEN_OWNERSHIP: u32 = 10_000_000;28pub const MAX_TOKEN_OWNERSHIP: u32 = 10_000_000;
29
30// TODO: Somehow use ChainLimits for BoundedVec len calculation?
31// Do we need ChainLimits anyway, if we can change them via forkless upgrades?
32parameter_types! {
33pub const MaxDataSize: u32 = 2048;
34// TODO: This limit isn't checked for substrate create_multiple_items call
35pub const MaxItemsPerBatch: u32 = 200;
36}
2737
28pub type CollectionId = u32;38pub type CollectionId = u32;
29pub type TokenId = u32;39pub type TokenId = u32;
30pub type DecimalPoints = u8;40pub type DecimalPoints = u8;
3141
32#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]42#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, Serialize, Deserialize)]
33#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
34pub enum CollectionMode {43pub enum CollectionMode {
35 Invalid,44 Invalid,
36 NFT,45 NFT,
60 fn resolve(who: &AccountId, call: &Call) -> Option<AccountId>;69 fn resolve(who: &AccountId, call: &Call) -> Option<AccountId>;
61}70}
6271
63#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]72#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, Serialize, Deserialize)]
64#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
65pub enum AccessMode {73pub enum AccessMode {
66 Normal,74 Normal,
67 WhiteList,75 WhiteList,
72 }80 }
73}81}
7482
75#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]83#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, Serialize, Deserialize)]
76#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
77pub enum SchemaVersion {84pub enum SchemaVersion {
78 ImageURL,85 ImageURL,
79 Unique,86 Unique,
84 }91 }
85}92}
8693
87#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]94#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
88#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
89pub struct Ownership<AccountId> {95pub struct Ownership<AccountId> {
90 pub owner: AccountId,96 pub owner: AccountId,
91 pub fraction: u128,97 pub fraction: u128,
92}98}
9399
94#[derive(Encode, Decode, Debug, Clone, PartialEq)]100#[derive(Encode, Decode, Debug, Clone, PartialEq, Serialize, Deserialize)]
95#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
96pub enum SponsorshipState<AccountId> {101pub enum SponsorshipState<AccountId> {
97 /// The fees are applied to the transaction sender102 /// The fees are applied to the transaction sender
98 Disabled,103 Disabled,
147 pub transfers_enabled: bool,152 pub transfers_enabled: bool,
148}153}
149154
150#[derive(Encode, Decode, Debug, Clone, PartialEq)]155#[derive(Encode, Decode, Debug, Clone, PartialEq, Serialize, Deserialize)]
151#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
152pub struct NftItemType<AccountId> {156pub struct NftItemType<AccountId> {
153 pub owner: AccountId,157 pub owner: AccountId,
154 pub const_data: Vec<u8>,158 pub const_data: Vec<u8>,
155 pub variable_data: Vec<u8>,159 pub variable_data: Vec<u8>,
156}160}
157161
158#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]162#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
159#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
160pub struct FungibleItemType {163pub struct FungibleItemType {
161 pub value: u128,164 pub value: u128,
162}165}
163166
164#[derive(Encode, Decode, Debug, Clone, PartialEq)]167#[derive(Encode, Decode, Debug, Clone, PartialEq, Serialize, Deserialize)]
165#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
166pub struct ReFungibleItemType<AccountId> {168pub struct ReFungibleItemType<AccountId> {
167 pub owner: Vec<Ownership<AccountId>>,169 pub owner: Vec<Ownership<AccountId>>,
168 pub const_data: Vec<u8>,170 pub const_data: Vec<u8>,
169 pub variable_data: Vec<u8>,171 pub variable_data: Vec<u8>,
170}172}
171173
172#[derive(Encode, Decode, Debug, Clone, PartialEq)]174#[derive(Encode, Decode, Debug, Clone, PartialEq, Serialize, Deserialize)]
173#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
174pub struct CollectionLimits<BlockNumber: Encode + Decode> {175pub struct CollectionLimits<BlockNumber: Encode + Decode> {
175 pub account_token_ownership_limit: u32,176 pub account_token_ownership_limit: u32,
176 pub sponsored_data_size: u32,177 pub sponsored_data_size: u32,
200 }201 }
201}202}
202203
203#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]204#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
204#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
205pub struct ChainLimits {205pub struct ChainLimits {
206 pub collection_numbers_limit: u32,206 pub collection_numbers_limit: u32,
207 pub account_token_ownership_limit: u32,207 pub account_token_ownership_limit: u32,
219 pub const_on_chain_schema_limit: u32,219 pub const_on_chain_schema_limit: u32,
220}220}
221
222/// BoundedVec doesn't supports serde
223mod bounded_serde {
224 use core::convert::TryFrom;
225 use frame_support::{BoundedVec, traits::Get};
226 use serde::{
227 ser::{self, Serialize},
228 de::{self, Deserialize, Error},
229 };
230 use sp_std::vec::Vec;
231
232 pub fn serialize<D, V, S>(value: &BoundedVec<V, S>, serializer: D) -> Result<D::Ok, D::Error>
233 where
234 D: ser::Serializer,
235 V: Serialize,
236 {
237 let vec: &Vec<_> = &value;
238 vec.serialize(serializer)
239 }
240
241 pub fn deserialize<'de, D, V, S>(deserializer: D) -> Result<BoundedVec<V, S>, D::Error>
242 where
243 D: de::Deserializer<'de>,
244 V: de::Deserialize<'de>,
245 S: Get<u32>,
246 {
247 // TODO: Implement custom visitor, which will limit vec size at parse time? Will serde only be used by chainspec?
248 let vec = <Vec<V>>::deserialize(deserializer)?;
249 let len = vec.len();
250 TryFrom::try_from(vec).map_err(|_| D::Error::invalid_length(len, &"lesser size"))
251 }
252}
221253
222#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]254#[derive(
255 Encode, Decode, MaxEncodedLen, Default, Derivative, Clone, PartialEq, Serialize, Deserialize,
256)]
223#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]257#[derivative(Debug)]
224pub struct CreateNftData {258pub struct CreateNftData {
259 #[serde(with = "bounded_serde")]
260 #[derivative(Debug="ignore")]
225 pub const_data: Vec<u8>,261 pub const_data: BoundedVec<u8, MaxDataSize>,
262 #[serde(with = "bounded_serde")]
263 #[derivative(Debug="ignore")]
226 pub variable_data: Vec<u8>,264 pub variable_data: BoundedVec<u8, MaxDataSize>,
227}265}
228266
229#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]267#[derive(
230#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]268 Encode, Decode, MaxEncodedLen, Default, Debug, Clone, PartialEq, Serialize, Deserialize,
269)]
231pub struct CreateFungibleData {270pub struct CreateFungibleData {
232 pub value: u128,271 pub value: u128,
233}272}
234273
235#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]274#[derive(
275 Encode, Decode, MaxEncodedLen, Default, Derivative, Clone, PartialEq, Serialize, Deserialize,
276)]
236#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]277#[derivative(Debug)]
237pub struct CreateReFungibleData {278pub struct CreateReFungibleData {
279 #[serde(with = "bounded_serde")]
280 #[derivative(Debug="ignore")]
238 pub const_data: Vec<u8>,281 pub const_data: BoundedVec<u8, MaxDataSize>,
282 #[serde(with = "bounded_serde")]
283 #[derivative(Debug="ignore")]
239 pub variable_data: Vec<u8>,284 pub variable_data: BoundedVec<u8, MaxDataSize>,
240 pub pieces: u128,285 pub pieces: u128,
241}286}
242287
243#[derive(Encode, Decode, Debug, Clone, PartialEq)]288#[derive(Encode, Decode, MaxEncodedLen, Debug, Clone, PartialEq, Serialize, Deserialize)]
244#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
245pub enum CreateItemData {289pub enum CreateItemData {
246 NFT(CreateNftData),290 NFT(CreateNftData),
247 Fungible(CreateFungibleData),291 Fungible(CreateFungibleData),
modifiedruntime/Cargo.tomldiffbeforeafterboth
31]31]
32std = [32std = [
33 'codec/std',33 'codec/std',
34 'max-encoded-len/std',
34 'cumulus-pallet-aura-ext/std',35 'cumulus-pallet-aura-ext/std',
35 'cumulus-pallet-parachain-system/std',36 'cumulus-pallet-parachain-system/std',
36 'cumulus-pallet-xcm/std',37 'cumulus-pallet-xcm/std',
378# local dependencies379# local dependencies
379380
380[dependencies]381[dependencies]
382max-encoded-len = { default-features = false, features = ['derive'], version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }
383derivative = "2.2.0"
381pallet-nft = { path = '../pallets/nft', default-features = false, version = '3.0.0' }384pallet-nft = { path = '../pallets/nft', default-features = false, version = '3.0.0' }
382pallet-inflation = { path = '../pallets/inflation', default-features = false, version = '3.0.0' }385pallet-inflation = { path = '../pallets/inflation', default-features = false, version = '3.0.0' }
383nft-data-structs = { path = '../primitives/nft', default-features = false, version = '0.9.0' }386nft-data-structs = { path = '../primitives/nft', default-features = false, version = '0.9.0' }
modifiedruntime/src/chain_extension.rsdiffbeforeafterboth
6//6//
77
8use codec::{Decode, Encode};8use codec::{Decode, Encode};
9use max_encoded_len::MaxEncodedLen;
10use derivative::Derivative;
911
10pub use pallet_contracts::chain_extension::RetVal;12pub use pallet_contracts::chain_extension::RetVal;
11use pallet_contracts::chain_extension::{13use pallet_contracts::chain_extension::{
20use pallet_nft::CrossAccountId;22use pallet_nft::CrossAccountId;
21use nft_data_structs::*;23use nft_data_structs::*;
22
23use crate::Vec;
2424
25/// Create item parameters25/// Create item parameters
26#[derive(Debug, PartialEq, Encode, Decode)]26#[derive(Debug, PartialEq, Encode, Decode, MaxEncodedLen)]
27pub struct NFTExtCreateItem<E: Ext> {27pub struct NFTExtCreateItem<AccountId> {
28 pub owner: <E::T as SysConfig>::AccountId,28 pub owner: AccountId,
29 pub collection_id: u32,29 pub collection_id: u32,
30 pub data: CreateItemData,30 pub data: CreateItemData,
31}31}
3232
33/// Transfer parameters33/// Transfer parameters
34#[derive(Debug, PartialEq, Encode, Decode)]34#[derive(Debug, PartialEq, Encode, Decode, MaxEncodedLen)]
35pub struct NFTExtTransfer<E: Ext> {35pub struct NFTExtTransfer<AccountId> {
36 pub recipient: <E::T as SysConfig>::AccountId,36 pub recipient: AccountId,
37 pub collection_id: u32,37 pub collection_id: u32,
38 pub token_id: u32,38 pub token_id: u32,
39 pub amount: u128,39 pub amount: u128,
40}40}
4141
42#[derive(Debug, PartialEq, Encode, Decode)]42#[derive(Derivative, PartialEq, Encode, Decode, MaxEncodedLen)]
43#[derivative(Debug)]
43pub struct NFTExtCreateMultipleItems<E: Ext> {44pub struct NFTExtCreateMultipleItems<AccountId> {
44 pub owner: <E::T as SysConfig>::AccountId,45 pub owner: AccountId,
45 pub collection_id: u32,46 pub collection_id: u32,
47 #[derivative(Debug = "ignore")]
46 pub data: Vec<CreateItemData>,48 pub data: BoundedVec<CreateItemData, MaxItemsPerBatch>,
47}49}
4850
49#[derive(Debug, PartialEq, Encode, Decode)]51#[derive(Debug, PartialEq, Encode, Decode, MaxEncodedLen)]
50pub struct NFTExtApprove<E: Ext> {52pub struct NFTExtApprove<AccountId> {
51 pub spender: <E::T as SysConfig>::AccountId,53 pub spender: AccountId,
52 pub collection_id: u32,54 pub collection_id: u32,
53 pub item_id: u32,55 pub item_id: u32,
54 pub amount: u128,56 pub amount: u128,
55}57}
5658
57#[derive(Debug, PartialEq, Encode, Decode)]59#[derive(Debug, PartialEq, Encode, Decode, MaxEncodedLen)]
58pub struct NFTExtTransferFrom<E: Ext> {60pub struct NFTExtTransferFrom<AccountId> {
59 pub owner: <E::T as SysConfig>::AccountId,61 pub owner: AccountId,
60 pub recipient: <E::T as SysConfig>::AccountId,62 pub recipient: AccountId,
61 pub collection_id: u32,63 pub collection_id: u32,
62 pub item_id: u32,64 pub item_id: u32,
63 pub amount: u128,65 pub amount: u128,
64}66}
6567
66#[derive(Debug, PartialEq, Encode, Decode)]68#[derive(Derivative, PartialEq, Encode, Decode, MaxEncodedLen)]
69#[derivative(Debug)]
67pub struct NFTExtSetVariableMetaData {70pub struct NFTExtSetVariableMetaData {
68 pub collection_id: u32,71 pub collection_id: u32,
69 pub item_id: u32,72 pub item_id: u32,
73 #[derivative(Debug = "ignore")]
70 pub data: Vec<u8>,74 pub data: BoundedVec<u8, MaxDataSize>,
71}75}
7276
73#[derive(Debug, PartialEq, Encode, Decode)]77#[derive(Debug, PartialEq, Encode, Decode, MaxEncodedLen)]
74pub struct NFTExtToggleWhiteList<E: Ext> {78pub struct NFTExtToggleWhiteList<AccountId> {
75 pub collection_id: u32,79 pub collection_id: u32,
76 pub address: <E::T as SysConfig>::AccountId,80 pub address: AccountId,
77 pub whitelisted: bool,81 pub whitelisted: bool,
78}82}
7983
8286
83pub type NftWeightInfoOf<C> = <C as pallet_nft::Config>::WeightInfo;87pub type NftWeightInfoOf<C> = <C as pallet_nft::Config>::WeightInfo;
88
89pub type AccountIdOf<C> = <C as SysConfig>::AccountId;
8490
85impl<C: Config + pallet_contracts::Config> ChainExtension<C> for NFTExtension {91impl<C: Config + pallet_contracts::Config> ChainExtension<C> for NFTExtension {
86 fn call<E: Ext>(func_id: u32, env: Environment<E, InitState>) -> Result<RetVal, DispatchError>92 fn call<E: Ext>(func_id: u32, env: Environment<E, InitState>) -> Result<RetVal, DispatchError>
93 match func_id {99 match func_id {
94 0 => {100 0 => {
95 let mut env = env.buf_in_buf_out();101 let mut env = env.buf_in_buf_out();
96 let input: NFTExtTransfer<E> = env.read_as()?;102 let input: NFTExtTransfer<AccountIdOf<C>> = env.read_as()?;
97 env.charge_weight(NftWeightInfoOf::<C>::transfer())?;103 env.charge_weight(NftWeightInfoOf::<C>::transfer())?;
98104
99 let collection = pallet_nft::Module::<C>::get_collection(input.collection_id)?;105 let collection = pallet_nft::Module::<C>::get_collection(input.collection_id)?;
106 input.amount,112 input.amount,
107 )?;113 )?;
108114
109 pallet_nft::Module::<C>::submit_logs(collection)?;115 collection.submit_logs()?;
110 Ok(RetVal::Converging(0))116 Ok(RetVal::Converging(0))
111 }117 }
112 1 => {118 1 => {
113 // Create Item119 // Create Item
114 let mut env = env.buf_in_buf_out();120 let mut env = env.buf_in_buf_out();
115 let input: NFTExtCreateItem<E> = env.read_as()?;121 let input: NFTExtCreateItem<AccountIdOf<C>> = env.read_as()?;
116 env.charge_weight(NftWeightInfoOf::<C>::create_item(input.data.data_size()))?;122 env.charge_weight(NftWeightInfoOf::<C>::create_item(input.data.data_size()))?;
117123
118 let collection = pallet_nft::Module::<C>::get_collection(input.collection_id)?;124 let collection = pallet_nft::Module::<C>::get_collection(input.collection_id)?;
124 input.data,130 input.data,
125 )?;131 )?;
126132
127 pallet_nft::Module::<C>::submit_logs(collection)?;133 collection.submit_logs()?;
128 Ok(RetVal::Converging(0))134 Ok(RetVal::Converging(0))
129 }135 }
130 2 => {136 2 => {
131 // Create multiple items137 // Create multiple items
132 let mut env = env.buf_in_buf_out();138 let mut env = env.buf_in_buf_out();
133 let input: NFTExtCreateMultipleItems<E> = env.read_as()?;139 let input: NFTExtCreateMultipleItems<AccountIdOf<C>> = env.read_as()?;
134 env.charge_weight(NftWeightInfoOf::<C>::create_item(140 env.charge_weight(NftWeightInfoOf::<C>::create_item(
135 input.data.iter().map(|i| i.data_size()).sum(),141 input.data.iter().map(|i| i.data_size()).sum(),
136 ))?;142 ))?;
141 &C::CrossAccountId::from_sub(env.ext().address().clone()),147 &C::CrossAccountId::from_sub(env.ext().address().clone()),
142 &collection,148 &collection,
143 &C::CrossAccountId::from_sub(input.owner),149 &C::CrossAccountId::from_sub(input.owner),
144 input.data,150 input.data.into_inner(),
145 )?;151 )?;
146152
147 pallet_nft::Module::<C>::submit_logs(collection)?;153 collection.submit_logs()?;
148 Ok(RetVal::Converging(0))154 Ok(RetVal::Converging(0))
149 }155 }
150 3 => {156 3 => {
151 // Approve157 // Approve
152 let mut env = env.buf_in_buf_out();158 let mut env = env.buf_in_buf_out();
153 let input: NFTExtApprove<E> = env.read_as()?;159 let input: NFTExtApprove<AccountIdOf<C>> = env.read_as()?;
154 env.charge_weight(NftWeightInfoOf::<C>::approve())?;160 env.charge_weight(NftWeightInfoOf::<C>::approve())?;
155161
156 let collection = pallet_nft::Module::<C>::get_collection(input.collection_id)?;162 let collection = pallet_nft::Module::<C>::get_collection(input.collection_id)?;
163 input.amount,169 input.amount,
164 )?;170 )?;
165171
166 pallet_nft::Module::<C>::submit_logs(collection)?;172 collection.submit_logs()?;
167 Ok(RetVal::Converging(0))173 Ok(RetVal::Converging(0))
168 }174 }
169 4 => {175 4 => {
170 // Transfer from176 // Transfer from
171 let mut env = env.buf_in_buf_out();177 let mut env = env.buf_in_buf_out();
172 let input: NFTExtTransferFrom<E> = env.read_as()?;178 let input: NFTExtTransferFrom<AccountIdOf<C>> = env.read_as()?;
173 env.charge_weight(NftWeightInfoOf::<C>::transfer_from())?;179 env.charge_weight(NftWeightInfoOf::<C>::transfer_from())?;
174180
175 let collection = pallet_nft::Module::<C>::get_collection(input.collection_id)?;181 let collection = pallet_nft::Module::<C>::get_collection(input.collection_id)?;
183 input.amount,189 input.amount,
184 )?;190 )?;
185191
186 pallet_nft::Module::<C>::submit_logs(collection)?;192 collection.submit_logs()?;
187 Ok(RetVal::Converging(0))193 Ok(RetVal::Converging(0))
188 }194 }
189 5 => {195 5 => {
198 &C::CrossAccountId::from_sub(env.ext().address().clone()),204 &C::CrossAccountId::from_sub(env.ext().address().clone()),
199 &collection,205 &collection,
200 input.item_id,206 input.item_id,
201 input.data,207 input.data.into_inner(),
202 )?;208 )?;
203209
204 pallet_nft::Module::<C>::submit_logs(collection)?;210 collection.submit_logs()?;
205 Ok(RetVal::Converging(0))211 Ok(RetVal::Converging(0))
206 }212 }
207 6 => {213 6 => {
208 // Toggle whitelist214 // Toggle whitelist
209 let mut env = env.buf_in_buf_out();215 let mut env = env.buf_in_buf_out();
210 let input: NFTExtToggleWhiteList<E> = env.read_as()?;216 let input: NFTExtToggleWhiteList<AccountIdOf<C>> = env.read_as()?;
211 env.charge_weight(NftWeightInfoOf::<C>::add_to_white_list())?;217 env.charge_weight(NftWeightInfoOf::<C>::add_to_white_list())?;
212218
213 let collection = pallet_nft::Module::<C>::get_collection(input.collection_id)?;219 let collection = pallet_nft::Module::<C>::get_collection(input.collection_id)?;
219 input.whitelisted,225 input.whitelisted,
220 )?;226 )?;
221227
222 pallet_nft::Module::<C>::submit_logs(collection)?;228 collection.submit_logs()?;
223 Ok(RetVal::Converging(0))229 Ok(RetVal::Converging(0))
224 }230 }
225 _ => Err(DispatchError::Other("unknown chain_extension func_id")),231 _ => Err(DispatchError::Other("unknown chain_extension func_id")),
modifiedruntime/src/lib.rsdiffbeforeafterboth
72use sp_runtime::{72use sp_runtime::{
73 traits::{Dispatchable},73 traits::{Dispatchable},
74};74};
75// use pallet_contracts::chain_extension::UncheckedFrom;
7675
77// pub use pallet_timestamp::Call as TimestampCall;76// pub use pallet_timestamp::Call as TimestampCall;
78pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;77pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
379 items as Balance * 15 * CENTIUNIQUE + (bytes as Balance) * 6 * CENTIUNIQUE378 items as Balance * 15 * CENTIUNIQUE + (bytes as Balance) * 6 * CENTIUNIQUE
380}379}
381380
382/*381/*
383parameter_types! {382parameter_types! {
384 pub TombstoneDeposit: Balance = deposit(383 pub TombstoneDeposit: Balance = deposit(
385 1,384 1,
386 sp_std::mem::size_of::<pallet_contracts::Pallet<Runtime>> as u32,385 sp_std::mem::size_of::<pallet_contracts::Pallet<Runtime>> as u32,
387 );386 );
388 pub DepositPerContract: Balance = TombstoneDeposit::get();387 pub DepositPerContract: Balance = TombstoneDeposit::get();
389 pub const DepositPerStorageByte: Balance = deposit(0, 1);388 pub const DepositPerStorageByte: Balance = deposit(0, 1);
390 pub const DepositPerStorageItem: Balance = deposit(1, 0);389 pub const DepositPerStorageItem: Balance = deposit(1, 0);
391 pub RentFraction: Perbill = Perbill::from_rational(1u32, 30 * DAYS);390 pub RentFraction: Perbill = Perbill::from_rational(1u32, 30 * DAYS);
392 pub const SurchargeReward: Balance = 150 * MILLIUNIQUE;391 pub const SurchargeReward: Balance = 150 * MILLIUNIQUE;
393 pub const SignedClaimHandicap: u32 = 2;392 pub const SignedClaimHandicap: u32 = 2;
394 pub const MaxDepth: u32 = 32;393 pub const MaxDepth: u32 = 32;
395 pub const MaxValueSize: u32 = 16 * 1024;394 pub const MaxValueSize: u32 = 16 * 1024;
396 pub const MaxCodeSize: u32 = 1024 * 1024 * 25; // 25 Mb395 pub const MaxCodeSize: u32 = 1024 * 1024 * 25; // 25 Mb
397 // The lazy deletion runs inside on_initialize.396 // The lazy deletion runs inside on_initialize.
398 pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO *397 pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO *
399 RuntimeBlockWeights::get().max_block;398 RuntimeBlockWeights::get().max_block;
400 // The weight needed for decoding the queue should be less or equal than a fifth399 // The weight needed for decoding the queue should be less or equal than a fifth
401 // of the overall weight dedicated to the lazy deletion.400 // of the overall weight dedicated to the lazy deletion.
402 pub DeletionQueueDepth: u32 = ((DeletionWeightLimit::get() / (401 pub DeletionQueueDepth: u32 = ((DeletionWeightLimit::get() / (
403 <Runtime as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(1) -402 <Runtime as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(1) -
404 <Runtime as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(0)403 <Runtime as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(0)
405 )) / 5) as u32;404 )) / 5) as u32;
406 pub Schedule: pallet_contracts::Schedule<Runtime> = Default::default();405 pub Schedule: pallet_contracts::Schedule<Runtime> = Default::default();
407}406}
408407
409impl pallet_contracts::Config for Runtime {408impl pallet_contracts::Config for Runtime {
410 type Time = Timestamp;409 type Time = Timestamp;
411 type Randomness = RandomnessCollectiveFlip;410 type Randomness = RandomnessCollectiveFlip;
412 type Currency = Balances;411 type Currency = Balances;
413 type Event = Event;412 type Event = Event;
414 type RentPayment = ();413 type RentPayment = ();
415 type SignedClaimHandicap = SignedClaimHandicap;414 type SignedClaimHandicap = SignedClaimHandicap;
416 type TombstoneDeposit = TombstoneDeposit;415 type TombstoneDeposit = TombstoneDeposit;
417 type DepositPerContract = DepositPerContract;416 type DepositPerContract = DepositPerContract;
418 type DepositPerStorageByte = DepositPerStorageByte;417 type DepositPerStorageByte = DepositPerStorageByte;
419 type DepositPerStorageItem = DepositPerStorageItem;418 type DepositPerStorageItem = DepositPerStorageItem;
420 type RentFraction = RentFraction;419 type RentFraction = RentFraction;
421 type SurchargeReward = SurchargeReward;420 type SurchargeReward = SurchargeReward;
422 type WeightPrice = pallet_transaction_payment::Module<Self>;421 type WeightPrice = pallet_transaction_payment::Pallet<Self>;
423 type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;422 type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
424 type ChainExtension = NFTExtension;423 type ChainExtension = NFTExtension;
425 type DeletionQueueDepth = DeletionQueueDepth;424 type DeletionQueueDepth = DeletionQueueDepth;
426 type DeletionWeightLimit = DeletionWeightLimit;425 type DeletionWeightLimit = DeletionWeightLimit;
427 type Schedule = Schedule;426 type Schedule = Schedule;
428 type CallStack = [pallet_contracts::Frame<Self>; 31];427 type CallStack = [pallet_contracts::Frame<Self>; 31];
429}428}
430*/429*/
431430
432parameter_types! {431parameter_types! {
433 pub const TransactionByteFee: Balance = 501 * MICROUNIQUE; // Targeting 0.1 Unique per NFT transfer432 pub const TransactionByteFee: Balance = 501 * MICROUNIQUE; // Targeting 0.1 Unique per NFT transfer