From 2986891de0fe9a43fb413da9382630e29fa69227 Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Fri, 11 Oct 2024 17:22:10 -0300 Subject: [PATCH 1/3] use reducible_balance to get free balance --- Cargo.lock | 1 + chain-extensions/token/Cargo.toml | 2 ++ chain-extensions/token/src/lib.rs | 21 +++++++++++++-------- zombienet/config.toml | 21 +++++++++++---------- 4 files changed, 27 insertions(+), 18 deletions(-) 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..deb12cbd6 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, @@ -19,8 +20,8 @@ use sp_core::crypto::UncheckedFrom; 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 +70,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 +156,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 +180,14 @@ 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..389f4240f 100644 --- a/zombienet/config.toml +++ b/zombienet/config.toml @@ -1,22 +1,23 @@ +[settings] +timeout = 1000 + [relaychain] -default_command = "../polkadot/target/release/polkadot" +default_command = "/Users/gianni/root/Pendulum/polkadot-sdk/target/debug/polkadot" default_args = [ "-lparachain=debug" ] chain = "rococo-local" - [[relaychain.nodes]] - name = "alice" - validator = true +[[relaychain.nodes]] +name = "alice" - [[relaychain.nodes]] - name = "bob" - validator = true +[[relaychain.nodes]] +name = "bob" [[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 = "/Users/gianni/root/Pendulum/pendulum/target/release/pendulum-node" From 1b7d4fa6d1ac4fac8a3c97b9433e4d7ce410c2d6 Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Fri, 11 Oct 2024 17:49:45 -0300 Subject: [PATCH 2/3] clean zombienet local command --- chain-extensions/token/src/lib.rs | 1 - zombienet/config.toml | 10 ++++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/chain-extensions/token/src/lib.rs b/chain-extensions/token/src/lib.rs index deb12cbd6..54d1a9ba1 100644 --- a/chain-extensions/token/src/lib.rs +++ b/chain-extensions/token/src/lib.rs @@ -183,7 +183,6 @@ where 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() }; diff --git a/zombienet/config.toml b/zombienet/config.toml index 389f4240f..1442ad56b 100644 --- a/zombienet/config.toml +++ b/zombienet/config.toml @@ -1,16 +1,15 @@ -[settings] -timeout = 1000 - [relaychain] -default_command = "/Users/gianni/root/Pendulum/polkadot-sdk/target/debug/polkadot" +default_command = "../polkadot/target/release/polkadot" default_args = [ "-lparachain=debug" ] chain = "rococo-local" [[relaychain.nodes]] name = "alice" +validator = true [[relaychain.nodes]] name = "bob" +validator = true [[parachains]] id = 1000 @@ -19,5 +18,4 @@ chain = "foucoco" # "pendulum"/"amplitude"/"dev"/"local" [parachains.collator] name = "alice" -command = "/Users/gianni/root/Pendulum/pendulum/target/release/pendulum-node" - +command = "../pendulum/target/release/pendulum-node" \ No newline at end of file From 8c3245d0fac5630b7f4bcf5875dd4bd277bfca0c Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Mon, 14 Oct 2024 09:41:10 -0300 Subject: [PATCH 3/3] add missing import --- chain-extensions/token/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/chain-extensions/token/src/lib.rs b/chain-extensions/token/src/lib.rs index 54d1a9ba1..6c4884b43 100644 --- a/chain-extensions/token/src/lib.rs +++ b/chain-extensions/token/src/lib.rs @@ -17,6 +17,7 @@ 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;