Skip to content

Commit

Permalink
chore(lease): take storage migration off
Browse files Browse the repository at this point in the history
  • Loading branch information
Gancho Manev committed May 23, 2023
1 parent 75220f0 commit 8f86f62
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 38 deletions.
2 changes: 1 addition & 1 deletion contracts/lease/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
25 changes: 7 additions & 18 deletions contracts/lease/src/contract/endpoins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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<CwResponse> {
versioning::update_software_and_storage::<CONTRACT_STORAGE_VERSION_FROM, _, _, _>(
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<CwResponse> {
#[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)]
Expand Down
2 changes: 1 addition & 1 deletion contracts/lease/src/contract/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 2 additions & 18 deletions contracts/lease/src/lease/alarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ where
Oracle: OracleTrait<Lpn>,
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,
Expand All @@ -37,26 +35,12 @@ where
) -> ContractResult<Batch> {
let mut time_alarms = time_alarms.as_stub();
let mut price_alarms = price_alarms.as_alarms_stub::<Lpn>();
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<TimeAlarms, PriceAlarms>(
&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<TimeAlarms>(
&self,
now: &Timestamp,
Expand Down

0 comments on commit 8f86f62

Please sign in to comment.