difftreelog
feat add dispatching
in: master
6 files changed
pallets/balances-adapter/src/common.rsdiffbeforeafterboth1use alloc::vec::Vec;2use core::marker::PhantomData;3use crate::{Config, NativeFungibleHandle};4use pallet_common::{CommonCollectionOperations, CommonWeightInfo};56pub struct CommonWeights<T: Config>(PhantomData<T>);7impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {8 fn create_multiple_items(9 amount: &[up_data_structs::CreateItemData],10 ) -> frame_support::weights::Weight {11 todo!()12 }1314 fn create_multiple_items_ex(15 cost: &up_data_structs::CreateItemExData<T::CrossAccountId>,16 ) -> frame_support::weights::Weight {17 todo!()18 }1920 fn burn_item() -> frame_support::weights::Weight {21 todo!()22 }2324 fn set_collection_properties(amount: u32) -> frame_support::weights::Weight {25 todo!()26 }2728 fn delete_collection_properties(amount: u32) -> frame_support::weights::Weight {29 todo!()30 }3132 fn set_token_properties(amount: u32) -> frame_support::weights::Weight {33 todo!()34 }3536 fn delete_token_properties(amount: u32) -> frame_support::weights::Weight {37 todo!()38 }3940 fn set_token_property_permissions(amount: u32) -> frame_support::weights::Weight {41 todo!()42 }4344 fn transfer() -> frame_support::weights::Weight {45 todo!()46 }4748 fn approve() -> frame_support::weights::Weight {49 todo!()50 }5152 fn approve_from() -> frame_support::weights::Weight {53 todo!()54 }5556 fn transfer_from() -> frame_support::weights::Weight {57 todo!()58 }5960 fn burn_from() -> frame_support::weights::Weight {61 todo!()62 }6364 fn burn_recursively_self_raw() -> frame_support::weights::Weight {65 todo!()66 }6768 fn burn_recursively_breadth_raw(amount: u32) -> frame_support::weights::Weight {69 todo!()70 }7172 fn token_owner() -> frame_support::weights::Weight {73 todo!()74 }7576 fn set_allowance_for_all() -> frame_support::weights::Weight {77 todo!()78 }7980 fn force_repair_item() -> frame_support::weights::Weight {81 todo!()82 }83}8485/// Implementation of `CommonCollectionOperations` for `FungibleHandle`. It wraps FungibleHandle Pallete86/// methods and adds weight info.87impl<T: Config> CommonCollectionOperations<T> for NativeFungibleHandle<T> {88 fn create_item(89 &self,90 sender: <T>::CrossAccountId,91 to: <T>::CrossAccountId,92 data: up_data_structs::CreateItemData,93 nesting_budget: &dyn up_data_structs::budget::Budget,94 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {95 todo!()96 }9798 fn create_multiple_items(99 &self,100 sender: <T>::CrossAccountId,101 to: <T>::CrossAccountId,102 data: Vec<up_data_structs::CreateItemData>,103 nesting_budget: &dyn up_data_structs::budget::Budget,104 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {105 todo!()106 }107108 fn create_multiple_items_ex(109 &self,110 sender: <T>::CrossAccountId,111 data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,112 nesting_budget: &dyn up_data_structs::budget::Budget,113 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {114 todo!()115 }116117 fn burn_item(118 &self,119 sender: <T>::CrossAccountId,120 token: up_data_structs::TokenId,121 amount: u128,122 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {123 todo!()124 }125126 fn burn_item_recursively(127 &self,128 sender: <T>::CrossAccountId,129 token: up_data_structs::TokenId,130 self_budget: &dyn up_data_structs::budget::Budget,131 breadth_budget: &dyn up_data_structs::budget::Budget,132 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {133 todo!()134 }135136 fn set_collection_properties(137 &self,138 sender: <T>::CrossAccountId,139 properties: Vec<up_data_structs::Property>,140 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {141 todo!()142 }143144 fn delete_collection_properties(145 &self,146 sender: &<T>::CrossAccountId,147 property_keys: Vec<up_data_structs::PropertyKey>,148 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {149 todo!()150 }151152 fn set_token_properties(153 &self,154 sender: <T>::CrossAccountId,155 token_id: up_data_structs::TokenId,156 properties: Vec<up_data_structs::Property>,157 budget: &dyn up_data_structs::budget::Budget,158 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {159 todo!()160 }161162 fn delete_token_properties(163 &self,164 sender: <T>::CrossAccountId,165 token_id: up_data_structs::TokenId,166 property_keys: Vec<up_data_structs::PropertyKey>,167 budget: &dyn up_data_structs::budget::Budget,168 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {169 todo!()170 }171172 fn set_token_property_permissions(173 &self,174 sender: &<T>::CrossAccountId,175 property_permissions: Vec<up_data_structs::PropertyKeyPermission>,176 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {177 todo!()178 }179180 fn transfer(181 &self,182 sender: <T>::CrossAccountId,183 to: <T>::CrossAccountId,184 token: up_data_structs::TokenId,185 amount: u128,186 budget: &dyn up_data_structs::budget::Budget,187 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {188 todo!()189 }190191 fn approve(192 &self,193 sender: <T>::CrossAccountId,194 spender: <T>::CrossAccountId,195 token: up_data_structs::TokenId,196 amount: u128,197 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {198 todo!()199 }200201 fn approve_from(202 &self,203 sender: <T>::CrossAccountId,204 from: <T>::CrossAccountId,205 to: <T>::CrossAccountId,206 token: up_data_structs::TokenId,207 amount: u128,208 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {209 todo!()210 }211212 fn transfer_from(213 &self,214 sender: <T>::CrossAccountId,215 from: <T>::CrossAccountId,216 to: <T>::CrossAccountId,217 token: up_data_structs::TokenId,218 amount: u128,219 budget: &dyn up_data_structs::budget::Budget,220 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {221 todo!()222 }223224 fn burn_from(225 &self,226 sender: <T>::CrossAccountId,227 from: <T>::CrossAccountId,228 token: up_data_structs::TokenId,229 amount: u128,230 budget: &dyn up_data_structs::budget::Budget,231 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {232 todo!()233 }234235 fn check_nesting(236 &self,237 sender: <T>::CrossAccountId,238 from: (up_data_structs::CollectionId, up_data_structs::TokenId),239 under: up_data_structs::TokenId,240 budget: &dyn up_data_structs::budget::Budget,241 ) -> frame_support::sp_runtime::DispatchResult {242 todo!()243 }244245 fn nest(246 &self,247 under: up_data_structs::TokenId,248 to_nest: (up_data_structs::CollectionId, up_data_structs::TokenId),249 ) {250 todo!()251 }252253 fn unnest(254 &self,255 under: up_data_structs::TokenId,256 to_nest: (up_data_structs::CollectionId, up_data_structs::TokenId),257 ) {258 todo!()259 }260261 fn account_tokens(&self, account: <T>::CrossAccountId) -> Vec<up_data_structs::TokenId> {262 todo!()263 }264265 fn collection_tokens(&self) -> Vec<up_data_structs::TokenId> {266 todo!()267 }268269 fn token_exists(&self, token: up_data_structs::TokenId) -> bool {270 todo!()271 }272273 fn last_token_id(&self) -> up_data_structs::TokenId {274 todo!()275 }276277 fn token_owner(278 &self,279 token: up_data_structs::TokenId,280 ) -> Result<<T>::CrossAccountId, up_data_structs::TokenOwnerError> {281 todo!()282 }283284 fn token_owners(&self, token: up_data_structs::TokenId) -> Vec<<T>::CrossAccountId> {285 todo!()286 }287288 fn token_property(289 &self,290 token_id: up_data_structs::TokenId,291 key: &up_data_structs::PropertyKey,292 ) -> Option<up_data_structs::PropertyValue> {293 todo!()294 }295296 fn token_properties(297 &self,298 token: up_data_structs::TokenId,299 keys: Option<Vec<up_data_structs::PropertyKey>>,300 ) -> Vec<up_data_structs::Property> {301 todo!()302 }303304 fn total_supply(&self) -> u32 {305 todo!()306 }307308 fn account_balance(&self, account: <T>::CrossAccountId) -> u32 {309 todo!()310 }311312 fn balance(&self, account: <T>::CrossAccountId, token: up_data_structs::TokenId) -> u128 {313 todo!()314 }315316 fn total_pieces(&self, token: up_data_structs::TokenId) -> Option<u128> {317 todo!()318 }319320 fn allowance(321 &self,322 sender: <T>::CrossAccountId,323 spender: <T>::CrossAccountId,324 token: up_data_structs::TokenId,325 ) -> u128 {326 todo!()327 }328329 fn refungible_extensions(&self) -> Option<&dyn pallet_common::RefungibleExtensions<T>> {330 todo!()331 }332333 fn set_allowance_for_all(334 &self,335 owner: <T>::CrossAccountId,336 operator: <T>::CrossAccountId,337 approve: bool,338 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {339 todo!()340 }341342 fn allowance_for_all(&self, owner: <T>::CrossAccountId, operator: <T>::CrossAccountId) -> bool {343 todo!()344 }345346 fn repair_item(347 &self,348 token: up_data_structs::TokenId,349 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {350 todo!()351 }352}pallets/balances-adapter/src/erc.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/erc.rs
+++ b/pallets/balances-adapter/src/erc.rs
@@ -1,5 +1,5 @@
-use crate::Config;
-use evm_coder::{abi::AbiType, AbiCoder, ToLog, generate_stubgen, solidity_interface, types::*};
+use crate::{Config, NativeFungibleHandle};
+use evm_coder::{abi::AbiType, ToLog, generate_stubgen, solidity_interface, types::*};
use frame_support::traits::{Currency, ExistenceRequirement};
use pallet_common::{
erc::{CommonEvmHandler, CrossAccountId, PrecompileHandle, PrecompileResult},
@@ -34,17 +34,6 @@
spender: Address,
value: U256,
},
-}
-
-pub struct NativeFungibleHandle<T: Config>(SubstrateRecorder<T>);
-
-impl<T: Config> WithRecorder<T> for NativeFungibleHandle<T> {
- fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {
- &self.0
- }
- fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {
- self.0
- }
}
#[solidity_interface(name = ERC20, events(ERC20Events), enum(derive(PreDispatch)), enum_attr(weight), expect_selector = 0x942e8b22)]
pallets/balances-adapter/src/lib.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/lib.rs
+++ b/pallets/balances-adapter/src/lib.rs
@@ -4,17 +4,42 @@
extern crate alloc;
pub use pallet::*;
+use pallet_common::CollectionHandle;
+use pallet_evm_coder_substrate::{WithRecorder, SubstrateRecorder};
+pub mod common;
pub mod erc;
+pub struct NativeFungibleHandle<T: Config>(CollectionHandle<T>);
+impl<T: Config> NativeFungibleHandle<T> {
+ pub fn cast(inner: CollectionHandle<T>) -> Self {
+ Self(inner)
+ }
+
+ /// Casts [`NativeFungibleHandle`] into [`CollectionHandle`][`pallet_common::CollectionHandle`].
+ pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {
+ self.0
+ }
+}
+
+impl<T: Config> WithRecorder<T> for NativeFungibleHandle<T> {
+ fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {
+ &self.0.recorder
+ }
+ fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {
+ self.0.recorder
+ }
+}
#[frame_support::pallet]
pub mod pallet {
use alloc::string::String;
- use frame_support::traits::Get;
+ use frame_support::{traits::Get, sp_runtime::DispatchResult};
use sp_core::U256;
#[pallet::config]
- pub trait Config: frame_system::Config + pallet_evm_coder_substrate::Config {
+ pub trait Config:
+ frame_system::Config + pallet_evm_coder_substrate::Config + pallet_common::Config
+ {
type Currency: frame_support::traits::Currency<
Self::AccountId,
Balance = Self::CurrencyBalance,
@@ -28,6 +53,10 @@
#[pallet::pallet]
pub struct Pallet<T>(_);
- #[pallet::call]
- impl<T: Config> Pallet<T> {}
+ // #[pallet::call]
+ impl<T: Config> Pallet<T> {
+ pub fn dummy() -> DispatchResult {
+ Ok(())
+ }
+ }
}
runtime/common/dispatch.rsdiffbeforeafterboth--- a/runtime/common/dispatch.rs
+++ b/runtime/common/dispatch.rs
@@ -25,6 +25,7 @@
};
pub use pallet_common::dispatch::CollectionDispatch;
use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};
+use pallet_balances_adapter::{Pallet as PalletNativeFungible, NativeFungibleHandle};
use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};
use pallet_refungible::{
Pallet as PalletRefungible, RefungibleHandle, erc_token::RefungibleTokenHandle,
@@ -39,11 +40,15 @@
pub enum CollectionDispatchT<T>
where
- T: pallet_fungible::Config + pallet_nonfungible::Config + pallet_refungible::Config,
+ T: pallet_fungible::Config
+ + pallet_nonfungible::Config
+ + pallet_refungible::Config
+ + pallet_balances_adapter::Config,
{
Fungible(FungibleHandle<T>),
Nonfungible(NonfungibleHandle<T>),
Refungible(RefungibleHandle<T>),
+ NativeFungible(NativeFungibleHandle<T>),
}
impl<T> CollectionDispatch<T> for CollectionDispatchT<T>
where
@@ -51,7 +56,8 @@
+ pallet_unique::Config
+ pallet_fungible::Config
+ pallet_nonfungible::Config
- + pallet_refungible::Config,
+ + pallet_refungible::Config
+ + pallet_balances_adapter::Config,
{
fn create(
sender: T::CrossAccountId,
@@ -100,7 +106,13 @@
fn dispatch(handle: CollectionHandle<T>) -> Self {
match handle.mode {
- CollectionMode::Fungible(_) => Self::Fungible(FungibleHandle::cast(handle)),
+ CollectionMode::Fungible(_) => {
+ if handle.id != up_data_structs::CollectionId(0) {
+ Self::Fungible(FungibleHandle::cast(handle))
+ } else {
+ Self::NativeFungible(NativeFungibleHandle::cast(handle))
+ }
+ }
CollectionMode::NFT => Self::Nonfungible(NonfungibleHandle::cast(handle)),
CollectionMode::ReFungible => Self::Refungible(RefungibleHandle::cast(handle)),
}
@@ -111,6 +123,7 @@
Self::Fungible(f) => f.into_inner(),
Self::Nonfungible(f) => f.into_inner(),
Self::Refungible(f) => f.into_inner(),
+ Self::NativeFungible(f) => f.into_inner(),
}
}
@@ -119,6 +132,7 @@
Self::Fungible(h) => h,
Self::Nonfungible(h) => h,
Self::Refungible(h) => h,
+ Self::NativeFungible(h) => h,
}
}
}
@@ -129,7 +143,8 @@
+ pallet_unique::Config
+ pallet_fungible::Config
+ pallet_nonfungible::Config
- + pallet_refungible::Config,
+ + pallet_refungible::Config
+ + pallet_balances_adapter::Config,
T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,
{
fn is_reserved(target: &H160) -> bool {
@@ -174,6 +189,7 @@
Self::Fungible(h) => h.call(handle),
Self::Nonfungible(h) => h.call(handle),
Self::Refungible(h) => h.call(handle),
+ Self::NativeFungible(f) => todo!(),
}
} else if let Some((collection_id, token_id)) =
<T as pallet_common::Config>::EvmTokenAddressMapping::address_to_token(
tests/src/eth/nativeFungible.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/nativeFungible.test.ts
@@ -0,0 +1,44 @@
+// Copyright 2019-2023 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {itEth, usingEthPlaygrounds} from './util';
+
+describe('NativeFungible: Plain calls', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+ let owner: IKeyringPair;
+
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ donor = await privateKey({url: import.meta.url});
+ [alice, owner] = await helper.arrange.createAccounts([30n, 20n], donor);
+ });
+ });
+
+ itEth.only('Can perform approve()', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const spender = helper.eth.createAccount();
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.mint(alice, 200n, {Ethereum: owner});
+
+ const collectionAddress = helper.ethAddress.fromCollectionId(0);
+ const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
+
+
+ await contract.methods.approve(spender, 100).send({from: owner});
+ });
+});
\ No newline at end of file
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -141,11 +141,16 @@
}
async collection(address: string, mode: TCollectionMode, caller?: string, mergeDeprecated = false) {
- let abi = {
- 'nft': nonFungibleAbi,
- 'rft': refungibleAbi,
- 'ft': fungibleAbi,
- }[mode];
+ let abi;
+ if (address === '0' && mode === 'ft') {
+ abi = nativeFungibleAbi;
+ } else {
+ abi ={
+ 'nft': nonFungibleAbi,
+ 'rft': refungibleAbi,
+ 'ft': fungibleAbi,
+ }[mode];
+ }
if (mergeDeprecated) {
const deprecated = {
'nft': nonFungibleDeprecatedAbi,