diff --git a/pallets/ocex/src/lib.rs b/pallets/ocex/src/lib.rs index ea156dce5..c1ed649d0 100644 --- a/pallets/ocex/src/lib.rs +++ b/pallets/ocex/src/lib.rs @@ -1966,7 +1966,7 @@ pub mod pallet { let config = crate::lmp::get_lmp_config(&mut state, current_epoch)?; log::debug!(target:"ocex", "fetch_checkpoint returning"); - Ok(ObCheckpointRaw::new( + Ok(ObCheckpointRaw { snapshot_id, balances, last_processed_block_number, @@ -1977,7 +1977,7 @@ pub mod pallet { taker_volume_map, fees_paid_map, total_maker_volume_map, - )) + }) } /// Fetches balance of given `AssetId` for given `AccountId` from offchain storage diff --git a/pallets/ocex/src/lmp.rs b/pallets/ocex/src/lmp.rs index f46080fde..2432c96a5 100644 --- a/pallets/ocex/src/lmp.rs +++ b/pallets/ocex/src/lmp.rs @@ -52,6 +52,7 @@ pub mod keys { use orderbook_primitives::types::TradingPair; use parity_scale_codec::Encode; use polkadex_primitives::AccountId; + use sp_std::vec::Vec; pub fn get_trade_volume_by_main_account_key( epoch: u16, @@ -103,7 +104,7 @@ pub fn update_trade_volume_by_main_account( volume: Decimal, main: &AccountId, ) -> Result { - let key = get_trade_volume_by_main_account_key(epoch, trading_pair, &main); + let key = get_trade_volume_by_main_account_key(epoch, trading_pair, main); Ok(match state.get(&key)? { None => { state.insert(key, volume.encode()); @@ -126,7 +127,7 @@ pub fn get_trade_volume_by_main_account( trading_pair: &TradingPair, main: &AccountId, ) -> Result { - let key = get_trade_volume_by_main_account_key(epoch, *trading_pair, &main); + let key = get_trade_volume_by_main_account_key(epoch, *trading_pair, main); Ok(match state.get(&key)? { None => Decimal::zero(), Some(encoded_volume) => { @@ -142,7 +143,7 @@ pub fn get_maker_volume_by_main_account( trading_pair: &TradingPair, main: &AccountId, ) -> Result { - let key = get_maker_volume_by_main_account_key(epoch, *trading_pair, &main); + let key = get_maker_volume_by_main_account_key(epoch, *trading_pair, main); Ok(match state.get(&key)? { None => Decimal::zero(), Some(encoded_volume) => { @@ -159,7 +160,7 @@ pub fn update_maker_volume_by_main_account( volume: Decimal, main: &AccountId, ) -> Result { - let key = get_maker_volume_by_main_account_key(epoch, trading_pair, &main); + let key = get_maker_volume_by_main_account_key(epoch, trading_pair, main); Ok(match state.get(&key)? { None => { state.insert(key, volume.encode()); diff --git a/primitives/orderbook/src/lib.rs b/primitives/orderbook/src/lib.rs index 765ed79e0..ee11f2e43 100644 --- a/primitives/orderbook/src/lib.rs +++ b/primitives/orderbook/src/lib.rs @@ -24,6 +24,7 @@ #![cfg_attr(not(feature = "std"), no_std)] use crate::ingress::EgressMessages; +use crate::lmp::LMPConfig; #[cfg(feature = "std")] use crate::recovery::ObCheckpoint; use crate::types::{AccountAsset, TradingPair}; @@ -38,7 +39,6 @@ use serde::{Deserialize, Serialize}; use sp_core::crypto::AccountId32; use sp_core::H256; use sp_std::{collections::btree_map::BTreeMap, vec::Vec}; -use crate::lmp::LMPConfig; pub mod constants; pub mod types; @@ -180,40 +180,6 @@ pub struct ObCheckpointRaw { } impl ObCheckpointRaw { - /// Create a new `ObCheckpointRaw` instance. - /// # Parameters - /// * `snapshot_id`: The snapshot ID of the order book recovery state. - /// * `balances`: A `BTreeMap` that maps `AccountAsset`s to `Decimal` balances. - /// * `last_processed_block_number`: The last block number that was processed by validator. - /// * `state_change_id`: State change id - /// # Returns - /// * `ObCheckpointRaw`: A new `ObCheckpointRaw` instance. - pub fn new( - snapshot_id: u64, - balances: BTreeMap, - last_processed_block_number: BlockNumber, - state_change_id: u64, - config: LMPConfig, - q_scores_uptime_map: BTreeMap<(u16, TradingPair, AccountId32), BTreeMap>, - maker_volume_map: BTreeMap<(u16, TradingPair, AccountId32), Decimal>, - taker_volume_map: BTreeMap<(u16, TradingPair, AccountId32), Decimal>, - fees_paid_map: BTreeMap<(u16, TradingPair, AccountId32), Decimal>, - total_maker_volume_map: BTreeMap<(u16, TradingPair), Decimal>, - ) -> Self { - Self { - snapshot_id, - balances, - last_processed_block_number, - state_change_id, - config, - q_scores_uptime_map, - maker_volume_map, - taker_volume_map, - fees_paid_map, - total_maker_volume_map - } - } - /// Convert `ObCheckpointRaw` to `ObCheckpoint`. /// # Returns /// * `ObCheckpoint`: A new `ObCheckpoint` instance. @@ -229,7 +195,7 @@ impl ObCheckpointRaw { maker_volume_map: self.maker_volume_map, taker_volume_map: self.taker_volume_map, fees_paid_map: self.fees_paid_map, - total_maker_volume_map: self.total_maker_volume_map + total_maker_volume_map: self.total_maker_volume_map, } } } diff --git a/primitives/orderbook/src/lmp.rs b/primitives/orderbook/src/lmp.rs index 8dbe18e81..2853581e6 100644 --- a/primitives/orderbook/src/lmp.rs +++ b/primitives/orderbook/src/lmp.rs @@ -29,7 +29,9 @@ use sp_std::collections::btree_map::BTreeMap; use sp_std::vec::Vec; /// LMP Epoch config -#[derive(Decode, Encode, TypeInfo, Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Default)] +#[derive( + Decode, Encode, TypeInfo, Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Default, +)] pub struct LMPConfig { pub epoch: u16, pub index: u16, diff --git a/primitives/orderbook/src/recovery.rs b/primitives/orderbook/src/recovery.rs index 60bd2bcd9..b8aa00041 100644 --- a/primitives/orderbook/src/recovery.rs +++ b/primitives/orderbook/src/recovery.rs @@ -16,16 +16,16 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use crate::lmp::LMPConfig; +use crate::types::TradingPair; use crate::{types::AccountAsset, ObCheckpointRaw}; use parity_scale_codec::{Decode, Encode}; use polkadex_primitives::{AccountId, AssetId, BlockNumber}; use rust_decimal::Decimal; use scale_info::TypeInfo; use serde_with::{json::JsonString, serde_as}; -use std::collections::BTreeMap; use sp_core::crypto::AccountId32; -use crate::lmp::LMPConfig; -use crate::types::TradingPair; +use std::collections::BTreeMap; /// A struct representing the recovery state of an Order Book. #[serde_as]