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.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.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! {