Skip to content

Commit

Permalink
added field created_at and updated_at in Request Struct
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulhakim2902 authored and irmannmal committed Nov 17, 2021
1 parent 77d4f7e commit 17d200f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pallets/service-request/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ pub struct Request<AccountId, Balance, Hash> {
pub service_category: Vec<u8>,
pub staking_amount: Balance,
pub status: RequestStatus,
pub created_at: u128,
pub updated_at: Option<u128>,
pub unstaked_at: Option<u128>,
}
impl<AccountId, Balance, Hash> Request<AccountId, Balance, Hash> {
Expand All @@ -63,6 +65,7 @@ impl<AccountId, Balance, Hash> Request<AccountId, Balance, Hash> {
city: Vec<u8>,
service_category: Vec<u8>,
staking_amount: Balance,
created_at: u128,
) -> Self {
Self {
hash,
Expand All @@ -74,6 +77,8 @@ impl<AccountId, Balance, Hash> Request<AccountId, Balance, Hash> {
service_category,
staking_amount,
status: RequestStatus::default(),
created_at,
updated_at: None,
unstaked_at: None,
}
}
Expand Down Expand Up @@ -489,6 +494,8 @@ impl<T: Config> SeviceRequestInterface<T> for Pallet<T> {
service_category.clone(),
);

let now = T::TimeProvider::now().as_millis();

match CurrencyOf::<T>::withdraw(
&requester_id,
staking_amount.clone(),
Expand All @@ -506,6 +513,7 @@ impl<T: Config> SeviceRequestInterface<T> for Pallet<T> {
city.clone(),
service_category.clone(),
staking_amount.clone(),
now,
);

RequestById::<T>::insert(request_id.clone(), request.clone());
Expand Down Expand Up @@ -646,9 +654,12 @@ impl<T: Config> SeviceRequestInterface<T> for Pallet<T> {
qc_price,
);

let now = T::TimeProvider::now().as_millis();

if lab_status.is_verified() {
request.status = RequestStatus::Claimed;
request.lab_address = Some(lab_id);
request.updated_at = Some(now);

RequestById::<T>::insert(request_id, request.clone());
ServiceOfferById::<T>::insert(request_id, service_offer.clone());
Expand Down Expand Up @@ -777,10 +788,13 @@ impl<T: Config> SeviceRequestInterface<T> for Pallet<T> {
final_pay_amount.clone(),
);

let now = T::TimeProvider::now().as_millis();

ServiceInvoiceById::<T>::insert(request_id.clone(), service_invoice.clone());
ServiceInvoiceByOrderId::<T>::insert(order_id.clone(), service_invoice.clone());

request.status = RequestStatus::Processed;
request.updated_at = Some(now);
RequestById::<T>::insert(request_id.clone(), request);

Ok(service_invoice.clone())
Expand Down Expand Up @@ -864,7 +878,10 @@ impl<T: Config> SeviceRequestInterface<T> for Pallet<T> {
},
}

let now = T::TimeProvider::now().as_millis();

request.status = RequestStatus::Finalized;
request.updated_at = Some(now);
RequestById::<T>::insert(request_id.clone(), request.clone());

Ok(service_invoice.clone())
Expand Down

0 comments on commit 17d200f

Please sign in to comment.