difftreelog
feat add dispatching
in: master
6 files changed
pallets/balances-adapter/src/common.rsdiffbeforeafterboth--- /dev/null
+++ b/pallets/balances-adapter/src/common.rs
@@ -0,0 +1,352 @@
+use alloc::vec::Vec;
+use core::marker::PhantomData;
+use crate::{Config, NativeFungibleHandle};
+use pallet_common::{CommonCollectionOperations, CommonWeightInfo};
+
+pub struct CommonWeights<T: Config>(PhantomData<T>);
+impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
+ fn create_multiple_items(
+ amount: &[up_data_structs::CreateItemData],
+ ) -> frame_support::weights::Weight {
+ todo!()
+ }
+
+ fn create_multiple_items_ex(
+ cost: &up_data_structs::CreateItemExData<T::CrossAccountId>,
+ ) -> frame_support::weights::Weight {
+ todo!()
+ }
+
+ fn burn_item() -> frame_support::weights::Weight {
+ todo!()
+ }
+
+ fn set_collection_properties(amount: u32) -> frame_support::weights::Weight {
+ todo!()
+ }
+
+ fn delete_collection_properties(amount: u32) -> frame_support::weights::Weight {
+ todo!()
+ }
+
+ fn set_token_properties(amount: u32) -> frame_support::weights::Weight {
+ todo!()
+ }
+
+ fn delete_token_properties(amount: u32) -> frame_support::weights::Weight {
+ todo!()
+ }
+
+ fn set_token_property_permissions(amount: u32) -> frame_support::weights::Weight {
+ todo!()
+ }
+
+ fn transfer() -> frame_support::weights::Weight {
+ todo!()
+ }
+
+ fn approve() -> frame_support::weights::Weight {
+ todo!()
+ }
+
+ fn approve_from() -> frame_support::weights::Weight {
+ todo!()
+ }
+
+ fn transfer_from() -> frame_support::weights::Weight {
+ todo!()
+ }
+
+ fn burn_from() -> frame_support::weights::Weight {
+ todo!()
+ }
+
+ fn burn_recursively_self_raw() -> frame_support::weights::Weight {
+ todo!()
+ }
+
+ fn burn_recursively_breadth_raw(amount: u32) -> frame_support::weights::Weight {
+ todo!()
+ }
+
+ fn token_owner() -> frame_support::weights::Weight {
+ todo!()
+ }
+
+ fn set_allowance_for_all() -> frame_support::weights::Weight {
+ todo!()
+ }
+
+ fn force_repair_item() -> frame_support::weights::Weight {
+ todo!()
+ }
+}
+
+/// Implementation of `CommonCollectionOperations` for `FungibleHandle`. It wraps FungibleHandle Pallete
+/// methods and adds weight info.
+impl<T: Config> CommonCollectionOperations<T> for NativeFungibleHandle<T> {
+ fn create_item(
+ &self,
+ sender: <T>::CrossAccountId,
+ to: <T>::CrossAccountId,
+ data: up_data_structs::CreateItemData,
+ nesting_budget: &dyn up_data_structs::budget::Budget,
+ ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+ todo!()
+ }
+
+ fn create_multiple_items(
+ &self,
+ sender: <T>::CrossAccountId,
+ to: <T>::CrossAccountId,
+ data: Vec<up_data_structs::CreateItemData>,
+ nesting_budget: &dyn up_data_structs::budget::Budget,
+ ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+ todo!()
+ }
+
+ fn create_multiple_items_ex(
+ &self,
+ sender: <T>::CrossAccountId,
+ data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,
+ nesting_budget: &dyn up_data_structs::budget::Budget,
+ ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+ todo!()
+ }
+
+ fn burn_item(
+ &self,
+ sender: <T>::CrossAccountId,
+ token: up_data_structs::TokenId,
+ amount: u128,
+ ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+ todo!()
+ }
+
+ fn burn_item_recursively(
+ &self,
+ sender: <T>::CrossAccountId,
+ token: up_data_structs::TokenId,
+ self_budget: &dyn up_data_structs::budget::Budget,
+ breadth_budget: &dyn up_data_structs::budget::Budget,
+ ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+ todo!()
+ }
+
+ fn set_collection_properties(
+ &self,
+ sender: <T>::CrossAccountId,
+ properties: Vec<up_data_structs::Property>,
+ ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+ todo!()
+ }
+
+ fn delete_collection_properties(
+ &self,
+ sender: &<T>::CrossAccountId,
+ property_keys: Vec<up_data_structs::PropertyKey>,
+ ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+ todo!()
+ }
+
+ fn set_token_properties(
+ &self,
+ sender: <T>::CrossAccountId,
+ token_id: up_data_structs::TokenId,
+ properties: Vec<up_data_structs::Property>,
+ budget: &dyn up_data_structs::budget::Budget,
+ ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+ todo!()
+ }
+
+ fn delete_token_properties(
+ &self,
+ sender: <T>::CrossAccountId,
+ token_id: up_data_structs::TokenId,
+ property_keys: Vec<up_data_structs::PropertyKey>,
+ budget: &dyn up_data_structs::budget::Budget,
+ ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+ todo!()
+ }
+
+ fn set_token_property_permissions(
+ &self,
+ sender: &<T>::CrossAccountId,
+ property_permissions: Vec<up_data_structs::PropertyKeyPermission>,
+ ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+ todo!()
+ }
+
+ fn transfer(
+ &self,
+ sender: <T>::CrossAccountId,
+ to: <T>::CrossAccountId,
+ token: up_data_structs::TokenId,
+ amount: u128,
+ budget: &dyn up_data_structs::budget::Budget,
+ ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+ todo!()
+ }
+
+ fn approve(
+ &self,
+ sender: <T>::CrossAccountId,
+ spender: <T>::CrossAccountId,
+ token: up_data_structs::TokenId,
+ amount: u128,
+ ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+ todo!()
+ }
+
+ fn approve_from(
+ &self,
+ sender: <T>::CrossAccountId,
+ from: <T>::CrossAccountId,
+ to: <T>::CrossAccountId,
+ token: up_data_structs::TokenId,
+ amount: u128,
+ ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+ todo!()
+ }
+
+ fn transfer_from(
+ &self,
+ sender: <T>::CrossAccountId,
+ from: <T>::CrossAccountId,
+ to: <T>::CrossAccountId,
+ token: up_data_structs::TokenId,
+ amount: u128,
+ budget: &dyn up_data_structs::budget::Budget,
+ ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+ todo!()
+ }
+
+ fn burn_from(
+ &self,
+ sender: <T>::CrossAccountId,
+ from: <T>::CrossAccountId,
+ token: up_data_structs::TokenId,
+ amount: u128,
+ budget: &dyn up_data_structs::budget::Budget,
+ ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+ todo!()
+ }
+
+ fn check_nesting(
+ &self,
+ sender: <T>::CrossAccountId,
+ from: (up_data_structs::CollectionId, up_data_structs::TokenId),
+ under: up_data_structs::TokenId,
+ budget: &dyn up_data_structs::budget::Budget,
+ ) -> frame_support::sp_runtime::DispatchResult {
+ todo!()
+ }
+
+ fn nest(
+ &self,
+ under: up_data_structs::TokenId,
+ to_nest: (up_data_structs::CollectionId, up_data_structs::TokenId),
+ ) {
+ todo!()
+ }
+
+ fn unnest(
+ &self,
+ under: up_data_structs::TokenId,
+ to_nest: (up_data_structs::CollectionId, up_data_structs::TokenId),
+ ) {
+ todo!()
+ }
+
+ fn account_tokens(&self, account: <T>::CrossAccountId) -> Vec<up_data_structs::TokenId> {
+ todo!()
+ }
+
+ fn collection_tokens(&self) -> Vec<up_data_structs::TokenId> {
+ todo!()
+ }
+
+ fn token_exists(&self, token: up_data_structs::TokenId) -> bool {
+ todo!()
+ }
+
+ fn last_token_id(&self) -> up_data_structs::TokenId {
+ todo!()
+ }
+
+ fn token_owner(
+ &self,
+ token: up_data_structs::TokenId,
+ ) -> Result<<T>::CrossAccountId, up_data_structs::TokenOwnerError> {
+ todo!()
+ }
+
+ fn token_owners(&self, token: up_data_structs::TokenId) -> Vec<<T>::CrossAccountId> {
+ todo!()
+ }
+
+ fn token_property(
+ &self,
+ token_id: up_data_structs::TokenId,
+ key: &up_data_structs::PropertyKey,
+ ) -> Option<up_data_structs::PropertyValue> {
+ todo!()
+ }
+
+ fn token_properties(
+ &self,
+ token: up_data_structs::TokenId,
+ keys: Option<Vec<up_data_structs::PropertyKey>>,
+ ) -> Vec<up_data_structs::Property> {
+ todo!()
+ }
+
+ fn total_supply(&self) -> u32 {
+ todo!()
+ }
+
+ fn account_balance(&self, account: <T>::CrossAccountId) -> u32 {
+ todo!()
+ }
+
+ fn balance(&self, account: <T>::CrossAccountId, token: up_data_structs::TokenId) -> u128 {
+ todo!()
+ }
+
+ fn total_pieces(&self, token: up_data_structs::TokenId) -> Option<u128> {
+ todo!()
+ }
+
+ fn allowance(
+ &self,
+ sender: <T>::CrossAccountId,
+ spender: <T>::CrossAccountId,
+ token: up_data_structs::TokenId,
+ ) -> u128 {
+ todo!()
+ }
+
+ fn refungible_extensions(&self) -> Option<&dyn pallet_common::RefungibleExtensions<T>> {
+ todo!()
+ }
+
+ fn set_allowance_for_all(
+ &self,
+ owner: <T>::CrossAccountId,
+ operator: <T>::CrossAccountId,
+ approve: bool,
+ ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+ todo!()
+ }
+
+ fn allowance_for_all(&self, owner: <T>::CrossAccountId, operator: <T>::CrossAccountId) -> bool {
+ todo!()
+ }
+
+ fn repair_item(
+ &self,
+ token: up_data_structs::TokenId,
+ ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
+ todo!()
+ }
+}
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.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.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,