From 8f86f62c29d4810beebb496bd7e05e817b74721a Mon Sep 17 00:00:00 2001 From: Gancho Manev Date: Wed, 17 May 2023 09:44:20 +0300 Subject: [PATCH] chore(lease): take storage migration off --- contracts/lease/Cargo.toml | 2 +- contracts/lease/src/contract/endpoins.rs | 25 +++++++---------------- contracts/lease/src/contract/state/mod.rs | 2 +- contracts/lease/src/lease/alarm.rs | 20 ++---------------- 4 files changed, 11 insertions(+), 38 deletions(-) diff --git a/contracts/lease/Cargo.toml b/contracts/lease/Cargo.toml index 756a39f64..be002ace9 100644 --- a/contracts/lease/Cargo.toml +++ b/contracts/lease/Cargo.toml @@ -16,7 +16,7 @@ test = true [features] default = ["contract-with-bindings"] -contract-with-bindings = ["contract", "migration"] +contract-with-bindings = ["contract"] contract = [] migration = ["timealarms/testing", "dex/migration", "lpp/migration"] testing = [] diff --git a/contracts/lease/src/contract/endpoins.rs b/contracts/lease/src/contract/endpoins.rs index b80ac455d..1ff382765 100644 --- a/contracts/lease/src/contract/endpoins.rs +++ b/contracts/lease/src/contract/endpoins.rs @@ -17,9 +17,9 @@ use crate::{ error::{ContractError, ContractResult}, }; -use super::state::{self, Migrate, Response, State}; +use super::state::{self, Response, State}; -const CONTRACT_STORAGE_VERSION_FROM: VersionSegment = 2; +// const CONTRACT_STORAGE_VERSION_FROM: VersionSegment = 2; const CONTRACT_STORAGE_VERSION: VersionSegment = 3; #[cfg_attr(feature = "contract-with-bindings", entry_point)] @@ -46,22 +46,11 @@ pub fn instantiate( } #[cfg_attr(feature = "contract-with-bindings", entry_point)] -pub fn migrate(deps: DepsMut<'_>, env: Env, _msg: MigrateMsg) -> ContractResult { - versioning::update_software_and_storage::( - deps.storage, - version!(CONTRACT_STORAGE_VERSION), - |storage: &mut _| { - state::load_v2(storage) - .and_then(|lease_v2| lease_v2.into_last_version(env.block.time)) - .and_then( - |Response { - response, - next_state: lease_v3, - }| state::save(storage, &lease_v3).map(|()| response), - ) - }, - ) - .and_then(|(release_label, resp)| response::response_with_messages(release_label, resp)) +pub fn migrate(deps: DepsMut<'_>, _env: Env, _msg: MigrateMsg) -> ContractResult { + #[cfg(feature = "migration")] + state::load_v2(deps.storage)?; + versioning::update_software(deps.storage, version!(CONTRACT_STORAGE_VERSION)) + .and_then(response::response) } #[cfg_attr(feature = "contract-with-bindings", entry_point)] diff --git a/contracts/lease/src/contract/state/mod.rs b/contracts/lease/src/contract/state/mod.rs index df35d9f05..25d574dc0 100644 --- a/contracts/lease/src/contract/state/mod.rs +++ b/contracts/lease/src/contract/state/mod.rs @@ -16,7 +16,7 @@ use crate::{ pub(crate) use self::handler::{Handler, Response}; #[cfg(feature = "migration")] -pub(in crate::contract) use self::v2::{Migrate, StateV2}; +pub(in crate::contract) use self::v2::StateV2; use self::{dex::State as DexState, lease::State as LeaseState}; mod closed; diff --git a/contracts/lease/src/lease/alarm.rs b/contracts/lease/src/lease/alarm.rs index ef605adee..f04c3129c 100644 --- a/contracts/lease/src/lease/alarm.rs +++ b/contracts/lease/src/lease/alarm.rs @@ -26,8 +26,6 @@ where Oracle: OracleTrait, Asset: Currency + Serialize, { - //TODO keep loan state updated on payments and liquidations to have the liquidation status accurate - //do it at the LppStub pub(crate) fn reschedule( &self, now: &Timestamp, @@ -37,26 +35,12 @@ where ) -> ContractResult { let mut time_alarms = time_alarms.as_stub(); let mut price_alarms = price_alarms.as_alarms_stub::(); - self.reschedule_typed(now, liquidation_zone, &mut time_alarms, &mut price_alarms)?; + self.reschedule_time_alarm(now, &mut time_alarms) + .and_then(|()| self.reschedule_price_alarm(now, liquidation_zone, &mut price_alarms))?; Ok(Batch::from(time_alarms).merge(price_alarms.into())) } - fn reschedule_typed( - &self, - now: &Timestamp, - liquidation_zone: &Zone, - time_alarms: &mut TimeAlarms, - price_alarms: &mut PriceAlarms, - ) -> ContractResult<()> - where - TimeAlarms: TimeAlarmsTrait, - PriceAlarms: PriceAlarmsTrait, - { - self.reschedule_time_alarm(now, time_alarms) - .and_then(|()| self.reschedule_price_alarm(now, liquidation_zone, price_alarms)) - } - fn reschedule_time_alarm( &self, now: &Timestamp,