Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Prev Previous commit
Next Next commit
add event deposit for eventual eviction upon pay_rent
  • Loading branch information
Robbepop committed Jan 20, 2020
commit 8576b0a292dee873a832808468b5d819cfacc156
10 changes: 9 additions & 1 deletion frame/contracts/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,15 @@ where
// Assumption: pay_rent doesn't collide with overlay because
// pay_rent will be done on first call and dest contract and balance
// cannot be changed before the first call
let contract_info = rent::pay_rent::<T>(&dest);
let (rent_outcome, contract_info) = rent::pay_rent::<T>(&dest);

// Deposit an event to indicate contract eviction.
if rent_outcome == rent::RentOutcome::Evicted {
self.deferred.push(DeferredAction::DepositEvent {
event: RawEvent::Evicted(dest.clone()),
topics: Vec::new(),
});
}

// Calls to dead contracts always fail.
if let Some(ContractInfo::Tombstone(_)) = contract_info {
Expand Down
4 changes: 2 additions & 2 deletions frame/contracts/src/rent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ fn try_evict_or_and_pay_rent<T: Trait>(
/// Make account paying the rent for the current block number
///
/// NOTE: This function acts eagerly.
pub fn pay_rent<T: Trait>(account: &T::AccountId) -> Option<ContractInfo<T>> {
try_evict_or_and_pay_rent::<T>(account, Zero::zero(), true).1
pub fn pay_rent<T: Trait>(account: &T::AccountId) -> (RentOutcome, Option<ContractInfo<T>>) {
try_evict_or_and_pay_rent::<T>(account, Zero::zero(), true)
}

/// Evict the account if it should be evicted at the given block number.
Expand Down