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.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/lib.rs
+++ b/pallets/balances-adapter/src/lib.rs
@@ -8,8 +8,16 @@
#[frame_support::pallet]
pub mod pallet {
+ 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 {
+ type Currency: frame_support::traits::Currency<
+ Self::AccountId,
+ Balance = Self::CurrencyBalance,
+ >;
+ type CurrencyBalance: Into<U256>;
+ }
#[pallet::pallet]
pub struct Pallet<T>(_);
runtime/common/config/pallets/mod.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -25,7 +25,7 @@
},
Runtime, RuntimeEvent, RuntimeCall, RuntimeOrigin, Balances,
};
-use frame_support::traits::{ConstU32, ConstU64};
+use frame_support::traits::{ConstU32, ConstU64, Currency};
use up_common::{
types::{AccountId, Balance, BlockNumber},
constants::*,
@@ -84,7 +84,8 @@
type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;
}
impl pallet_balances_adapter::Config for Runtime {
- // type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;
+ type Currency = Balances;
+ type CurrencyBalance = <Balances as Currency<Self::AccountId>>::Balance;
}
parameter_types! {