diff --git a/Cargo.lock b/Cargo.lock index 3e7192fae..14a660e51 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15564,6 +15564,7 @@ dependencies = [ "orml-currencies-allowance-extension", "orml-tokens", "orml-traits", + "pallet-balances", "pallet-contracts", "parity-scale-codec", "sp-core", diff --git a/chain-extensions/token/Cargo.toml b/chain-extensions/token/Cargo.toml index cf070adb1..614677392 100644 --- a/chain-extensions/token/Cargo.toml +++ b/chain-extensions/token/Cargo.toml @@ -21,6 +21,7 @@ sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", default-featu sp-std = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false } sp-tracing = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" } sp-weights = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" } +pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" } pallet-contracts = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" } # Open Runtime Module Library @@ -56,4 +57,5 @@ std = [ "spacewalk-primitives/std", "chain-extension-common/std", "sp-std/std", + "pallet-balances/std" ] diff --git a/chain-extensions/token/src/lib.rs b/chain-extensions/token/src/lib.rs index 17eb83dc7..6c4884b43 100644 --- a/chain-extensions/token/src/lib.rs +++ b/chain-extensions/token/src/lib.rs @@ -7,6 +7,7 @@ use frame_support::{ pallet_prelude::{Decode, Get, PhantomData}, DefaultNoBound, }; +use frame_support::traits::tokens::{fungibles,fungible, Preservation, Fortitude}; use orml_currencies::WeightInfo; use orml_currencies_allowance_extension::{ default_weights::WeightInfo as AllowanceWeightInfo, Config as AllowanceConfig, @@ -16,11 +17,12 @@ use pallet_contracts::chain_extension::{ ChainExtension, Environment, Ext, InitState, RetVal, SysConfig, }; use sp_core::crypto::UncheckedFrom; +use sp_std::vec::Vec; use sp_runtime::DispatchError; use sp_tracing::{error, trace}; use sp_weights::Weight; -use spacewalk_primitives::CurrencyId; - +use spacewalk_primitives::{CurrencyId}; +use pallet_balances; pub(crate) type BalanceOfForChainExt = <::MultiCurrency as orml_traits::MultiCurrency< ::AccountId, @@ -69,6 +71,7 @@ where T: SysConfig + orml_tokens::Config + pallet_contracts::Config + + pallet_balances::Config + orml_currencies::Config + orml_currencies_allowance_extension::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, @@ -154,7 +157,8 @@ where T: SysConfig + orml_tokens::Config + pallet_contracts::Config - + orml_currencies::Config + + orml_currencies::Config + + pallet_balances::Config + orml_currencies_allowance_extension::Config, E: Ext, Tokens: orml_traits::MultiCurrency, @@ -177,12 +181,13 @@ where return Ok(RetVal::Converging(ChainExtensionTokenError::Unsupported.as_u32())) } - let balance = as MultiCurrency>::free_balance( - currency_id, - &account_id, - ); + let balance_encoded: Vec = if currency_id == T::GetNativeCurrencyId::get() { + as fungible::Inspect>::reducible_balance(&account_id, Preservation::Preserve, Fortitude::Polite).encode() + } else { + as fungibles::Inspect>::reducible_balance(currency_id, &account_id, Preservation::Preserve, Fortitude::Polite).encode() + }; - if let Err(_) = env.write(&balance.encode(), false, None) { + if let Err(_) = env.write(&balance_encoded, false, None) { return Ok(RetVal::Converging(ChainExtensionOutcome::WriteError.as_u32())) }; return Ok(RetVal::Converging(ChainExtensionOutcome::Success.as_u32())) diff --git a/zombienet/config.toml b/zombienet/config.toml index 558bc1e3d..1442ad56b 100644 --- a/zombienet/config.toml +++ b/zombienet/config.toml @@ -3,20 +3,19 @@ default_command = "../polkadot/target/release/polkadot" default_args = [ "-lparachain=debug" ] chain = "rococo-local" - [[relaychain.nodes]] - name = "alice" - validator = true +[[relaychain.nodes]] +name = "alice" +validator = true - [[relaychain.nodes]] - name = "bob" - validator = true +[[relaychain.nodes]] +name = "bob" +validator = true [[parachains]] id = 1000 cumulus_based = true chain = "foucoco" # "pendulum"/"amplitude"/"dev"/"local" - [parachains.collator] - name = "alice" - command = "../pendulum/target/release/pendulum-node" - +[parachains.collator] +name = "alice" +command = "../pendulum/target/release/pendulum-node" \ No newline at end of file