From b887f62f2dc2e7029f35116fc7cf5b9e2f5fed67 Mon Sep 17 00:00:00 2001 From: dmoka Date: Wed, 18 Dec 2024 14:01:04 +0100 Subject: [PATCH] cleaning up --- pallets/amm-support/README.md | 4 ---- pallets/amm-support/src/lib.rs | 20 ++++++++----------- .../amm-support/src/tests/incremental_id.rs | 1 - pallets/amm-support/src/types.rs | 1 - 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/pallets/amm-support/README.md b/pallets/amm-support/README.md index 44eb41c86..7c1222481 100644 --- a/pallets/amm-support/README.md +++ b/pallets/amm-support/README.md @@ -24,7 +24,3 @@ remove nonfungibalbe asset type input and output should be tpye instead of tuple, because asset fee is also having same strucutre for inputs, outputs and fees - -next inceremetnal id use overflwoing add - -call it context instead of stack \ No newline at end of file diff --git a/pallets/amm-support/src/lib.rs b/pallets/amm-support/src/lib.rs index 57f351265..7be2f610f 100644 --- a/pallets/amm-support/src/lib.rs +++ b/pallets/amm-support/src/lib.rs @@ -22,14 +22,12 @@ type AssetId = u32; type Balance = u128; use crate::types::*; -use codec::{Decode, Encode}; use frame_support::sp_runtime::app_crypto::sp_core; use frame_support::sp_runtime::{ArithmeticError, BoundedVec, DispatchError, DispatchResult}; use frame_system::pallet_prelude::BlockNumberFor; pub use primitives::IncrementalId as IncrementalIdType; use primitives::ItemId as NftId; -use scale_info::TypeInfo; -use sp_core::{ConstU32, RuntimeDebug}; +use sp_core::{ConstU32}; use sp_std::vec::Vec; #[cfg(test)] mod tests; @@ -65,11 +63,10 @@ pub mod pallet { #[pallet::getter(fn incremental_id)] pub(super) type IncrementalId = StorageValue<_, IncrementalIdType, ValueQuery>; - //TODO: add better name #[pallet::storage] - /// Next available incremental ID + /// Execution context stack #[pallet::getter(fn id_stack)] - pub(super) type IdStack = StorageValue<_, ExecutionIdStack, ValueQuery>; + pub(super) type ExecutionContext = StorageValue<_, ExecutionIdStack, ValueQuery>; #[pallet::error] pub enum Error { @@ -96,11 +93,10 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { fn on_initialize(_n: BlockNumberFor) -> Weight { - //TODO: we might not need it if we can make sotrage not persistable let mut weight: Weight = Weight::zero(); weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1)); - IdStack::::get().clear(); + ExecutionContext::::kill(); Weight::from_parts(weight.ref_time(), 0) } @@ -129,7 +125,7 @@ impl Pallet { outputs: Vec<(AssetType, Balance)>, fees: Vec>, ) { - let operation_id = IdStack::::get().to_vec(); + let operation_id = ExecutionContext::::get().to_vec(); Self::deposit_event(Event::::Swapped { swapper, filler, @@ -151,7 +147,7 @@ impl Pallet { Ok(inc_id) })?; - IdStack::::try_mutate(|stack| -> DispatchResult { + ExecutionContext::::try_mutate(|stack| -> DispatchResult { stack .try_push(execution_type(next_id)) .map_err(|_| Error::::MaxStackSizeReached)?; @@ -165,13 +161,13 @@ impl Pallet { //TODO: rename to pop context pub fn remove_from_context() -> Result, DispatchError> { //TODO: check what to do when it fails, we might dont want to bloc ktrades becase of it - IdStack::::try_mutate(|stack| -> Result, DispatchError> { + ExecutionContext::::try_mutate(|stack| -> Result, DispatchError> { stack.pop().ok_or(Error::::EmptyStack.into()) }) } fn get() -> Vec> { - IdStack::::get().to_vec() + ExecutionContext::::get().to_vec() } } diff --git a/pallets/amm-support/src/tests/incremental_id.rs b/pallets/amm-support/src/tests/incremental_id.rs index 2ca8e07eb..a038374f9 100644 --- a/pallets/amm-support/src/tests/incremental_id.rs +++ b/pallets/amm-support/src/tests/incremental_id.rs @@ -16,7 +16,6 @@ // limitations under the License. use crate::tests::mock::*; -use crate::types::*; use crate::Event; #[test] fn event_id_should_be_incremented() { diff --git a/pallets/amm-support/src/types.rs b/pallets/amm-support/src/types.rs index c84d83965..95f68fefc 100644 --- a/pallets/amm-support/src/types.rs +++ b/pallets/amm-support/src/types.rs @@ -1,5 +1,4 @@ use codec::{Decode, Encode, MaxEncodedLen}; -use frame_support::dispatch::DispatchResultWithPostInfo; use scale_info::TypeInfo; #[cfg(feature = "std")] use serde::{Deserialize, Serialize};