difftreelog
cargo fmt
in: master
10 files changed
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -168,7 +168,9 @@
use scale_info::TypeInfo;
#[pallet::config]
- pub trait Config: frame_system::Config + pallet_evm_coder_substrate::Config + TypeInfo + account::Config {
+ pub trait Config:
+ frame_system::Config + pallet_evm_coder_substrate::Config + TypeInfo + account::Config
+ {
type Event: IsType<<Self as frame_system::Config>::Event> + From<Event<Self>>;
type Currency: Currency<Self::AccountId>;
pallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -18,7 +18,8 @@
use evm_coder::{abi::AbiWriter, execution::Result, generate_stubgen, solidity_interface, types::*};
use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
use pallet_evm::{
- ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure, account::CrossAccountId
+ ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure,
+ account::CrossAccountId,
};
use sp_core::H160;
use crate::{
@@ -179,7 +180,9 @@
}
pub struct HelpersContractSponsoring<T: Config>(PhantomData<*const T>);
-impl<T: Config> SponsorshipHandler<T::CrossAccountId, (H160, Vec<u8>)> for HelpersContractSponsoring<T> {
+impl<T: Config> SponsorshipHandler<T::CrossAccountId, (H160, Vec<u8>)>
+ for HelpersContractSponsoring<T>
+{
fn get_sponsor(who: &T::CrossAccountId, call: &(H160, Vec<u8>)) -> Option<T::CrossAccountId> {
let mode = <Pallet<T>>::sponsoring_mode(call.0);
if mode == SponsoringModeT::Disabled {
pallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/lib.rs
+++ b/pallets/evm-contract-helpers/src/lib.rs
@@ -30,7 +30,9 @@
use sp_core::H160;
#[pallet::config]
- pub trait Config: frame_system::Config + pallet_evm_coder_substrate::Config + pallet_evm::account::Config {
+ pub trait Config:
+ frame_system::Config + pallet_evm_coder_substrate::Config + pallet_evm::account::Config
+ {
type ContractAddress: Get<H160>;
type DefaultSponsoringRateLimit: Get<Self::BlockNumber>;
}
pallets/evm-transaction-payment/src/lib.rsdiffbeforeafterboth--- a/pallets/evm-transaction-payment/src/lib.rs
+++ b/pallets/evm-transaction-payment/src/lib.rs
@@ -87,7 +87,8 @@
fee: U256,
) -> core::result::Result<Self::LiquidityInfo, pallet_evm::Error<T>> {
let who_pays_fee = if let WithdrawReason::Call { target, input } = &reason {
- T::EvmSponsorshipHandler::get_sponsor(who, &(*target, input.clone())).unwrap_or(who.clone())
+ T::EvmSponsorshipHandler::get_sponsor(who, &(*target, input.clone()))
+ .unwrap_or(who.clone())
} else {
who.clone()
};
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -19,9 +19,7 @@
use core::ops::Deref;
use frame_support::{ensure};
use up_data_structs::{AccessMode, CollectionId, TokenId, CreateCollectionData};
-use pallet_common::{
- Error as CommonError, Event as CommonEvent, Pallet as PalletCommon,
-};
+use pallet_common::{Error as CommonError, Event as CommonEvent, Pallet as PalletCommon};
use pallet_evm::account::CrossAccountId;
use pallet_evm_coder_substrate::WithRecorder;
use sp_core::H160;
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -21,9 +21,7 @@
use up_data_structs::{
AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,
};
-use pallet_common::{
- Error as CommonError, Pallet as PalletCommon, Event as CommonEvent,
-};
+use pallet_common::{Error as CommonError, Pallet as PalletCommon, Event as CommonEvent};
use pallet_evm::account::CrossAccountId;
use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
use sp_core::H160;
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -21,9 +21,7 @@
AccessMode, CollectionId, CustomDataLimit, MAX_REFUNGIBLE_PIECES, TokenId,
CreateCollectionData, CreateRefungibleExData,
};
-use pallet_common::{
- Error as CommonError, Event as CommonEvent, Pallet as PalletCommon,
-};
+use pallet_common::{Error as CommonError, Event as CommonEvent, Pallet as PalletCommon};
use pallet_evm::account::CrossAccountId;
use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};
use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};
pallets/unique/src/eth/sponsoring.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//! Implements EVM sponsoring logic via OnChargeEVMTransaction1819use crate::{Config, sponsorship::*};20use evm_coder::{Call, abi::AbiReader};21use pallet_common::{CollectionHandle, eth::map_eth_to_id};22use sp_core::H160;23use sp_std::prelude::*;24use up_sponsorship::SponsorshipHandler;25use core::marker::PhantomData;26use core::convert::TryInto;27use up_data_structs::TokenId;28use pallet_evm::account::CrossAccountId;2930use pallet_nonfungible::erc::{UniqueNFTCall, ERC721UniqueExtensionsCall, ERC721Call};31use pallet_fungible::erc::{UniqueFungibleCall, ERC20Call};32use up_data_structs::{CreateItemData, CreateNftData};3334pub struct UniqueEthSponsorshipHandler<T: Config>(PhantomData<*const T>);35impl<T: Config> SponsorshipHandler<T::CrossAccountId, (H160, Vec<u8>)> for UniqueEthSponsorshipHandler<T> {36 fn get_sponsor(who: &T::CrossAccountId, call: &(H160, Vec<u8>)) -> Option<T::CrossAccountId> {37 let collection_id = map_eth_to_id(&call.0)?;38 let collection = <CollectionHandle<T>>::new(collection_id)?;39 let sponsor = collection.sponsorship.sponsor()?.clone();40 let (method_id, mut reader) = AbiReader::new_call(&call.1).ok()?;41 Some(T::CrossAccountId::from_sub(match &collection.mode {42 crate::CollectionMode::NFT => {43 let call = <UniqueNFTCall<T>>::parse(method_id, &mut reader).ok()??;44 match call {45 UniqueNFTCall::ERC721UniqueExtensions(46 ERC721UniqueExtensionsCall::Transfer { token_id, .. },47 ) => {48 let token_id: TokenId = token_id.try_into().ok()?;49 withdraw_transfer::<T>(&collection, &who, &token_id).map(|()| sponsor)50 }51 UniqueNFTCall::ERC721(ERC721Call::TransferFrom { token_id, from, .. }) => {52 let token_id: TokenId = token_id.try_into().ok()?;53 let from = T::CrossAccountId::from_eth(from);54 withdraw_transfer::<T>(&collection, &from, &token_id).map(|()| sponsor)55 }56 UniqueNFTCall::ERC721(ERC721Call::Approve { token_id, .. }) => {57 let token_id: TokenId = token_id.try_into().ok()?;58 withdraw_approve::<T>(&collection, who.as_sub(), &token_id)59 .map(|()| sponsor)60 }61 UniqueNFTCall::ERC721Mintable(call) => match call {62 pallet_nonfungible::erc::ERC721MintableCall::Mint { .. } |63 pallet_nonfungible::erc::ERC721MintableCall::MintWithTokenUri { .. } => {64 withdraw_create_item(65 &collection, 66 who.as_sub(), 67 &CreateItemData::NFT(CreateNftData::default()))68 .map(|()| sponsor)69 }70 _ => None,71 }72 _ => None,73 }74 }75 crate::CollectionMode::Fungible(_) => {76 let call = <UniqueFungibleCall<T>>::parse(method_id, &mut reader).ok()??;77 #[allow(clippy::single_match)]78 match call {79 UniqueFungibleCall::ERC20(ERC20Call::Transfer { .. }) => {80 withdraw_transfer::<T>(&collection, who, &TokenId::default())81 .map(|()| sponsor)82 }83 UniqueFungibleCall::ERC20(ERC20Call::TransferFrom { from, .. }) => {84 let from = T::CrossAccountId::from_eth(from);85 withdraw_transfer::<T>(&collection, &from, &TokenId::default())86 .map(|()| sponsor)87 }88 UniqueFungibleCall::ERC20(ERC20Call::Approve { .. }) => {89 withdraw_approve::<T>(&collection, who.as_sub(), &TokenId::default())90 .map(|()| sponsor)91 }92 _ => None,93 }94 }95 _ => None,96 }?))97 }98}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//! Implements EVM sponsoring logic via OnChargeEVMTransaction1819use crate::{Config, sponsorship::*};20use evm_coder::{Call, abi::AbiReader};21use pallet_common::{CollectionHandle, eth::map_eth_to_id};22use sp_core::H160;23use sp_std::prelude::*;24use up_sponsorship::SponsorshipHandler;25use core::marker::PhantomData;26use core::convert::TryInto;27use up_data_structs::TokenId;28use pallet_evm::account::CrossAccountId;2930use pallet_nonfungible::erc::{UniqueNFTCall, ERC721UniqueExtensionsCall, ERC721Call};31use pallet_fungible::erc::{UniqueFungibleCall, ERC20Call};32use up_data_structs::{CreateItemData, CreateNftData};3334pub struct UniqueEthSponsorshipHandler<T: Config>(PhantomData<*const T>);35impl<T: Config> SponsorshipHandler<T::CrossAccountId, (H160, Vec<u8>)>36 for UniqueEthSponsorshipHandler<T>37{38 fn get_sponsor(who: &T::CrossAccountId, call: &(H160, Vec<u8>)) -> Option<T::CrossAccountId> {39 let collection_id = map_eth_to_id(&call.0)?;40 let collection = <CollectionHandle<T>>::new(collection_id)?;41 let sponsor = collection.sponsorship.sponsor()?.clone();42 let (method_id, mut reader) = AbiReader::new_call(&call.1).ok()?;43 Some(T::CrossAccountId::from_sub(match &collection.mode {44 crate::CollectionMode::NFT => {45 let call = <UniqueNFTCall<T>>::parse(method_id, &mut reader).ok()??;46 match call {47 UniqueNFTCall::ERC721UniqueExtensions(48 ERC721UniqueExtensionsCall::Transfer { token_id, .. },49 ) => {50 let token_id: TokenId = token_id.try_into().ok()?;51 withdraw_transfer::<T>(&collection, &who, &token_id).map(|()| sponsor)52 }53 UniqueNFTCall::ERC721(ERC721Call::TransferFrom { token_id, from, .. }) => {54 let token_id: TokenId = token_id.try_into().ok()?;55 let from = T::CrossAccountId::from_eth(from);56 withdraw_transfer::<T>(&collection, &from, &token_id).map(|()| sponsor)57 }58 UniqueNFTCall::ERC721(ERC721Call::Approve { token_id, .. }) => {59 let token_id: TokenId = token_id.try_into().ok()?;60 withdraw_approve::<T>(&collection, who.as_sub(), &token_id)61 .map(|()| sponsor)62 }63 UniqueNFTCall::ERC721Mintable(call) => match call {64 pallet_nonfungible::erc::ERC721MintableCall::Mint { .. }65 | pallet_nonfungible::erc::ERC721MintableCall::MintWithTokenUri {66 ..67 } => withdraw_create_item(68 &collection,69 who.as_sub(),70 &CreateItemData::NFT(CreateNftData::default()),71 )72 .map(|()| sponsor),73 _ => None,74 },75 _ => None,76 }77 }78 crate::CollectionMode::Fungible(_) => {79 let call = <UniqueFungibleCall<T>>::parse(method_id, &mut reader).ok()??;80 #[allow(clippy::single_match)]81 match call {82 UniqueFungibleCall::ERC20(ERC20Call::Transfer { .. }) => {83 withdraw_transfer::<T>(&collection, who, &TokenId::default())84 .map(|()| sponsor)85 }86 UniqueFungibleCall::ERC20(ERC20Call::TransferFrom { from, .. }) => {87 let from = T::CrossAccountId::from_eth(from);88 withdraw_transfer::<T>(&collection, &from, &TokenId::default())89 .map(|()| sponsor)90 }91 UniqueFungibleCall::ERC20(ERC20Call::Approve { .. }) => {92 withdraw_approve::<T>(&collection, who.as_sub(), &TokenId::default())93 .map(|()| sponsor)94 }95 _ => None,96 }97 }98 _ => None,99 }?))100 }101}pallets/unique/src/lib.rsdiffbeforeafterboth--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -53,10 +53,7 @@
CollectionMode, TokenId, SchemaVersion, SponsorshipState, MetaUpdatePermission,
CreateCollectionData, CustomDataLimit, CreateItemExData,
};
-use pallet_common::{
- CollectionHandle, Pallet as PalletCommon, Error as CommonError,
- CommonWeightInfo,
-};
+use pallet_common::{CollectionHandle, Pallet as PalletCommon, Error as CommonError, CommonWeightInfo};
use pallet_evm::account::CrossAccountId;
use pallet_refungible::{Pallet as PalletRefungible, RefungibleHandle};
use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};
pallets/unique/src/tests.rsdiffbeforeafterboth--- a/pallets/unique/src/tests.rs
+++ b/pallets/unique/src/tests.rs
@@ -2865,18 +2865,49 @@
let origin1 = Origin::signed(user1);
let origin2 = Origin::signed(user2);
let account2 = account(user2);
-
- let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, user1, CollectionId(1));
- assert_ok!(TemplateModule::set_collection_sponsor(origin1.clone(), collection_id, user1));
- assert_ok!(TemplateModule::confirm_sponsorship(origin1.clone(), collection_id));
+ let collection_id =
+ create_test_collection_for_owner(&CollectionMode::NFT, user1, CollectionId(1));
+ assert_ok!(TemplateModule::set_collection_sponsor(
+ origin1.clone(),
+ collection_id,
+ user1
+ ));
+ assert_ok!(TemplateModule::confirm_sponsorship(
+ origin1.clone(),
+ collection_id
+ ));
+
// Expect error while have no permissions
- assert!(TemplateModule::create_item(origin2.clone(), collection_id, account2.clone(), default_nft_data().into()).is_err());
+ assert!(TemplateModule::create_item(
+ origin2.clone(),
+ collection_id,
+ account2.clone(),
+ default_nft_data().into()
+ )
+ .is_err());
- assert_ok!(TemplateModule::set_public_access_mode(origin1.clone(), collection_id, AccessMode::AllowList));
- assert_ok!(TemplateModule::add_to_allow_list(origin1.clone(), collection_id, account2.clone()));
- assert_ok!(TemplateModule::set_mint_permission(origin1.clone(), collection_id, true));
-
- assert_ok!(TemplateModule::create_item(origin2, collection_id, account2, default_nft_data().into()));
+ assert_ok!(TemplateModule::set_public_access_mode(
+ origin1.clone(),
+ collection_id,
+ AccessMode::AllowList
+ ));
+ assert_ok!(TemplateModule::add_to_allow_list(
+ origin1.clone(),
+ collection_id,
+ account2.clone()
+ ));
+ assert_ok!(TemplateModule::set_mint_permission(
+ origin1.clone(),
+ collection_id,
+ true
+ ));
+
+ assert_ok!(TemplateModule::create_item(
+ origin2,
+ collection_id,
+ account2,
+ default_nft_data().into()
+ ));
});
-}
\ No newline at end of file
+}