Skip to content

Commit

Permalink
add APR and RPR helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
Aenyi committed Jan 22, 2025
1 parent 1bdb817 commit f110386
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
28 changes: 28 additions & 0 deletions substrate/frame/broker/src/dispatchable_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,34 @@ impl<T: Config> Pallet<T> {
Ok(core)
}

pub(crate) fn do_add_potential_renewal(core: CoreIndex) -> Result<(), Error<T>> {
let now = RCBlockNumberProviderOf::<T::Coretime>::current_block_number();
let sale = SaleInfo::<T>::get().ok_or(Error::<T>::NoSales)?;
let renewal_id = PotentialRenewalId { core, when: sale.region_begin };
// Check if a record already exists
if PotentialRenewals::<T>::contains_key(renewal_id) {
return Err(Error::<T>::NotAllowed);
}
price = Self::sale_price(&sale, now);
let workload = Workload::<T>::get(core);
log::debug!(
"Create PotentialRenewalRecord for workload {:?}",
workload
);
let new_record = PotentialRenewalRecord { price, completion: Complete(workload) }
PotentialRenewals::<T>::insert(PotentialRenewalId { core, when: begin }, &new_record);
}

pub(crate) fn do_remove_potential_renewal(core: CoreIndex) -> Result<(), Error<T>> {
let sale = SaleInfo::<T>::get().ok_or(Error::<T>::NoSales)?;
let renewal_id = PotentialRenewalId { core, when: sale.region_begin };
let current_record = PotentialRenewals::<T>::get(renewal_id);

if let Some(_) = current_record {
PotentialRenewals::<T>::remove(renewal_id);
}
}

pub(crate) fn do_transfer(
region_id: RegionId,
maybe_check_owner: Option<T::AccountId>,
Expand Down
15 changes: 15 additions & 0 deletions substrate/frame/broker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,5 +976,20 @@ pub mod pallet {
Self::do_swap_leases(id, other)?;
Ok(())
}

/*
#[pallet::call_index(60)]
pub fn potential_renewal(origin: OriginFor<T>, core: CoreIndex, renew: bool) -> DispatchResult {
let who = T::AdminOrigin::ensure_origin_or_root(origin)?;
if renew {
Self::do_renew(who, core)?;
} else {
let renewal_id = PotentialRenewalId { core, when: sale.region_begin };
PotentialRenewals::<T>::remove(renewal_id);
}
Ok(Pays::Yes.into())
}
*/
}
}

0 comments on commit f110386

Please sign in to comment.