difftreelog
feat impl approve, allowance, balance_of
in: master
3 files changed
pallets/balances-adapter/src/erc.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/erc.rs
+++ b/pallets/balances-adapter/src/erc.rs
@@ -1,6 +1,7 @@
use crate::Config;
use evm_coder::{abi::AbiType, AbiCoder, ToLog, generate_stubgen, solidity_interface, types::*};
-use pallet_common::erc::{CommonEvmHandler, PrecompileHandle, PrecompileResult};
+use frame_support::traits::Currency;
+use pallet_common::erc::{CommonEvmHandler, CrossAccountId, PrecompileHandle, PrecompileResult};
use pallet_evm_coder_substrate::{
call, dispatch_to_evm,
execution::{PreDispatch, Result},
@@ -45,37 +46,48 @@
#[solidity_interface(name = ERC20, events(ERC20Events), enum(derive(PreDispatch)), enum_attr(weight), expect_selector = 0x942e8b22)]
impl<T: Config> NativeFungibleHandle<T> {
- fn name(&self) -> Result<String> {
- // Ok(decode_utf16(self.name.iter().copied())
- // .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
- // .collect::<String>())
- todo!()
+ fn allowance(&self, owner: Address, spender: Address) -> Result<U256> {
+ Ok(U256::zero())
}
- fn symbol(&self) -> Result<String> {
- // Ok(String::from_utf8_lossy(&self.token_prefix).into())
- todo!()
+ // #[weight(<SelfWeightOf<T>>::approve())]
+ fn approve(&mut self, caller: Caller, spender: Address, amount: U256) -> Result<bool> {
+ // self.consume_store_reads(1)?;
+ Err("Approve not supported now".into())
}
- fn total_supply(&self) -> Result<U256> {
+ fn balance_of(&self, owner: Address) -> Result<U256> {
// self.consume_store_reads(1)?;
- // Ok(<TotalSupply<T>>::get(self.id).into())
- todo!()
+ let owner = T::CrossAccountId::from_eth(owner);
+ let a = <T as Config>::Currency::free_balance(owner.as_sub());
+ Ok(a.into())
}
fn decimals(&self) -> Result<u8> {
// Ok(if let CollectionMode::Fungible(decimals) = &self.mode {
// *decimals
// } else {
- // unreachable!()
+ // unreachable!
// })
+
+ // From config 18
todo!()
}
- fn balance_of(&self, owner: Address) -> Result<U256> {
+ fn name(&self) -> Result<String> {
+ // Ok(decode_utf16(self.name.iter().copied())
+ // .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
+ // .collect::<String>())
+ todo!()
+ }
+
+ fn symbol(&self) -> Result<String> {
+ // Ok(String::from_utf8_lossy(&self.token_prefix).into())
+ todo!()
+ }
+
+ fn total_supply(&self) -> Result<U256> {
// self.consume_store_reads(1)?;
- // let owner = T::CrossAccountId::from_eth(owner);
- // let balance = <Balance<T>>::get((self.id, owner));
- // Ok(balance.into())
+ // Ok(<TotalSupply<T>>::get(self.id).into())
todo!()
}
@@ -112,27 +124,6 @@
// <Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)
// .map_err(dispatch_to_evm::<T>)?;
// Ok(true)
- todo!()
- }
-
- // #[weight(<SelfWeightOf<T>>::approve())]
- fn approve(&mut self, caller: Caller, spender: Address, amount: U256) -> Result<bool> {
- // let caller = T::CrossAccountId::from_eth(caller);
- // let spender = T::CrossAccountId::from_eth(spender);
- // let amount = amount.try_into().map_err(|_| "amount overflow")?;
-
- // <Pallet<T>>::set_allowance(self, &caller, &spender, amount)
- // .map_err(dispatch_to_evm::<T>)?;
- // Ok(true)
- todo!()
- }
-
- fn allowance(&self, owner: Address, spender: Address) -> Result<U256> {
- // self.consume_store_reads(1)?;
- // let owner = T::CrossAccountId::from_eth(owner);
- // let spender = T::CrossAccountId::from_eth(spender);
-
- // Ok(<Allowance<T>>::get((self.id, owner, spender)).into())
todo!()
}
}
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.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! {