From 2880b7f76c032798bcf34e0b1b79ca02a267e201 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Mon, 05 Dec 2022 13:18:30 +0000 Subject: [PATCH] fix zero transfer --- --- a/Cargo.lock +++ b/Cargo.lock @@ -5901,7 +5901,7 @@ [[package]] name = "pallet-common" -version = "0.1.12" +version = "0.1.13" dependencies = [ "ethereum", "evm-coder", @@ -6191,7 +6191,7 @@ [[package]] name = "pallet-fungible" -version = "0.1.7" +version = "0.1.8" dependencies = [ "ethereum", "evm-coder", @@ -6446,7 +6446,7 @@ [[package]] name = "pallet-nonfungible" -version = "0.1.9" +version = "0.1.10" dependencies = [ "ethereum", "evm-coder", @@ -6568,7 +6568,7 @@ [[package]] name = "pallet-refungible" -version = "0.2.8" +version = "0.2.9" dependencies = [ "derivative", "ethereum", --- a/pallets/common/CHANGELOG.md +++ b/pallets/common/CHANGELOG.md @@ -4,6 +4,12 @@ +## [0.1.13] - 2022-12-05 + +### Added + +- The error `ZeroTransferNotAllowed` to handling transactions with the transfer of a zero amount of tokens. + ## [0.1.12] - 2022-11-16 ### Changed --- a/pallets/common/Cargo.toml +++ b/pallets/common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-common" -version = "0.1.12" +version = "0.1.13" license = "GPLv3" edition = "2021" --- a/pallets/common/src/lib.rs +++ b/pallets/common/src/lib.rs @@ -601,6 +601,9 @@ /// Tried to access an internal collection with an external API CollectionIsInternal, + + /// Transfer operation with zero amount + ZeroTransferNotAllowed, } /// Storage of the count of created collections. Essentially contains the last collection ID. --- a/pallets/fungible/CHANGELOG.md +++ b/pallets/fungible/CHANGELOG.md @@ -4,6 +4,12 @@ +## [0.1.9] - 2022-12-05 + +### Fixed + +- Transfer with zero tokens. + ## [0.1.8] - 2022-11-18 ### Added --- a/pallets/fungible/Cargo.toml +++ b/pallets/fungible/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-fungible" -version = "0.1.7" +version = "0.1.8" license = "GPLv3" edition = "2021" --- a/pallets/fungible/src/lib.rs +++ b/pallets/fungible/src/lib.rs @@ -365,6 +365,8 @@ amount: u128, nesting_budget: &dyn Budget, ) -> DispatchResult { + ensure!(amount > 0, >::ZeroTransferNotAllowed); + ensure!( collection.limits.transfers_enabled(), >::TransferNotAllowed, --- a/pallets/nonfungible/CHANGELOG.md +++ b/pallets/nonfungible/CHANGELOG.md @@ -4,6 +4,12 @@ +## [0.1.11] - 2022-12-05 + +### Fixed + +- Transfer with zero tokens. + ## [0.1.10] - 2022-11-18 ### Added --- a/pallets/nonfungible/Cargo.toml +++ b/pallets/nonfungible/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-nonfungible" -version = "0.1.9" +version = "0.1.10" license = "GPLv3" edition = "2021" --- a/pallets/nonfungible/src/common.rs +++ b/pallets/nonfungible/src/common.rs @@ -23,7 +23,7 @@ }; use pallet_common::{ CommonCollectionOperations, CommonWeightInfo, RefungibleExtensions, with_weight, - weights::WeightInfo as _, + weights::WeightInfo as _, Error as CommonError, }; use sp_runtime::DispatchError; use sp_std::{vec::Vec, vec}; @@ -314,14 +314,12 @@ nesting_budget: &dyn Budget, ) -> DispatchResultWithPostInfo { ensure!(amount <= 1, >::NonfungibleItemsHaveNoAmount); - if amount == 1 { - with_weight( - >::transfer(self, &from, &to, token, nesting_budget), - >::transfer(), - ) - } else { - Ok(().into()) - } + ensure!(amount > 0, >::ZeroTransferNotAllowed); + + with_weight( + >::transfer(self, &from, &to, token, nesting_budget), + >::transfer(), + ) } fn approve( @@ -353,15 +351,12 @@ nesting_budget: &dyn Budget, ) -> DispatchResultWithPostInfo { ensure!(amount <= 1, >::NonfungibleItemsHaveNoAmount); + ensure!(amount > 0, >::ZeroTransferNotAllowed); - if amount == 1 { - with_weight( - >::transfer_from(self, &sender, &from, &to, token, nesting_budget), - >::transfer_from(), - ) - } else { - Ok(().into()) - } + with_weight( + >::transfer_from(self, &sender, &from, &to, token, nesting_budget), + >::transfer_from(), + ) } fn burn_from( --- a/pallets/refungible/CHANGELOG.md +++ b/pallets/refungible/CHANGELOG.md @@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file. +## [0.2.10] - 2022-12-05 + +### Fixed + +- Transfer with zero pieces. ## [0.2.9] - 2022-11-18 --- a/pallets/refungible/Cargo.toml +++ b/pallets/refungible/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-refungible" -version = "0.2.8" +version = "0.2.9" license = "GPLv3" edition = "2021" --- a/pallets/refungible/src/lib.rs +++ b/pallets/refungible/src/lib.rs @@ -727,6 +727,8 @@ amount: u128, nesting_budget: &dyn Budget, ) -> DispatchResult { + ensure!(amount > 0, >::ZeroTransferNotAllowed); + ensure!( collection.limits.transfers_enabled(), >::TransferNotAllowed -- gitstuff