difftreelog
feat nest on create/transfer
in: master
12 files changed
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -723,17 +723,20 @@
sender: T::CrossAccountId,
to: T::CrossAccountId,
data: CreateItemData,
+ nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo;
fn create_multiple_items(
&self,
sender: T::CrossAccountId,
to: T::CrossAccountId,
data: Vec<CreateItemData>,
+ nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo;
fn create_multiple_items_ex(
&self,
sender: T::CrossAccountId,
data: CreateItemExData<T::CrossAccountId>,
+ nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo;
fn burn_item(
&self,
@@ -748,6 +751,7 @@
to: T::CrossAccountId,
token: TokenId,
amount: u128,
+ nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo;
fn approve(
&self,
@@ -781,11 +785,12 @@
data: BoundedVec<u8, CustomDataLimit>,
) -> DispatchResultWithPostInfo;
- fn nest_token(
+ fn check_nesting(
&self,
sender: T::CrossAccountId,
- from: (CollectionId, TokenId),
+ from: CollectionId,
under: TokenId,
+ budget: &dyn Budget,
) -> DispatchResult;
fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId>;
pallets/evm-coder-substrate/src/lib.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819#[cfg(not(feature = "std"))]20extern crate alloc;21#[cfg(not(feature = "std"))]22use alloc::format;23use frame_support::dispatch::Weight;2425use core::marker::PhantomData;26use sp_std::cell::RefCell;27use sp_std::vec::Vec;2829use frame_support::pallet_prelude::DispatchError;30use frame_support::traits::PalletInfo;31use frame_support::{ensure, sp_runtime::ModuleError};32use up_data_structs::budget;33use pallet_evm::{34 ExitError, ExitRevert, ExitSucceed, GasWeightMapping, PrecompileFailure, PrecompileOutput,35 PrecompileResult, runner::stack::MaybeMirroredLog,36};37use ethereum::TransactionV2;38use sp_core::{H160, H256};39use pallet_ethereum::EthereumTransactionSender;40// #[cfg(feature = "runtime-benchmarks")]41// pub mod benchmarking;4243use evm_coder::{44 ToLog,45 abi::{AbiReader, AbiWrite, AbiWriter},46 execution::{self, Result},47 types::{Msg, value},48};4950pub use pallet::*;5152#[frame_support::pallet]53pub mod pallet {54 use super::*;5556 use frame_system::ensure_signed;57 pub use frame_support::dispatch::DispatchResult;58 use frame_support::{pallet_prelude::*, traits::PalletInfo};59 use frame_system::pallet_prelude::*;6061 /// DispatchError is opaque, but we need to somehow extract correct error in case of OutOfGas failure62 /// So we have this pallet, which defines OutOfGas error, and knews its own id to check if DispatchError63 /// is thrown because of it64 ///65 /// These errors shouldn't end in extrinsic results, as they only used in evm execution path66 #[pallet::error]67 pub enum Error<T> {68 OutOfGas,69 OutOfFund,70 }7172 #[pallet::config]73 pub trait Config: frame_system::Config {74 type EthereumTransactionSender: pallet_ethereum::EthereumTransactionSender;75 type GasWeightMapping: pallet_evm::GasWeightMapping;76 }7778 #[pallet::pallet]79 pub struct Pallet<T>(_);8081 #[pallet::call]82 impl<T: Config> Pallet<T> {83 #[pallet::weight(0)]84 pub fn empty_call(origin: OriginFor<T>) -> DispatchResult {85 let _sender = ensure_signed(origin)?;86 Ok(())87 }88 }89}9091// From instabul hardfork configuration: https://github.com/rust-blockchain/evm/blob/fd4fd6acc0ca3208d6770fdb3ba407c94cdf97c6/runtime/src/lib.rs#L28492pub const G_SLOAD_WORD: u64 = 800;93pub const G_SSTORE_WORD: u64 = 20000;9495pub fn generate_transaction() -> TransactionV2 {96 use ethereum::{TransactionV0, TransactionAction, TransactionSignature};97 TransactionV2::Legacy(TransactionV0 {98 nonce: 0.into(),99 gas_price: 0.into(),100 gas_limit: 0.into(),101 action: TransactionAction::Call(H160([0; 20])),102 value: 0.into(),103 // zero selector, this transaction always has same sender, so all data should be acquired from logs104 input: Vec::from([0, 0, 0, 0]),105 // if v is not 27 - then we need to pass some other validity checks106 signature: TransactionSignature::new(27, H256([0x88; 32]), H256([0x88; 32])).unwrap(),107 })108}109110pub struct GasCallsBudget<'r, T: Config> {111 recorder: &'r SubstrateRecorder<T>,112 gas_per_call: u64,113}114impl<T: Config> budget::Budget for GasCallsBudget<'_, T> {115 fn consume_custom(&self, calls: u32) -> bool {116 let (gas, overflown) = (calls as u64).overflowing_add(self.gas_per_call);117 if overflown {118 return false;119 }120 self.recorder.consume_gas(gas).is_ok()121 }122}123124#[derive(Default)]125pub struct SubstrateRecorder<T: Config> {126 contract: H160,127 logs: RefCell<Vec<MaybeMirroredLog>>,128 initial_gas: u64,129 gas_limit: RefCell<u64>,130 _phantom: PhantomData<*const T>,131}132133impl<T: Config> SubstrateRecorder<T> {134 pub fn new(contract: H160, gas_limit: u64) -> Self {135 Self {136 contract,137 logs: RefCell::new(Vec::new()),138 initial_gas: gas_limit,139 gas_limit: RefCell::new(gas_limit),140 _phantom: PhantomData,141 }142 }143144 pub fn is_empty(&self) -> bool {145 self.logs.borrow().is_empty()146 }147 // Logs emitted with log_direct appear as substrate evm.Log event148 pub fn log_direct(&self, log: impl ToLog) {149 self.logs150 .borrow_mut()151 .push(MaybeMirroredLog::direct(log.to_log(self.contract)))152 }153 /// If log already has substrate equivalent - then we don't need to emit evm.Log154 pub fn log_mirrored(&self, log: impl ToLog) {155 self.logs156 .borrow_mut()157 .push(MaybeMirroredLog::mirrored(log.to_log(self.contract)))158 }159 pub fn retrieve_logs(self) -> Vec<MaybeMirroredLog> {160 self.logs.into_inner()161 }162163 pub fn gas_left(&self) -> u64 {164 *self.gas_limit.borrow()165 }166 pub fn gas_calls_budget(&self, gas_per_call: u64) -> GasCallsBudget<T> {167 GasCallsBudget {168 recorder: self,169 gas_per_call,170 }171 }172 pub fn weight_calls_budget(&self, weight_per_call: Weight) -> GasCallsBudget<T> {173 GasCallsBudget {174 recorder: self,175 gas_per_call: T::GasWeightMapping::weight_to_gas(weight_per_call),176 }177 }178 pub fn consume_sload_sub(&self) -> DispatchResult {179 self.consume_gas_sub(G_SLOAD_WORD)180 }181 pub fn consume_sstores_sub(&self, amount: usize) -> DispatchResult {182 self.consume_gas_sub(G_SSTORE_WORD.saturating_mul(amount as u64))183 }184 pub fn consume_sstore_sub(&self) -> DispatchResult {185 self.consume_gas_sub(G_SSTORE_WORD)186 }187 pub fn consume_gas_sub(&self, gas: u64) -> DispatchResult {188 ensure!(gas != u64::MAX, Error::<T>::OutOfGas);189 let mut gas_limit = self.gas_limit.borrow_mut();190 ensure!(gas <= *gas_limit, Error::<T>::OutOfGas);191 *gas_limit -= gas;192 Ok(())193 }194195 pub fn consume_sload(&self) -> Result<()> {196 self.consume_gas(G_SLOAD_WORD)197 }198 pub fn consume_sstore(&self) -> Result<()> {199 self.consume_gas(G_SSTORE_WORD)200 }201 pub fn consume_gas(&self, gas: u64) -> Result<()> {202 if gas == u64::MAX {203 return Err(execution::Error::Error(ExitError::OutOfGas));204 }205 let mut gas_limit = self.gas_limit.borrow_mut();206 if gas > *gas_limit {207 return Err(execution::Error::Error(ExitError::OutOfGas));208 }209 *gas_limit -= gas;210 Ok(())211 }212 pub fn return_gas(&self, gas: u64) {213 let mut gas_limit = self.gas_limit.borrow_mut();214 *gas_limit += gas;215 }216217 pub fn evm_to_precompile_output(218 self,219 result: evm_coder::execution::Result<Option<AbiWriter>>,220 ) -> Option<PrecompileResult> {221 use evm_coder::execution::Error;222 Some(match result {223 Ok(Some(v)) => Ok(PrecompileOutput {224 exit_status: ExitSucceed::Returned,225 cost: self.initial_gas - self.gas_left(),226 // TODO: preserve mirroring status227 logs: self.retrieve_logs().into_iter().map(|l| l.log).collect(),228 output: v.finish(),229 }),230 Ok(None) => return None,231 Err(Error::Revert(e)) => {232 let mut writer = AbiWriter::new_call(evm_coder::fn_selector!(Error(string)));233 (&e as &str).abi_write(&mut writer);234235 Err(PrecompileFailure::Revert {236 exit_status: ExitRevert::Reverted,237 cost: self.initial_gas - self.gas_left(),238 output: writer.finish(),239 })240 }241 Err(Error::Fatal(f)) => Err(f.into()),242 Err(Error::Error(e)) => Err(e.into()),243 })244 }245246 pub fn submit_logs(self) {247 let logs = self.retrieve_logs();248 if logs.is_empty() {249 return;250 }251 T::EthereumTransactionSender::submit_logs_transaction(252 Default::default(),253 generate_transaction(),254 logs,255 )256 }257}258259pub fn dispatch_to_evm<T: Config>(err: DispatchError) -> evm_coder::execution::Error {260 use evm_coder::execution::Error as ExError;261 match err {262 DispatchError::Module(ModuleError { index, error, .. })263 if index264 == T::PalletInfo::index::<Pallet<T>>()265 .expect("evm-coder-substrate is a pallet, which should be added to runtime")266 as u8 =>267 {268 match error {269 v if v == Error::<T>::OutOfGas.as_u8() => ExError::Error(ExitError::OutOfGas),270 v if v == Error::<T>::OutOfFund.as_u8() => ExError::Error(ExitError::OutOfFund),271 _ => unreachable!("this pallet only defines two possible errors"),272 }273 }274 DispatchError::Module(ModuleError {275 message: Some(msg), ..276 }) => ExError::Revert(msg.into()),277 DispatchError::Module(ModuleError { index, error, .. }) => {278 ExError::Revert(format!("error {} in pallet {}", error, index))279 }280 e => ExError::Revert(format!("substrate error: {:?}", e)),281 }282}283284pub trait WithRecorder<T: Config> {285 fn recorder(&self) -> &SubstrateRecorder<T>;286 fn into_recorder(self) -> SubstrateRecorder<T>;287}288289/// Helper to simplify implementing bridge between evm-coder definitions and pallet-evm290pub fn call<291 T: Config,292 C: evm_coder::Call + evm_coder::Weighted,293 E: evm_coder::Callable<C> + WithRecorder<T>,294>(295 caller: H160,296 mut e: E,297 value: value,298 input: &[u8],299) -> Option<PrecompileResult> {300 let result = call_internal(caller, &mut e, value, input);301 e.into_recorder().evm_to_precompile_output(result)302}303304fn call_internal<305 T: Config,306 C: evm_coder::Call + evm_coder::Weighted,307 E: evm_coder::Callable<C> + WithRecorder<T>,308>(309 caller: H160,310 e: &mut E,311 value: value,312 input: &[u8],313) -> evm_coder::execution::Result<Option<AbiWriter>> {314 let (selector, mut reader) = AbiReader::new_call(input)?;315 let call = C::parse(selector, &mut reader)?;316 if call.is_none() {317 return Ok(None);318 }319 let call = call.unwrap();320321 let dispatch_info = call.weight();322 e.recorder()323 .consume_gas(T::GasWeightMapping::weight_to_gas(dispatch_info.weight))?;324325 match e.call(Msg {326 call,327 caller,328 value,329 }) {330 Ok(v) => {331 let unspent = v.post_info.calc_unspent(&dispatch_info);332 e.recorder()333 .return_gas(T::GasWeightMapping::weight_to_gas(unspent));334 Ok(Some(v.data))335 }336 Err(v) => {337 let unspent = v.post_info.calc_unspent(&dispatch_info);338 e.recorder()339 .return_gas(T::GasWeightMapping::weight_to_gas(unspent));340 Err(v.data)341 }342 }343}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819#[cfg(not(feature = "std"))]20extern crate alloc;21#[cfg(not(feature = "std"))]22use alloc::format;23use frame_support::dispatch::Weight;2425use core::marker::PhantomData;26use sp_std::cell::RefCell;27use sp_std::vec::Vec;2829use frame_support::pallet_prelude::DispatchError;30use frame_support::traits::PalletInfo;31use frame_support::{ensure, sp_runtime::ModuleError};32use up_data_structs::budget;33use pallet_evm::{34 ExitError, ExitRevert, ExitSucceed, GasWeightMapping, PrecompileFailure, PrecompileOutput,35 PrecompileResult, runner::stack::MaybeMirroredLog,36};37use ethereum::TransactionV2;38use sp_core::{H160, H256};39use pallet_ethereum::EthereumTransactionSender;40// #[cfg(feature = "runtime-benchmarks")]41// pub mod benchmarking;4243use evm_coder::{44 ToLog,45 abi::{AbiReader, AbiWrite, AbiWriter},46 execution::{self, Result},47 types::{Msg, value},48};4950pub use pallet::*;5152#[frame_support::pallet]53pub mod pallet {54 use super::*;5556 use frame_system::ensure_signed;57 pub use frame_support::dispatch::DispatchResult;58 use frame_system::pallet_prelude::*;5960 /// DispatchError is opaque, but we need to somehow extract correct error in case of OutOfGas failure61 /// So we have this pallet, which defines OutOfGas error, and knews its own id to check if DispatchError62 /// is thrown because of it63 ///64 /// These errors shouldn't end in extrinsic results, as they only used in evm execution path65 #[pallet::error]66 pub enum Error<T> {67 OutOfGas,68 OutOfFund,69 }7071 #[pallet::config]72 pub trait Config: frame_system::Config {73 type EthereumTransactionSender: pallet_ethereum::EthereumTransactionSender;74 type GasWeightMapping: pallet_evm::GasWeightMapping;75 }7677 #[pallet::pallet]78 pub struct Pallet<T>(_);7980 #[pallet::call]81 impl<T: Config> Pallet<T> {82 #[pallet::weight(0)]83 pub fn empty_call(origin: OriginFor<T>) -> DispatchResult {84 let _sender = ensure_signed(origin)?;85 Ok(())86 }87 }88}8990// From instabul hardfork configuration: https://github.com/rust-blockchain/evm/blob/fd4fd6acc0ca3208d6770fdb3ba407c94cdf97c6/runtime/src/lib.rs#L28491pub const G_SLOAD_WORD: u64 = 800;92pub const G_SSTORE_WORD: u64 = 20000;9394pub fn generate_transaction() -> TransactionV2 {95 use ethereum::{TransactionV0, TransactionAction, TransactionSignature};96 TransactionV2::Legacy(TransactionV0 {97 nonce: 0.into(),98 gas_price: 0.into(),99 gas_limit: 0.into(),100 action: TransactionAction::Call(H160([0; 20])),101 value: 0.into(),102 // zero selector, this transaction always has same sender, so all data should be acquired from logs103 input: Vec::from([0, 0, 0, 0]),104 // if v is not 27 - then we need to pass some other validity checks105 signature: TransactionSignature::new(27, H256([0x88; 32]), H256([0x88; 32])).unwrap(),106 })107}108109pub struct GasCallsBudget<'r, T: Config> {110 recorder: &'r SubstrateRecorder<T>,111 gas_per_call: u64,112}113impl<T: Config> budget::Budget for GasCallsBudget<'_, T> {114 fn consume_custom(&self, calls: u32) -> bool {115 let (gas, overflown) = (calls as u64).overflowing_add(self.gas_per_call);116 if overflown {117 return false;118 }119 self.recorder.consume_gas(gas).is_ok()120 }121}122123#[derive(Default)]124pub struct SubstrateRecorder<T: Config> {125 contract: H160,126 logs: RefCell<Vec<MaybeMirroredLog>>,127 initial_gas: u64,128 gas_limit: RefCell<u64>,129 _phantom: PhantomData<*const T>,130}131132impl<T: Config> SubstrateRecorder<T> {133 pub fn new(contract: H160, gas_limit: u64) -> Self {134 Self {135 contract,136 logs: RefCell::new(Vec::new()),137 initial_gas: gas_limit,138 gas_limit: RefCell::new(gas_limit),139 _phantom: PhantomData,140 }141 }142143 pub fn is_empty(&self) -> bool {144 self.logs.borrow().is_empty()145 }146 // Logs emitted with log_direct appear as substrate evm.Log event147 pub fn log_direct(&self, log: impl ToLog) {148 self.logs149 .borrow_mut()150 .push(MaybeMirroredLog::direct(log.to_log(self.contract)))151 }152 /// If log already has substrate equivalent - then we don't need to emit evm.Log153 pub fn log_mirrored(&self, log: impl ToLog) {154 self.logs155 .borrow_mut()156 .push(MaybeMirroredLog::mirrored(log.to_log(self.contract)))157 }158 pub fn retrieve_logs(self) -> Vec<MaybeMirroredLog> {159 self.logs.into_inner()160 }161162 pub fn gas_left(&self) -> u64 {163 *self.gas_limit.borrow()164 }165 pub fn gas_calls_budget(&self, gas_per_call: u64) -> GasCallsBudget<T> {166 GasCallsBudget {167 recorder: self,168 gas_per_call,169 }170 }171 pub fn weight_calls_budget(&self, weight_per_call: Weight) -> GasCallsBudget<T> {172 GasCallsBudget {173 recorder: self,174 gas_per_call: T::GasWeightMapping::weight_to_gas(weight_per_call),175 }176 }177 pub fn consume_sload_sub(&self) -> DispatchResult {178 self.consume_gas_sub(G_SLOAD_WORD)179 }180 pub fn consume_sstores_sub(&self, amount: usize) -> DispatchResult {181 self.consume_gas_sub(G_SSTORE_WORD.saturating_mul(amount as u64))182 }183 pub fn consume_sstore_sub(&self) -> DispatchResult {184 self.consume_gas_sub(G_SSTORE_WORD)185 }186 pub fn consume_gas_sub(&self, gas: u64) -> DispatchResult {187 ensure!(gas != u64::MAX, Error::<T>::OutOfGas);188 let mut gas_limit = self.gas_limit.borrow_mut();189 ensure!(gas <= *gas_limit, Error::<T>::OutOfGas);190 *gas_limit -= gas;191 Ok(())192 }193194 pub fn consume_sload(&self) -> Result<()> {195 self.consume_gas(G_SLOAD_WORD)196 }197 pub fn consume_sstore(&self) -> Result<()> {198 self.consume_gas(G_SSTORE_WORD)199 }200 pub fn consume_gas(&self, gas: u64) -> Result<()> {201 if gas == u64::MAX {202 return Err(execution::Error::Error(ExitError::OutOfGas));203 }204 let mut gas_limit = self.gas_limit.borrow_mut();205 if gas > *gas_limit {206 return Err(execution::Error::Error(ExitError::OutOfGas));207 }208 *gas_limit -= gas;209 Ok(())210 }211 pub fn return_gas(&self, gas: u64) {212 let mut gas_limit = self.gas_limit.borrow_mut();213 *gas_limit += gas;214 }215216 pub fn evm_to_precompile_output(217 self,218 result: evm_coder::execution::Result<Option<AbiWriter>>,219 ) -> Option<PrecompileResult> {220 use evm_coder::execution::Error;221 Some(match result {222 Ok(Some(v)) => Ok(PrecompileOutput {223 exit_status: ExitSucceed::Returned,224 cost: self.initial_gas - self.gas_left(),225 // TODO: preserve mirroring status226 logs: self.retrieve_logs().into_iter().map(|l| l.log).collect(),227 output: v.finish(),228 }),229 Ok(None) => return None,230 Err(Error::Revert(e)) => {231 let mut writer = AbiWriter::new_call(evm_coder::fn_selector!(Error(string)));232 (&e as &str).abi_write(&mut writer);233234 Err(PrecompileFailure::Revert {235 exit_status: ExitRevert::Reverted,236 cost: self.initial_gas - self.gas_left(),237 output: writer.finish(),238 })239 }240 Err(Error::Fatal(f)) => Err(f.into()),241 Err(Error::Error(e)) => Err(e.into()),242 })243 }244245 pub fn submit_logs(self) {246 let logs = self.retrieve_logs();247 if logs.is_empty() {248 return;249 }250 T::EthereumTransactionSender::submit_logs_transaction(251 Default::default(),252 generate_transaction(),253 logs,254 )255 }256}257258pub fn dispatch_to_evm<T: Config>(err: DispatchError) -> evm_coder::execution::Error {259 use evm_coder::execution::Error as ExError;260 match err {261 DispatchError::Module(ModuleError { index, error, .. })262 if index263 == T::PalletInfo::index::<Pallet<T>>()264 .expect("evm-coder-substrate is a pallet, which should be added to runtime")265 as u8 =>266 {267 match error {268 v if v == Error::<T>::OutOfGas.as_u8() => ExError::Error(ExitError::OutOfGas),269 v if v == Error::<T>::OutOfFund.as_u8() => ExError::Error(ExitError::OutOfFund),270 _ => unreachable!("this pallet only defines two possible errors"),271 }272 }273 DispatchError::Module(ModuleError {274 message: Some(msg), ..275 }) => ExError::Revert(msg.into()),276 DispatchError::Module(ModuleError { index, error, .. }) => {277 ExError::Revert(format!("error {} in pallet {}", error, index))278 }279 e => ExError::Revert(format!("substrate error: {:?}", e)),280 }281}282283pub trait WithRecorder<T: Config> {284 fn recorder(&self) -> &SubstrateRecorder<T>;285 fn into_recorder(self) -> SubstrateRecorder<T>;286}287288/// Helper to simplify implementing bridge between evm-coder definitions and pallet-evm289pub fn call<290 T: Config,291 C: evm_coder::Call + evm_coder::Weighted,292 E: evm_coder::Callable<C> + WithRecorder<T>,293>(294 caller: H160,295 mut e: E,296 value: value,297 input: &[u8],298) -> Option<PrecompileResult> {299 let result = call_internal(caller, &mut e, value, input);300 e.into_recorder().evm_to_precompile_output(result)301}302303fn call_internal<304 T: Config,305 C: evm_coder::Call + evm_coder::Weighted,306 E: evm_coder::Callable<C> + WithRecorder<T>,307>(308 caller: H160,309 e: &mut E,310 value: value,311 input: &[u8],312) -> evm_coder::execution::Result<Option<AbiWriter>> {313 let (selector, mut reader) = AbiReader::new_call(input)?;314 let call = C::parse(selector, &mut reader)?;315 if call.is_none() {316 return Ok(None);317 }318 let call = call.unwrap();319320 let dispatch_info = call.weight();321 e.recorder()322 .consume_gas(T::GasWeightMapping::weight_to_gas(dispatch_info.weight))?;323324 match e.call(Msg {325 call,326 caller,327 value,328 }) {329 Ok(v) => {330 let unspent = v.post_info.calc_unspent(&dispatch_info);331 e.recorder()332 .return_gas(T::GasWeightMapping::weight_to_gas(unspent));333 Ok(Some(v.data))334 }335 Err(v) => {336 let unspent = v.post_info.calc_unspent(&dispatch_info);337 e.recorder()338 .return_gas(T::GasWeightMapping::weight_to_gas(unspent));339 Err(v.data)340 }341 }342}pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -17,7 +17,7 @@
use core::marker::PhantomData;
use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, BoundedVec};
-use up_data_structs::{TokenId, CreateItemExData, budget::Budget};
+use up_data_structs::{TokenId, CollectionId, CreateItemExData, budget::Budget};
use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
use sp_runtime::ArithmeticError;
use sp_std::{vec::Vec, vec};
@@ -78,10 +78,11 @@
sender: T::CrossAccountId,
to: T::CrossAccountId,
data: up_data_structs::CreateItemData,
+ nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
match data {
up_data_structs::CreateItemData::Fungible(data) => with_weight(
- <Pallet<T>>::create_item(self, &sender, (to, data.value)),
+ <Pallet<T>>::create_item(self, &sender, (to, data.value), nesting_budget),
<CommonWeights<T>>::create_item(),
),
_ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),
@@ -93,6 +94,7 @@
sender: T::CrossAccountId,
to: T::CrossAccountId,
data: Vec<up_data_structs::CreateItemData>,
+ nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
let mut sum: u128 = 0;
for data in data {
@@ -107,7 +109,7 @@
}
with_weight(
- <Pallet<T>>::create_item(self, &sender, (to, sum)),
+ <Pallet<T>>::create_item(self, &sender, (to, sum), nesting_budget),
<CommonWeights<T>>::create_item(),
)
}
@@ -116,6 +118,7 @@
&self,
sender: <T>::CrossAccountId,
data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,
+ nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);
let data = match data {
@@ -124,7 +127,7 @@
};
with_weight(
- <Pallet<T>>::create_multiple_items(self, &sender, data.into_inner()),
+ <Pallet<T>>::create_multiple_items(self, &sender, data.into_inner(), nesting_budget),
weight,
)
}
@@ -152,6 +155,7 @@
to: T::CrossAccountId,
token: TokenId,
amount: u128,
+ nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
ensure!(
token == TokenId::default(),
@@ -159,7 +163,7 @@
);
with_weight(
- <Pallet<T>>::transfer(self, &from, &to, amount),
+ <Pallet<T>>::transfer(self, &from, &to, amount, nesting_budget),
<CommonWeights<T>>::transfer(),
)
}
@@ -230,11 +234,12 @@
fail!(<Error<T>>::FungibleItemsDontHaveData)
}
- fn nest_token(
+ fn check_nesting(
&self,
_sender: <T>::CrossAccountId,
- _from: (up_data_structs::CollectionId, TokenId),
+ _from: CollectionId,
_under: TokenId,
+ _budget: &dyn Budget,
) -> sp_runtime::DispatchResult {
fail!(<Error<T>>::FungibleDisallowsNesting)
}
pallets/fungible/src/erc.rsdiffbeforeafterboth--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -81,8 +81,11 @@
let caller = T::CrossAccountId::from_eth(caller);
let to = T::CrossAccountId::from_eth(to);
let amount = amount.try_into().map_err(|_| "amount overflow")?;
+ let budget = self
+ .recorder
+ .weight_calls_budget(<StructureWeight<T>>::find_parent());
- <Pallet<T>>::transfer(self, &caller, &to, amount).map_err(|_| "transfer error")?;
+ <Pallet<T>>::transfer(self, &caller, &to, amount, &budget).map_err(|_| "transfer error")?;
Ok(true)
}
#[weight(<SelfWeightOf<T>>::transfer_from())]
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -193,6 +193,7 @@
from: &T::CrossAccountId,
to: &T::CrossAccountId,
amount: u128,
+ nesting_budget: &dyn Budget,
) -> DispatchResult {
ensure!(
collection.limits.transfers_enabled(),
@@ -222,12 +223,12 @@
let handle = <CollectionHandle<T>>::try_get(target.0)?;
let dispatch = T::CollectionDispatch::dispatch(handle);
let dispatch = dispatch.as_dyn();
-
- // =========
- dispatch.nest_token(from.clone(), (collection.id, TokenId::default()), target.1)?;
+ dispatch.check_nesting(from.clone(), collection.id, target.1, nesting_budget)?;
}
+ // =========
+
if let Some(balance_to) = balance_to {
// from != to
if balance_from == 0 {
@@ -257,6 +258,7 @@
collection: &FungibleHandle<T>,
sender: &T::CrossAccountId,
data: BTreeMap<T::CrossAccountId, u128>,
+ nesting_budget: &dyn Budget,
) -> DispatchResult {
if !collection.is_owner_or_admin(sender) {
ensure!(
@@ -285,6 +287,16 @@
.ok_or(ArithmeticError::Overflow)?;
}
+ for (to, _) in balances.iter() {
+ if let Some(target) = T::CrossTokenAddressMapping::address_to_token(to) {
+ let handle = <CollectionHandle<T>>::try_get(target.0)?;
+ let dispatch = T::CollectionDispatch::dispatch(handle);
+ let dispatch = dispatch.as_dyn();
+
+ dispatch.check_nesting(sender.clone(), collection.id, target.1, nesting_budget)?;
+ }
+ }
+
// =========
<TotalSupply<T>>::insert(collection.id, total_supply);
@@ -407,7 +419,7 @@
// =========
- Self::transfer(collection, from, to, amount)?;
+ Self::transfer(collection, from, to, amount, nesting_budget)?;
if let Some(allowance) = allowance {
Self::set_allowance_unchecked(collection, from, spender, allowance);
}
@@ -437,7 +449,13 @@
collection: &FungibleHandle<T>,
sender: &T::CrossAccountId,
data: CreateItemData<T>,
+ nesting_budget: &dyn Budget,
) -> DispatchResult {
- Self::create_multiple_items(collection, sender, [(data.0, data.1)].into_iter().collect())
+ Self::create_multiple_items(
+ collection,
+ sender,
+ [(data.0, data.1)].into_iter().collect(),
+ nesting_budget,
+ )
}
}
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -89,9 +89,15 @@
sender: T::CrossAccountId,
to: T::CrossAccountId,
data: up_data_structs::CreateItemData,
+ nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
with_weight(
- <Pallet<T>>::create_item(self, &sender, map_create_data::<T>(data, &to)?),
+ <Pallet<T>>::create_item(
+ self,
+ &sender,
+ map_create_data::<T>(data, &to)?,
+ nesting_budget,
+ ),
<CommonWeights<T>>::create_item(),
)
}
@@ -101,6 +107,7 @@
sender: T::CrossAccountId,
to: T::CrossAccountId,
data: Vec<up_data_structs::CreateItemData>,
+ nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
let data = data
.into_iter()
@@ -109,7 +116,7 @@
let amount = data.len();
with_weight(
- <Pallet<T>>::create_multiple_items(self, &sender, data),
+ <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),
<CommonWeights<T>>::create_multiple_items(amount as u32),
)
}
@@ -118,6 +125,7 @@
&self,
sender: <T>::CrossAccountId,
data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,
+ nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);
let data = match data {
@@ -126,7 +134,7 @@
};
with_weight(
- <Pallet<T>>::create_multiple_items(self, &sender, data.into_inner()),
+ <Pallet<T>>::create_multiple_items(self, &sender, data.into_inner(), nesting_budget),
weight,
)
}
@@ -154,11 +162,12 @@
to: T::CrossAccountId,
token: TokenId,
amount: u128,
+ nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);
if amount == 1 {
with_weight(
- <Pallet<T>>::transfer(self, &from, &to, token),
+ <Pallet<T>>::transfer(self, &from, &to, token, nesting_budget),
<CommonWeights<T>>::transfer(),
)
} else {
@@ -239,13 +248,14 @@
)
}
- fn nest_token(
+ fn check_nesting(
&self,
sender: T::CrossAccountId,
- (from, _): (CollectionId, TokenId),
+ from: CollectionId,
under: TokenId,
+ budget: &dyn Budget,
) -> sp_runtime::DispatchResult {
- <Pallet<T>>::nest_token(self, sender, from, under)
+ <Pallet<T>>::check_nesting(self, sender, from, under, budget)
}
fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -256,6 +256,10 @@
let caller = T::CrossAccountId::from_eth(caller);
let to = T::CrossAccountId::from_eth(to);
let token_id: u32 = token_id.try_into()?;
+ let budget = self
+ .recorder
+ .weight_calls_budget(<StructureWeight<T>>::find_parent());
+
if <TokensMinted<T>>::get(self.id)
.checked_add(1)
.ok_or("item id overflow")?
@@ -272,6 +276,7 @@
variable_data: BoundedVec::default(),
owner: to,
},
+ &budget,
)
.map_err(dispatch_to_evm::<T>)?;
@@ -296,6 +301,10 @@
let caller = T::CrossAccountId::from_eth(caller);
let to = T::CrossAccountId::from_eth(to);
let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;
+ let budget = self
+ .recorder
+ .weight_calls_budget(<StructureWeight<T>>::find_parent());
+
if <TokensMinted<T>>::get(self.id)
.checked_add(1)
.ok_or("item id overflow")?
@@ -314,6 +323,7 @@
variable_data: BoundedVec::default(),
owner: to,
},
+ &budget,
)
.map_err(dispatch_to_evm::<T>)?;
Ok(true)
@@ -338,8 +348,11 @@
let caller = T::CrossAccountId::from_eth(caller);
let to = T::CrossAccountId::from_eth(to);
let token = token_id.try_into()?;
+ let budget = self
+ .recorder
+ .weight_calls_budget(<StructureWeight<T>>::find_parent());
- <Pallet<T>>::transfer(self, &caller, &to, token).map_err(dispatch_to_evm::<T>)?;
+ <Pallet<T>>::transfer(self, &caller, &to, token, &budget).map_err(dispatch_to_evm::<T>)?;
Ok(())
}
@@ -409,6 +422,9 @@
let mut expected_index = <TokensMinted<T>>::get(self.id)
.checked_add(1)
.ok_or("item id overflow")?;
+ let budget = self
+ .recorder
+ .weight_calls_budget(<StructureWeight<T>>::find_parent());
let total_tokens = token_ids.len();
for id in token_ids.into_iter() {
@@ -426,7 +442,8 @@
})
.collect();
- <Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;
+ <Pallet<T>>::create_multiple_items(self, &caller, data, &budget)
+ .map_err(dispatch_to_evm::<T>)?;
Ok(true)
}
@@ -447,6 +464,9 @@
let mut expected_index = <TokensMinted<T>>::get(self.id)
.checked_add(1)
.ok_or("item id overflow")?;
+ let budget = self
+ .recorder
+ .weight_calls_budget(<StructureWeight<T>>::find_parent());
let mut data = Vec::with_capacity(tokens.len());
for (id, token_uri) in tokens {
@@ -465,7 +485,8 @@
});
}
- <Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;
+ <Pallet<T>>::create_multiple_items(self, &caller, data, &budget)
+ .map_err(dispatch_to_evm::<T>)?;
Ok(true)
}
}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -251,6 +251,7 @@
from: &T::CrossAccountId,
to: &T::CrossAccountId,
token: TokenId,
+ nesting_budget: &dyn Budget,
) -> DispatchResult {
ensure!(
collection.limits.transfers_enabled(),
@@ -294,12 +295,12 @@
let handle = <CollectionHandle<T>>::try_get(target.0)?;
let dispatch = T::CollectionDispatch::dispatch(handle);
let dispatch = dispatch.as_dyn();
-
- // =========
- dispatch.nest_token(from.clone(), (collection.id, token), target.1)?;
+ dispatch.check_nesting(from.clone(), collection.id, target.1, nesting_budget)?;
}
+ // =========
+
<TokenData<T>>::insert(
(collection.id, token),
ItemData {
@@ -340,6 +341,7 @@
collection: &NonfungibleHandle<T>,
sender: &T::CrossAccountId,
data: Vec<CreateItemData<T>>,
+ nesting_budget: &dyn Budget,
) -> DispatchResult {
if !collection.is_owner_or_admin(sender) {
ensure!(
@@ -379,6 +381,16 @@
);
}
+ for (to, _) in balances.iter() {
+ if let Some(target) = T::CrossTokenAddressMapping::address_to_token(to) {
+ let handle = <CollectionHandle<T>>::try_get(target.0)?;
+ let dispatch = T::CollectionDispatch::dispatch(handle);
+ let dispatch = dispatch.as_dyn();
+
+ dispatch.check_nesting(sender.clone(), collection.id, target.1, nesting_budget)?;
+ }
+ }
+
// =========
<TokensMinted<T>>::insert(collection.id, tokens_minted);
@@ -556,7 +568,7 @@
// =========
// Allowance is reset in [`transfer`]
- Self::transfer(collection, from, to, token)
+ Self::transfer(collection, from, to, token, nesting_budget)
}
pub fn burn_from(
@@ -595,35 +607,34 @@
Ok(())
}
- pub fn nest_token(
+ pub fn check_nesting(
handle: &NonfungibleHandle<T>,
sender: T::CrossAccountId,
from: CollectionId,
under: TokenId,
+ nesting_budget: &dyn Budget,
) -> DispatchResult {
fn ensure_sender_allowed<T: Config>(
collection: CollectionId,
token: TokenId,
sender: T::CrossAccountId,
+ budget: &dyn Budget,
) -> DispatchResult {
ensure!(
- <TokenData<T>>::get((collection, token))
- .ok_or(<CommonError<T>>::TokenNotFound)?
- .owner
- .conv_eq(&sender),
+ <PalletStructure<T>>::indirectly_owned(sender, collection, token, budget)?,
<CommonError<T>>::OnlyOwnerAllowedToNest,
);
Ok(())
}
match handle.limits.nesting_rule() {
NestingRule::Disabled => fail!(<CommonError<T>>::NestingIsDisabled),
- NestingRule::Owner => ensure_sender_allowed::<T>(from, under, sender)?,
+ NestingRule::Owner => ensure_sender_allowed::<T>(from, under, sender, nesting_budget)?,
NestingRule::OwnerRestricted(whitelist) => {
ensure!(
whitelist.contains(&from),
<CommonError<T>>::SourceCollectionIsNotAllowedToNest
);
- ensure_sender_allowed::<T>(from, under, sender)?
+ ensure_sender_allowed::<T>(from, under, sender, nesting_budget)?
}
}
Ok(())
@@ -634,7 +645,8 @@
collection: &NonfungibleHandle<T>,
sender: &T::CrossAccountId,
data: CreateItemData<T>,
+ nesting_budget: &dyn Budget,
) -> DispatchResult {
- Self::create_multiple_items(collection, sender, vec![data])
+ Self::create_multiple_items(collection, sender, vec![data], nesting_budget)
}
}
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -19,7 +19,8 @@
use sp_std::collections::btree_map::BTreeMap;
use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight, BoundedVec};
use up_data_structs::{
- TokenId, CustomDataLimit, CreateItemExData, CreateRefungibleExData, budget::Budget,
+ CollectionId, TokenId, CustomDataLimit, CreateItemExData, CreateRefungibleExData,
+ budget::Budget,
};
use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
use sp_runtime::DispatchError;
@@ -120,9 +121,15 @@
sender: T::CrossAccountId,
to: T::CrossAccountId,
data: up_data_structs::CreateItemData,
+ nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
with_weight(
- <Pallet<T>>::create_item(self, &sender, map_create_data::<T>(data, &to)?),
+ <Pallet<T>>::create_item(
+ self,
+ &sender,
+ map_create_data::<T>(data, &to)?,
+ nesting_budget,
+ ),
<CommonWeights<T>>::create_item(),
)
}
@@ -132,6 +139,7 @@
sender: T::CrossAccountId,
to: T::CrossAccountId,
data: Vec<up_data_structs::CreateItemData>,
+ nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
let data = data
.into_iter()
@@ -140,7 +148,7 @@
let amount = data.len();
with_weight(
- <Pallet<T>>::create_multiple_items(self, &sender, data),
+ <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),
<CommonWeights<T>>::create_multiple_items(amount as u32),
)
}
@@ -149,6 +157,7 @@
&self,
sender: <T>::CrossAccountId,
data: CreateItemExData<T::CrossAccountId>,
+ nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);
let data = match data {
@@ -162,7 +171,7 @@
};
with_weight(
- <Pallet<T>>::create_multiple_items(self, &sender, data),
+ <Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),
weight,
)
}
@@ -185,9 +194,10 @@
to: T::CrossAccountId,
token: TokenId,
amount: u128,
+ nesting_budget: &dyn Budget,
) -> DispatchResultWithPostInfo {
with_weight(
- <Pallet<T>>::transfer(self, &from, &to, token, amount),
+ <Pallet<T>>::transfer(self, &from, &to, token, amount, nesting_budget),
<CommonWeights<T>>::transfer(),
)
}
@@ -247,11 +257,12 @@
)
}
- fn nest_token(
+ fn check_nesting(
&self,
_sender: <T>::CrossAccountId,
- _from: (up_data_structs::CollectionId, TokenId),
+ _from: CollectionId,
_under: TokenId,
+ _budget: &dyn Budget,
) -> sp_runtime::DispatchResult {
fail!(<Error<T>>::RefungibleDisallowsNesting)
}
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -289,6 +289,7 @@
to: &T::CrossAccountId,
token: TokenId,
amount: u128,
+ nesting_budget: &dyn Budget,
) -> DispatchResult {
ensure!(
collection.limits.transfers_enabled(),
@@ -351,10 +352,10 @@
let dispatch = T::CollectionDispatch::dispatch(handle);
let dispatch = dispatch.as_dyn();
- // =========
+ dispatch.check_nesting(from.clone(), collection.id, target.1, nesting_budget)?;
+ }
- dispatch.nest_token(from.clone(), (collection.id, token), target.1)?;
- }
+ // =========
if let Some(balance_to) = balance_to {
// from != to
@@ -389,6 +390,7 @@
collection: &RefungibleHandle<T>,
sender: &T::CrossAccountId,
data: Vec<CreateRefungibleExData<T::CrossAccountId>>,
+ nesting_budget: &dyn Budget,
) -> DispatchResult {
if !collection.is_owner_or_admin(sender) {
ensure!(
@@ -453,6 +455,23 @@
}
}
+ for token in data.iter() {
+ for (to, _) in token.users.iter() {
+ if let Some(target) = T::CrossTokenAddressMapping::address_to_token(to) {
+ let handle = <CollectionHandle<T>>::try_get(target.0)?;
+ let dispatch = T::CollectionDispatch::dispatch(handle);
+ let dispatch = dispatch.as_dyn();
+
+ dispatch.check_nesting(
+ sender.clone(),
+ collection.id,
+ target.1,
+ nesting_budget,
+ )?;
+ }
+ }
+ }
+
// =========
<TokensMinted<T>>::insert(collection.id, tokens_minted);
@@ -591,7 +610,7 @@
// =========
- Self::transfer(collection, from, to, token, amount)?;
+ Self::transfer(collection, from, to, token, amount, nesting_budget)?;
if let Some(allowance) = allowance {
Self::set_allowance_unchecked(collection, from, spender, token, allowance);
}
@@ -648,7 +667,8 @@
collection: &RefungibleHandle<T>,
sender: &T::CrossAccountId,
data: CreateRefungibleExData<T::CrossAccountId>,
+ nesting_budget: &dyn Budget,
) -> DispatchResult {
- Self::create_multiple_items(collection, sender, vec![data])
+ Self::create_multiple_items(collection, sender, vec![data], nesting_budget)
}
}
pallets/structure/src/lib.rsdiffbeforeafterboth--- a/pallets/structure/src/lib.rs
+++ b/pallets/structure/src/lib.rs
@@ -19,7 +19,6 @@
use frame_support::Parameter;
use frame_support::dispatch::{GetDispatchInfo, UnfilteredDispatchable};
use frame_support::pallet_prelude::*;
- use frame_system::pallet_prelude::*;
use super::*;
pallets/unique/src/lib.rsdiffbeforeafterboth--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -693,8 +693,9 @@
#[transactional]
pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+ let budget = budget::Value::new(2);
- dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data))
+ dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))
}
/// This method creates multiple items in a collection created with CreateCollection method.
@@ -720,16 +721,18 @@
pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {
ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+ let budget = budget::Value::new(2);
- dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data))
+ dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))
}
#[weight = <CommonWeights<T>>::create_multiple_items_ex(&data)]
#[transactional]
pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+ let budget = budget::Value::new(2);
- dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data))
+ dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))
}
// TODO! transaction weight
@@ -839,8 +842,9 @@
#[transactional]
pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+ let budget = budget::Value::new(2);
- dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value))
+ dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))
}
/// Set, change, or remove approved address to transfer the ownership of the NFT.