difftreelog
feat impl approve, allowance, balance_of
in: master
3 files changed
pallets/balances-adapter/src/erc.rsdiffbeforeafterboth1use crate::Config;1use crate::Config;2use evm_coder::{abi::AbiType, AbiCoder, ToLog, generate_stubgen, solidity_interface, types::*};2use evm_coder::{abi::AbiType, AbiCoder, ToLog, generate_stubgen, solidity_interface, types::*};3use frame_support::traits::Currency;3use pallet_common::erc::{CommonEvmHandler, PrecompileHandle, PrecompileResult};4use pallet_common::erc::{CommonEvmHandler, CrossAccountId, PrecompileHandle, PrecompileResult};4use pallet_evm_coder_substrate::{5use pallet_evm_coder_substrate::{5 call, dispatch_to_evm,6 call, dispatch_to_evm,6 execution::{PreDispatch, Result},7 execution::{PreDispatch, Result},454646#[solidity_interface(name = ERC20, events(ERC20Events), enum(derive(PreDispatch)), enum_attr(weight), expect_selector = 0x942e8b22)]47#[solidity_interface(name = ERC20, events(ERC20Events), enum(derive(PreDispatch)), enum_attr(weight), expect_selector = 0x942e8b22)]47impl<T: Config> NativeFungibleHandle<T> {48impl<T: Config> NativeFungibleHandle<T> {49 fn allowance(&self, owner: Address, spender: Address) -> Result<U256> {50 Ok(U256::zero())51 }5253 // #[weight(<SelfWeightOf<T>>::approve())]54 fn approve(&mut self, caller: Caller, spender: Address, amount: U256) -> Result<bool> {55 // self.consume_store_reads(1)?;56 Err("Approve not supported now".into())57 }58 fn balance_of(&self, owner: Address) -> Result<U256> {59 // self.consume_store_reads(1)?;60 let owner = T::CrossAccountId::from_eth(owner);61 let a = <T as Config>::Currency::free_balance(owner.as_sub());62 Ok(a.into())63 }6465 fn decimals(&self) -> Result<u8> {66 // Ok(if let CollectionMode::Fungible(decimals) = &self.mode {67 // *decimals68 // } else {69 // unreachable!70 // })7172 // From config 1873 todo!()74 }7548 fn name(&self) -> Result<String> {76 fn name(&self) -> Result<String> {49 // Ok(decode_utf16(self.name.iter().copied())77 // Ok(decode_utf16(self.name.iter().copied())62 todo!()91 todo!()63 }92 }6465 fn decimals(&self) -> Result<u8> {66 // Ok(if let CollectionMode::Fungible(decimals) = &self.mode {67 // *decimals68 // } else {69 // unreachable!()70 // })71 todo!()72 }7374 fn balance_of(&self, owner: Address) -> Result<U256> {75 // self.consume_store_reads(1)?;76 // let owner = T::CrossAccountId::from_eth(owner);77 // let balance = <Balance<T>>::get((self.id, owner));78 // Ok(balance.into())79 todo!()80 }819382 // #[weight(<SelfWeightOf<T>>::transfer())]94 // #[weight(<SelfWeightOf<T>>::transfer())]83 fn transfer(&mut self, caller: Caller, to: Address, amount: U256) -> Result<bool> {95 fn transfer(&mut self, caller: Caller, to: Address, amount: U256) -> Result<bool> {115 todo!()127 todo!()116 }128 }117118 // #[weight(<SelfWeightOf<T>>::approve())]119 fn approve(&mut self, caller: Caller, spender: Address, amount: U256) -> Result<bool> {120 // let caller = T::CrossAccountId::from_eth(caller);121 // let spender = T::CrossAccountId::from_eth(spender);122 // let amount = amount.try_into().map_err(|_| "amount overflow")?;123124 // <Pallet<T>>::set_allowance(self, &caller, &spender, amount)125 // .map_err(dispatch_to_evm::<T>)?;126 // Ok(true)127 todo!()128 }129130 fn allowance(&self, owner: Address, spender: Address) -> Result<U256> {131 // self.consume_store_reads(1)?;132 // let owner = T::CrossAccountId::from_eth(owner);133 // let spender = T::CrossAccountId::from_eth(spender);134135 // Ok(<Allowance<T>>::get((self.id, owner, spender)).into())136 todo!()137 }138}129}139130140#[solidity_interface(131#[solidity_interface(pallets/balances-adapter/src/lib.rsdiffbeforeafterboth889#[frame_support::pallet]9#[frame_support::pallet]10pub mod pallet {10pub mod pallet {11 use sp_core::U256;1211 #[pallet::config]13 #[pallet::config]12 pub trait Config: frame_system::Config + pallet_evm_coder_substrate::Config {}14 pub trait Config: frame_system::Config + pallet_evm_coder_substrate::Config {15 type Currency: frame_support::traits::Currency<16 Self::AccountId,17 Balance = Self::CurrencyBalance,18 >;19 type CurrencyBalance: Into<U256>;20 }13 #[pallet::pallet]21 #[pallet::pallet]14 pub struct Pallet<T>(_);22 pub struct Pallet<T>(_);runtime/common/config/pallets/mod.rsdiffbeforeafterboth25 },25 },26 Runtime, RuntimeEvent, RuntimeCall, RuntimeOrigin, Balances,26 Runtime, RuntimeEvent, RuntimeCall, RuntimeOrigin, Balances,27};27};28use frame_support::traits::{ConstU32, ConstU64};28use frame_support::traits::{ConstU32, ConstU64, Currency};29use up_common::{29use up_common::{30 types::{AccountId, Balance, BlockNumber},30 types::{AccountId, Balance, BlockNumber},31 constants::*,31 constants::*,84 type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;84 type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;85}85}86impl pallet_balances_adapter::Config for Runtime {86impl pallet_balances_adapter::Config for Runtime {87 // type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;87 type Currency = Balances;88 type CurrencyBalance = <Balances as Currency<Self::AccountId>>::Balance;88}89}899090parameter_types! {91parameter_types! {