Skip to content

Commit

Permalink
cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
dmoka committed Dec 18, 2024
1 parent 83104b3 commit b887f62
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
4 changes: 0 additions & 4 deletions pallets/amm-support/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 8 additions & 12 deletions pallets/amm-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,11 +63,10 @@ pub mod pallet {
#[pallet::getter(fn incremental_id)]
pub(super) type IncrementalId<T: Config> = 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<T: Config> = StorageValue<_, ExecutionIdStack, ValueQuery>;
pub(super) type ExecutionContext<T: Config> = StorageValue<_, ExecutionIdStack, ValueQuery>;

#[pallet::error]
pub enum Error<T> {
Expand All @@ -96,11 +93,10 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_n: BlockNumberFor<T>) -> 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::<T>::get().clear();
ExecutionContext::<T>::kill();

Weight::from_parts(weight.ref_time(), 0)
}
Expand Down Expand Up @@ -129,7 +125,7 @@ impl<T: Config> Pallet<T> {
outputs: Vec<(AssetType<AssetId, NftId>, Balance)>,
fees: Vec<Fee<AssetId, Balance, T::AccountId>>,
) {
let operation_id = IdStack::<T>::get().to_vec();
let operation_id = ExecutionContext::<T>::get().to_vec();
Self::deposit_event(Event::<T>::Swapped {
swapper,
filler,
Expand All @@ -151,7 +147,7 @@ impl<T: Config> Pallet<T> {
Ok(inc_id)
})?;

IdStack::<T>::try_mutate(|stack| -> DispatchResult {
ExecutionContext::<T>::try_mutate(|stack| -> DispatchResult {
stack
.try_push(execution_type(next_id))
.map_err(|_| Error::<T>::MaxStackSizeReached)?;
Expand All @@ -165,13 +161,13 @@ impl<T: Config> Pallet<T> {
//TODO: rename to pop context
pub fn remove_from_context() -> Result<ExecutionType<IncrementalIdType>, DispatchError> {
//TODO: check what to do when it fails, we might dont want to bloc ktrades becase of it
IdStack::<T>::try_mutate(|stack| -> Result<ExecutionType<IncrementalIdType>, DispatchError> {
ExecutionContext::<T>::try_mutate(|stack| -> Result<ExecutionType<IncrementalIdType>, DispatchError> {
stack.pop().ok_or(Error::<T>::EmptyStack.into())
})
}

fn get() -> Vec<ExecutionType<IncrementalIdType>> {
IdStack::<T>::get().to_vec()
ExecutionContext::<T>::get().to_vec()
}

}
1 change: 0 additions & 1 deletion pallets/amm-support/src/tests/incremental_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 0 additions & 1 deletion pallets/amm-support/src/types.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down

0 comments on commit b887f62

Please sign in to comment.