Skip to content

Commit

Permalink
fulfill order
Browse files Browse the repository at this point in the history
  • Loading branch information
cuteolaf committed Jul 10, 2024
1 parent 4b70491 commit af73b15
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pallets/orders/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,9 @@ pub mod pallet {
fn order(order_id: &OrderId) -> Option<Order<T::AccountId>> {
Orders::<T>::get(order_id)
}

fn remove_order(order_id: &OrderId) {
Orders::<T>::remove(order_id)
}
}
}
19 changes: 16 additions & 3 deletions pallets/processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ pub mod pallet {

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {}
pub enum Event<T: Config> {
OrderFulfilled { order_id: OrderId, region_id: RegionId, seller: T::AccountId },
}

#[pallet::error]
#[derive(PartialEq)]
Expand All @@ -84,6 +86,8 @@ pub mod pallet {
RecordUnavailable,
/// Locked regions cannot be listed on sale.
RegionLocked,
/// The caller is not the owner of the region.
NotOwner,
}

#[pallet::call]
Expand All @@ -100,14 +104,23 @@ pub mod pallet {
let region = T::Regions::region(&region_id.into()).ok_or(Error::<T>::UnknownRegion)?;
ensure!(!region.locked, Error::<T>::RegionLocked);

ensure!(region.owner == who, Error::<T>::NotOwner);

let record = region.record.get().ok_or(Error::<T>::RecordUnavailable)?;
let order = T::Orders::order(&order_id).ok_or(Error::<T>::UnknownOrder)?;

Self::ensure_matching_requirements(region_id, record, order.requirements)?;

// TODO: process fulfilling.
// Transfer the region to the order creator
T::Regions::transfer(&region_id.into(), &order.creator)?;
// Transfer the tokens collected by the order to the caller(ie the seller)
// FIXME: Price ???
// T::Currency::transfer(&order.creator, &region.owner)

// remove the order
T::Orders::remove_order(&order_id);

// TODO: event
Self::deposit_event(Event::OrderFulfilled { order_id, region_id, seller: who });

Ok(())
}
Expand Down
3 changes: 3 additions & 0 deletions primitives/order/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ pub trait OrderInspect<AccountId: Clone> {
///
/// If `None` the order was not found.
fn order(order_id: &OrderId) -> Option<Order<AccountId>>;

/// Remove an order with the associated id.
fn remove_order(order_id: &OrderId);
}

0 comments on commit af73b15

Please sign in to comment.