difftreelog
feat burn_from
in: master
12 files changed
pallets/common/src/lib.rsdiffbeforeafterboth459 fn transfer() -> Weight;459 fn transfer() -> Weight;460 fn approve() -> Weight;460 fn approve() -> Weight;461 fn transfer_from() -> Weight;461 fn transfer_from() -> Weight;462 fn burn_from() -> Weight;462 fn set_variable_metadata(bytes: u32) -> Weight;463 fn set_variable_metadata(bytes: u32) -> Weight;463}464}464465504 token: TokenId,505 token: TokenId,505 amount: u128,506 amount: u128,506 ) -> DispatchResultWithPostInfo;507 ) -> DispatchResultWithPostInfo;508 fn burn_from(509 &self,510 sender: T::CrossAccountId,511 from: T::CrossAccountId,512 token: TokenId,513 amount: u128,514 ) -> DispatchResultWithPostInfo;507515508 fn set_variable_metadata(516 fn set_variable_metadata(509 &self,517 &self,pallets/fungible/src/common.rsdiffbeforeafterboth38 <SelfWeightOf<T>>::transfer_from()38 <SelfWeightOf<T>>::transfer_from()39 }39 }4041 fn burn_from() -> Weight {42 043 }404441 fn set_variable_metadata(_bytes: u32) -> Weight {45 fn set_variable_metadata(_bytes: u32) -> Weight {42 // Error46 // Error156 )160 )157 }161 }162163 fn burn_from(164 &self,165 sender: T::CrossAccountId,166 from: T::CrossAccountId,167 token: TokenId,168 amount: u128,169 ) -> DispatchResultWithPostInfo {170 ensure!(171 token == TokenId::default(),172 <Error<T>>::FungibleItemsHaveNoId173 );174175 with_weight(176 <Pallet<T>>::burn_from(&self, &sender, &from, amount),177 <CommonWeights<T>>::burn_from(),178 )179 }158180159 fn set_variable_metadata(181 fn set_variable_metadata(160 &self,182 &self,pallets/fungible/src/erc.rsdiffbeforeafterboth96 }96 }97}97}9899#[solidity_interface(name = "ERC20UniqueExtensions")]100impl<T: Config> FungibleHandle<T> {101 fn burn_from(&mut self, caller: caller, from: address, amount: uint256) -> Result<bool> {102 let caller = T::CrossAccountId::from_eth(caller);103 let from = T::CrossAccountId::from_eth(from);104 let amount = amount.try_into().map_err(|_| "amount overflow")?;105106 <Pallet<T>>::burn_from(self, &caller, &from, amount).map_err(dispatch_to_evm::<T>)?;107 Ok(true)108 }109}9811099#[solidity_interface(name = "UniqueFungible", is(ERC20))]111#[solidity_interface(name = "UniqueFungible", is(ERC20))]100impl<T: Config> FungibleHandle<T> {}112impl<T: Config> FungibleHandle<T> {}pallets/fungible/src/lib.rsdiffbeforeafterboth356 Ok(())356 Ok(())357 }357 }358359 pub fn burn_from(360 collection: &FungibleHandle<T>,361 spender: &T::CrossAccountId,362 from: &T::CrossAccountId,363 amount: u128,364 ) -> DispatchResult {365 if spender == from {366 return Self::burn(collection, from, amount);367 }368 if collection.access == AccessMode::WhiteList {369 // `from` checked in [`burn`]370 collection.check_allowlist(spender)?;371 }372373 let allowance = <Allowance<T>>::get((collection.id, from.as_sub(), spender.as_sub()))374 .checked_sub(amount);375 if allowance.is_none() {376 ensure!(377 collection.ignores_allowance(spender)?,378 <CommonError<T>>::TokenValueNotEnough379 );380 }381382 // =========383384 Self::burn(collection, from, amount)?;385 if let Some(allowance) = allowance {386 Self::set_allowance_unchecked(collection, from, spender, allowance);387 }388 Ok(())389 }358390359 /// Delegated to `create_multiple_items`391 /// Delegated to `create_multiple_items`360 pub fn create_item(392 pub fn create_item(pallets/nft/src/common.rsdiffbeforeafterboth46 dispatch_weight::<T>() + max_weight_of!(set_variable_metadata(bytes))46 dispatch_weight::<T>() + max_weight_of!(set_variable_metadata(bytes))47 }47 }4849 fn burn_from() -> Weight {50 dispatch_weight::<T>() + max_weight_of!(burn_from())51 }48}52}4953pallets/nft/src/eth/sponsoring.rsdiffbeforeafterboth35 .map_err(|_| AnyError)?35 .map_err(|_| AnyError)?36 .ok_or(AnyError)?;36 .ok_or(AnyError)?;37 match call {37 match call {38 UniqueNFTCall::ERC721UniqueExtensions(38 UniqueNFTCall::ERC721UniqueExtensions(ERC721UniqueExtensionsCall::Transfer {39 ERC721UniqueExtensionsCall::TransferNft { token_id, .. },39 token_id,40 ..40 )41 })41 | UniqueNFTCall::ERC721(ERC721Call::TransferFrom { token_id, .. }) => {42 | UniqueNFTCall::ERC721(ERC721Call::TransferFrom { token_id, .. }) => {pallets/nft/src/lib.rsdiffbeforeafterboth623 /// * item_id: ID of NFT to burn.623 /// * item_id: ID of NFT to burn.624 ///624 ///625 /// * from: owner of item625 /// * from: owner of item626 // #[weight = 0]626 #[weight = <CommonWeights<T>>::burn_from()]627 // #[transactional]627 #[transactional]628 // pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> PostDispatchInfo {628 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {629 // let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);629 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);630630631 // // dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value))631 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value))632 // todo!()632 }633 // }634633635 /// Change ownership of the token.634 /// Change ownership of the token.636 ///635 ///pallets/nonfungible/src/common.rsdiffbeforeafterboth39 <SelfWeightOf<T>>::transfer_from()39 <SelfWeightOf<T>>::transfer_from()40 }40 }4142 fn burn_from() -> Weight {43 044 }414542 fn set_variable_metadata(bytes: u32) -> Weight {46 fn set_variable_metadata(bytes: u32) -> Weight {43 <SelfWeightOf<T>>::set_variable_metadata(bytes)47 <SelfWeightOf<T>>::set_variable_metadata(bytes)163 }167 }164 }168 }169170 fn burn_from(171 &self,172 sender: T::CrossAccountId,173 from: T::CrossAccountId,174 token: TokenId,175 amount: u128,176 ) -> DispatchResultWithPostInfo {177 ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);178179 if amount == 1 {180 with_weight(181 <Pallet<T>>::burn_from(&self, &sender, &from, token),182 <CommonWeights<T>>::burn_from(),183 )184 } else {185 Ok(().into())186 }187 }165188166 fn set_variable_metadata(189 fn set_variable_metadata(167 &self,190 &self,pallets/nonfungible/src/erc.rsdiffbeforeafterboth264264265#[solidity_interface(name = "ERC721UniqueExtensions")]265#[solidity_interface(name = "ERC721UniqueExtensions")]266impl<T: Config> NonfungibleHandle<T> {266impl<T: Config> NonfungibleHandle<T> {267 #[solidity(rename_selector = "transfer")]268 fn transfer_nft(267 fn transfer(269 &mut self,268 &mut self,270 caller: caller,269 caller: caller,271 to: address,270 to: address,280 Ok(())279 Ok(())281 }280 }281282 fn burn_from(283 &mut self,284 caller: caller,285 from: address,286 token_id: uint256,287 _value: value,288 ) -> Result<void> {289 let caller = T::CrossAccountId::from_eth(caller);290 let from = T::CrossAccountId::from_eth(from);291 let token = token_id.try_into()?;292293 <Pallet<T>>::burn_from(self, &caller, &from, token).map_err(dispatch_to_evm::<T>)?;294 Ok(())295 }282296283 fn next_token_id(&self) -> Result<uint256> {297 fn next_token_id(&self) -> Result<uint256> {284 Ok(<TokensMinted<T>>::get(self.id)298 Ok(<TokensMinted<T>>::get(self.id)pallets/nonfungible/src/lib.rsdiffbeforeafterboth499 Ok(())499 Ok(())500 }500 }501502 pub fn burn_from(503 collection: &NonfungibleHandle<T>,504 spender: &T::CrossAccountId,505 from: &T::CrossAccountId,506 token: TokenId,507 ) -> DispatchResult {508 if spender == from {509 return Self::burn(collection, from, token);510 }511 if collection.access == AccessMode::WhiteList {512 // `from` checked in [`burn`]513 collection.check_allowlist(spender)?;514 }515516 if <Allowance<T>>::get((collection.id, token)).as_ref() != Some(spender) {517 ensure!(518 collection.ignores_allowance(spender)?,519 <CommonError<T>>::TokenValueNotEnough520 );521 }522523 // =========524525 Self::burn(collection, &from, token)526 }501527502 pub fn set_variable_metadata(528 pub fn set_variable_metadata(503 collection: &NonfungibleHandle<T>,529 collection: &NonfungibleHandle<T>,pallets/refungible/src/common.rsdiffbeforeafterboth59 )59 )60 }60 }6162 fn burn_from() -> Weight {63 064 }616562 fn set_variable_metadata(bytes: u32) -> Weight {66 fn set_variable_metadata(bytes: u32) -> Weight {63 <SelfWeightOf<T>>::set_variable_metadata(bytes)67 <SelfWeightOf<T>>::set_variable_metadata(bytes)161 ) -> DispatchResultWithPostInfo {165 ) -> DispatchResultWithPostInfo {162 with_weight(166 with_weight(163 <Pallet<T>>::transfer_from(&self, &sender, &from, &to, token, amount),167 <Pallet<T>>::transfer_from(&self, &sender, &from, &to, token, amount),164 <CommonWeights<T>>::approve(),168 <CommonWeights<T>>::transfer_from(),165 )169 )166 }170 }171172 fn burn_from(173 &self,174 sender: T::CrossAccountId,175 from: T::CrossAccountId,176 token: TokenId,177 amount: u128,178 ) -> DispatchResultWithPostInfo {179 with_weight(180 <Pallet<T>>::burn_from(&self, &sender, &from, token, amount),181 <CommonWeights<T>>::burn_from(),182 )183 }167184168 fn set_variable_metadata(185 fn set_variable_metadata(169 &self,186 &self,pallets/refungible/src/lib.rsdiffbeforeafterboth537 Ok(())537 Ok(())538 }538 }539540 pub fn burn_from(541 collection: &RefungibleHandle<T>,542 spender: &T::CrossAccountId,543 from: &T::CrossAccountId,544 token: TokenId,545 amount: u128,546 ) -> DispatchResult {547 if spender == from {548 return Self::burn(collection, from, token, amount);549 }550 if collection.access == AccessMode::WhiteList {551 // `from` checked in [`burn`]552 collection.check_allowlist(spender)?;553 }554555 let allowance = <Allowance<T>>::get((collection.id, token, from.as_sub(), &spender))556 .checked_sub(amount);557 if allowance.is_none() {558 ensure!(559 collection.ignores_allowance(spender)?,560 <CommonError<T>>::TokenValueNotEnough561 );562 }563564 // =========565566 Self::burn(collection, from, token, amount)?;567 if let Some(allowance) = allowance {568 Self::set_allowance_unchecked(collection, from, spender, token, allowance);569 }570 Ok(())571 }539572540 pub fn set_variable_metadata(573 pub fn set_variable_metadata(541 collection: &RefungibleHandle<T>,574 collection: &RefungibleHandle<T>,