@@ -99,18 +99,12 @@ decl_module! {
9999 pub fn cancel_order( origin, pair_index: TradingPairIndex , order_index: OrderIndex ) -> Result {
100100 let who = ensure_signed( origin) ?;
101101
102- let pair = Self :: trading_pair( & pair_index) ?;
103- ensure!( pair. online, "Can't cancel order if the trading pair is already offline" ) ;
104-
105- let order_status = match Self :: order_info_of( & ( who. clone( ) , order_index) ) {
106- Some ( x) => x. status,
107- None => return Err ( "The order doesn't exist" ) ,
108- } ;
109- ensure!(
110- order_status == OrderStatus :: ZeroExecuted || order_status == OrderStatus :: ParitialExecuted ,
111- "Only ZeroExecuted and ParitialExecuted order can be canceled"
112- ) ;
102+ Self :: check_cancel_order( & who, pair_index, order_index) ?;
103+ Self :: apply_cancel_order( & who, pair_index, order_index)
104+ }
113105
106+ fn set_cancel_order( who: T :: AccountId , pair_index: TradingPairIndex , order_index: OrderIndex ) -> Result {
107+ Self :: check_cancel_order( & who, pair_index, order_index) ?;
114108 Self :: apply_cancel_order( & who, pair_index, order_index)
115109 }
116110
@@ -343,6 +337,22 @@ impl<T: Trait> Module<T> {
343337 Ok ( ( ) )
344338 }
345339
340+ fn check_cancel_order ( who : & T :: AccountId , pair_index : TradingPairIndex , order_index : OrderIndex ) -> Result {
341+ let pair = Self :: trading_pair ( & pair_index) ?;
342+ ensure ! ( pair. online, "Can't cancel order if the trading pair is already offline" ) ;
343+
344+ let order_status = match Self :: order_info_of ( & ( who. clone ( ) , order_index) ) {
345+ Some ( x) => x. status ,
346+ None => return Err ( "The order doesn't exist" ) ,
347+ } ;
348+ ensure ! (
349+ order_status == OrderStatus :: ZeroExecuted || order_status == OrderStatus :: ParitialExecuted ,
350+ "Only ZeroExecuted and ParitialExecuted order can be canceled"
351+ ) ;
352+
353+ Ok ( ( ) )
354+ }
355+
346356 fn apply_cancel_order (
347357 who : & T :: AccountId ,
348358 pair_index : TradingPairIndex ,
0 commit comments