difftreelog
feat add dispatching
in: master
6 files changed
pallets/balances-adapter/src/common.rsdiffbeforeafterbothno changes
pallets/balances-adapter/src/erc.rsdiffbeforeafterboth1use crate::Config;1use crate::{Config, NativeFungibleHandle};2use evm_coder::{abi::AbiType, AbiCoder, ToLog, generate_stubgen, solidity_interface, types::*};2use evm_coder::{abi::AbiType, ToLog, generate_stubgen, solidity_interface, types::*};3use frame_support::traits::{Currency, ExistenceRequirement};3use frame_support::traits::{Currency, ExistenceRequirement};4use pallet_common::{4use pallet_common::{5 erc::{CommonEvmHandler, CrossAccountId, PrecompileHandle, PrecompileResult},5 erc::{CommonEvmHandler, CrossAccountId, PrecompileHandle, PrecompileResult},36 },36 },37}37}3839pub struct NativeFungibleHandle<T: Config>(SubstrateRecorder<T>);4041impl<T: Config> WithRecorder<T> for NativeFungibleHandle<T> {42 fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {43 &self.044 }45 fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {46 self.047 }48}493850#[solidity_interface(name = ERC20, events(ERC20Events), enum(derive(PreDispatch)), enum_attr(weight), expect_selector = 0x942e8b22)]39#[solidity_interface(name = ERC20, events(ERC20Events), enum(derive(PreDispatch)), enum_attr(weight), expect_selector = 0x942e8b22)]51impl<T: Config> NativeFungibleHandle<T> {40impl<T: Config> NativeFungibleHandle<T> {pallets/balances-adapter/src/lib.rsdiffbeforeafterboth445extern crate alloc;5extern crate alloc;6pub use pallet::*;6pub use pallet::*;77use pallet_common::CollectionHandle;8use pallet_evm_coder_substrate::{WithRecorder, SubstrateRecorder};910pub mod common;8pub mod erc;11pub mod erc;91213pub struct NativeFungibleHandle<T: Config>(CollectionHandle<T>);14impl<T: Config> NativeFungibleHandle<T> {15 pub fn cast(inner: CollectionHandle<T>) -> Self {16 Self(inner)17 }1819 /// Casts [`NativeFungibleHandle`] into [`CollectionHandle`][`pallet_common::CollectionHandle`].20 pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {21 self.022 }23}2425impl<T: Config> WithRecorder<T> for NativeFungibleHandle<T> {26 fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {27 &self.0.recorder28 }29 fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {30 self.0.recorder31 }32}10#[frame_support::pallet]33#[frame_support::pallet]11pub mod pallet {34pub mod pallet {12 use alloc::string::String;35 use alloc::string::String;13 use frame_support::traits::Get;36 use frame_support::{traits::Get, sp_runtime::DispatchResult};14 use sp_core::U256;37 use sp_core::U256;153816 #[pallet::config]39 #[pallet::config]17 pub trait Config: frame_system::Config + pallet_evm_coder_substrate::Config {40 pub trait Config:41 frame_system::Config + pallet_evm_coder_substrate::Config + pallet_common::Config42 {18 type Currency: frame_support::traits::Currency<43 type Currency: frame_support::traits::Currency<19 Self::AccountId,44 Self::AccountId,28 #[pallet::pallet]53 #[pallet::pallet]29 pub struct Pallet<T>(_);54 pub struct Pallet<T>(_);305531 #[pallet::call]56 // #[pallet::call]32 impl<T: Config> Pallet<T> {}57 impl<T: Config> Pallet<T> {58 pub fn dummy() -> DispatchResult {59 Ok(())60 }61 }33}62}3463runtime/common/dispatch.rsdiffbeforeafterboth25};25};26pub use pallet_common::dispatch::CollectionDispatch;26pub use pallet_common::dispatch::CollectionDispatch;27use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};27use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};28use pallet_balances_adapter::{Pallet as PalletNativeFungible, NativeFungibleHandle};28use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};29use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};29use pallet_refungible::{30use pallet_refungible::{30 Pallet as PalletRefungible, RefungibleHandle, erc_token::RefungibleTokenHandle,31 Pallet as PalletRefungible, RefungibleHandle, erc_token::RefungibleTokenHandle,42 T: pallet_fungible::Config + pallet_nonfungible::Config + pallet_refungible::Config,43 T: pallet_fungible::Config44 + pallet_nonfungible::Config45 + pallet_refungible::Config46 + pallet_balances_adapter::Config,43{47{44 Fungible(FungibleHandle<T>),48 Fungible(FungibleHandle<T>),45 Nonfungible(NonfungibleHandle<T>),49 Nonfungible(NonfungibleHandle<T>),46 Refungible(RefungibleHandle<T>),50 Refungible(RefungibleHandle<T>),51 NativeFungible(NativeFungibleHandle<T>),47}52}48impl<T> CollectionDispatch<T> for CollectionDispatchT<T>53impl<T> CollectionDispatch<T> for CollectionDispatchT<T>49where54where50 T: pallet_common::Config55 T: pallet_common::Config51 + pallet_unique::Config56 + pallet_unique::Config52 + pallet_fungible::Config57 + pallet_fungible::Config53 + pallet_nonfungible::Config58 + pallet_nonfungible::Config54 + pallet_refungible::Config,59 + pallet_refungible::Config60 + pallet_balances_adapter::Config,55{61{56 fn create(62 fn create(57 sender: T::CrossAccountId,63 sender: T::CrossAccountId,100106101 fn dispatch(handle: CollectionHandle<T>) -> Self {107 fn dispatch(handle: CollectionHandle<T>) -> Self {102 match handle.mode {108 match handle.mode {103 CollectionMode::Fungible(_) => Self::Fungible(FungibleHandle::cast(handle)),109 CollectionMode::Fungible(_) => {110 if handle.id != up_data_structs::CollectionId(0) {111 Self::Fungible(FungibleHandle::cast(handle))112 } else {113 Self::NativeFungible(NativeFungibleHandle::cast(handle))114 }115 }104 CollectionMode::NFT => Self::Nonfungible(NonfungibleHandle::cast(handle)),116 CollectionMode::NFT => Self::Nonfungible(NonfungibleHandle::cast(handle)),105 CollectionMode::ReFungible => Self::Refungible(RefungibleHandle::cast(handle)),117 CollectionMode::ReFungible => Self::Refungible(RefungibleHandle::cast(handle)),106 }118 }111 Self::Fungible(f) => f.into_inner(),123 Self::Fungible(f) => f.into_inner(),112 Self::Nonfungible(f) => f.into_inner(),124 Self::Nonfungible(f) => f.into_inner(),113 Self::Refungible(f) => f.into_inner(),125 Self::Refungible(f) => f.into_inner(),126 Self::NativeFungible(f) => f.into_inner(),114 }127 }115 }128 }116129119 Self::Fungible(h) => h,132 Self::Fungible(h) => h,120 Self::Nonfungible(h) => h,133 Self::Nonfungible(h) => h,121 Self::Refungible(h) => h,134 Self::Refungible(h) => h,135 Self::NativeFungible(h) => h,122 }136 }123 }137 }124}138}130 + pallet_fungible::Config144 + pallet_fungible::Config131 + pallet_nonfungible::Config145 + pallet_nonfungible::Config132 + pallet_refungible::Config,146 + pallet_refungible::Config147 + pallet_balances_adapter::Config,133 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,148 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,134{149{135 fn is_reserved(target: &H160) -> bool {150 fn is_reserved(target: &H160) -> bool {174 Self::Fungible(h) => h.call(handle),189 Self::Fungible(h) => h.call(handle),175 Self::Nonfungible(h) => h.call(handle),190 Self::Nonfungible(h) => h.call(handle),176 Self::Refungible(h) => h.call(handle),191 Self::Refungible(h) => h.call(handle),192 Self::NativeFungible(f) => todo!(),177 }193 }178 } else if let Some((collection_id, token_id)) =194 } else if let Some((collection_id, token_id)) =179 <T as pallet_common::Config>::EvmTokenAddressMapping::address_to_token(195 <T as pallet_common::Config>::EvmTokenAddressMapping::address_to_token(tests/src/eth/nativeFungible.test.tsdiffbeforeafterbothno changes
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth141 }141 }142142143 async collection(address: string, mode: TCollectionMode, caller?: string, mergeDeprecated = false) {143 async collection(address: string, mode: TCollectionMode, caller?: string, mergeDeprecated = false) {144 let abi = {144 let abi;145 if (address === '0' && mode === 'ft') {146 abi = nativeFungibleAbi;147 } else {148 abi ={145 'nft': nonFungibleAbi,149 'nft': nonFungibleAbi,146 'rft': refungibleAbi,150 'rft': refungibleAbi,147 'ft': fungibleAbi,151 'ft': fungibleAbi,148 }[mode];152 }[mode];153 }149 if (mergeDeprecated) {154 if (mergeDeprecated) {150 const deprecated = {155 const deprecated = {151 'nft': nonFungibleDeprecatedAbi,156 'nft': nonFungibleDeprecatedAbi,