Skip to content

Commit

Permalink
emit reward in OrderProcessed (#247)
Browse files Browse the repository at this point in the history
* emit reward in OrderProcessed

* inc spec version

* cargo fmt

* Update runtime/cocos/src/lib.rs

---------

Co-authored-by: Sergej Sakac <[email protected]>
  • Loading branch information
cuteolaf and Szegoo authored Aug 15, 2024
1 parent 8b5d77e commit d51efff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
17 changes: 15 additions & 2 deletions pallets/processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ pub use weights::WeightInfo;

const LOG_TARGET: &str = "runtime::order-creator";

pub type BalanceOf<T> =
<<T as crate::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;

pub type RegionRecordOf<T> =
RegionRecord<<T as frame_system::Config>::AccountId, <T as crate::Config>::Balance>;

Expand Down Expand Up @@ -118,7 +121,12 @@ pub mod pallet {
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Order got fulfilled with a region which is matching the requirements.
OrderProcessed { order_id: OrderId, region_id: RegionId, seller: T::AccountId },
OrderProcessed {
order_id: OrderId,
region_id: RegionId,
seller: T::AccountId,
reward: BalanceOf<T>,
},
/// Region got successfully assigned to a parachain.
RegionAssigned { region_id: RegionId, para_id: ParaId },
/// Region assignment failed.
Expand Down Expand Up @@ -204,7 +212,12 @@ pub mod pallet {
// remove the order
T::Orders::remove_order(&order_id);

Self::deposit_event(Event::OrderProcessed { order_id, region_id, seller: who });
Self::deposit_event(Event::OrderProcessed {
order_id,
region_id,
seller: who,
reward: amount,
});

// NOTE: If the assignment fails, we don't return an error; instead, we return ok and
// allow anyone to attempt to assign the region.
Expand Down
10 changes: 9 additions & 1 deletion pallets/processor/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,19 @@ fn fulfill_order_works() {
// Works with a region that meets the requirements and is unlocked:

Regions::unlock(&region_id.into(), None).unwrap();

assert_eq!(Balances::free_balance(region_owner), 0);
assert_ok!(Processor::fulfill_order(RuntimeOrigin::signed(region_owner), 0, region_id));
// Check events
System::assert_has_event(Event::RegionAssigned { region_id, para_id: 2000.into() }.into());
System::assert_has_event(
Event::OrderProcessed { order_id: 0, region_id, seller: region_owner }.into(),
Event::OrderProcessed {
order_id: 0,
region_id,
seller: region_owner,
reward: 1500u32.into(),
}
.into(),
);

// Ensure order is removed:
Expand Down

0 comments on commit d51efff

Please sign in to comment.