@@ -78,7 +78,7 @@ use rstd::prelude::*;
7878use  rstd:: marker:: PhantomData ; 
7979use  rstd:: convert:: TryInto ; 
8080use  primitives:: { 
81- 	generic:: Digest ,  ApplyResult ,  ApplyError ,  DispatchError ,  Error  as  PrimitiveError , 
81+ 	generic:: Digest ,  ApplyResult ,  ApplyOutcome ,   ApplyError ,  DispatchError ,  Error  as  PrimitiveError , 
8282	traits:: { 
8383		self ,  Header ,  Zero ,  One ,  Checkable ,  Applyable ,  CheckEqual ,  OnFinalize , 
8484		OnInitialize ,  NumberFor ,  Block  as  BlockT ,  OffchainWorker , 
@@ -231,8 +231,8 @@ where
231231 	fn  apply_extrinsic_no_note ( uxt :  Block :: Extrinsic )  { 
232232		let  l = uxt. encode ( ) . len ( ) ; 
233233		match  Self :: apply_extrinsic_with_len ( uxt,  l,  None )  { 
234- 			ApplyResult :: Success  => ( ) , 
235- 			ApplyResult :: DispatchError ( e )  => { 
234+ 			Ok ( ApplyOutcome :: Success )  => ( ) , 
235+ 			Ok ( ApplyOutcome :: Fail ( e ) )  => { 
236236				runtime_io:: print ( "Error:" ) ; 
237237				// as u8 first to ensure not using sign-extend 
238238				runtime_io:: print ( e. module  as  u8  as  u64 ) ; 
@@ -241,10 +241,10 @@ where
241241					runtime_io:: print ( msg) ; 
242242				} 
243243			} , 
244- 			ApplyResult :: ApplyError ( ApplyError :: CantPay )  => panic ! ( "All extrinsics should have sender able to pay their fees" ) , 
245- 			ApplyResult :: ApplyError ( ApplyError :: BadSignature )  => panic ! ( "All extrinsics should be properly signed" ) , 
246- 			ApplyResult :: ApplyError ( ApplyError :: Stale )  | ApplyResult :: ApplyError ( ApplyError :: Future )  => panic ! ( "All extrinsics should have the correct nonce" ) , 
247- 			ApplyResult :: ApplyError ( ApplyError :: FullBlock )  => panic ! ( "Extrinsics should not exceed block limit" ) , 
244+ 			Err ( ApplyError :: CantPay )  => panic ! ( "All extrinsics should have sender able to pay their fees" ) , 
245+ 			Err ( ApplyError :: BadSignature )  => panic ! ( "All extrinsics should be properly signed" ) , 
246+ 			Err ( ApplyError :: Stale )  | Err ( ApplyError :: Future )  => panic ! ( "All extrinsics should have the correct nonce" ) , 
247+ 			Err ( ApplyError :: FullBlock )  => panic ! ( "Extrinsics should not exceed block limit" ) , 
248248		} 
249249	} 
250250
@@ -255,56 +255,49 @@ where
255255		to_note :  Option < Vec < u8 > > , 
256256	)  -> ApplyResult  { 
257257		// Verify that the signature is good. 
258- 		match  uxt. check ( & Default :: default ( ) )  { 
259- 			Err ( _)  => ApplyResult :: ApplyError ( ApplyError :: BadSignature ) , 
260- 			Ok ( xt)  => { 
261- 				// Check the weight of the block if that extrinsic is applied. 
262- 				let  weight = xt. weight ( encoded_len) ; 
263- 				if  <system:: Module < System > >:: all_extrinsics_weight ( )  + weight > internal:: MAX_TRANSACTIONS_WEIGHT  { 
264- 					return  ApplyResult :: ApplyError ( ApplyError :: FullBlock ) ; 
265- 				} 
258+ 		let  xt = uxt. check ( & Default :: default ( ) ) . map_err ( |_| ApplyError :: BadSignature ) ?; 
259+ 		// Check the weight of the block if that extrinsic is applied. 
260+ 		let  weight = xt. weight ( encoded_len) ; 
261+ 		if  <system:: Module < System > >:: all_extrinsics_weight ( )  + weight > internal:: MAX_TRANSACTIONS_WEIGHT  { 
262+ 			return  Err ( ApplyError :: FullBlock ) ; 
263+ 		} 
266264
267- 				if  let  ( Some ( sender) ,  Some ( index) )  = ( xt. sender ( ) ,  xt. index ( ) )  { 
268- 					// check index 
269- 					let  expected_index = <system:: Module < System > >:: account_nonce ( sender) ; 
270- 					if  index != & expected_index { 
271- 						return  if  index < & expected_index { 
272- 							ApplyResult :: ApplyError ( ApplyError :: Stale ) 
273- 						}  else  { 
274- 							ApplyResult :: ApplyError ( ApplyError :: Future ) 
275- 						} 
276- 					} 
277- 					// pay any fees 
278- 					// TODO: propagate why can't pay 
279- 					match  Payment :: make_payment ( sender,  encoded_len)  { 
280- 						Err ( _)  => return  ApplyResult :: ApplyError ( ApplyError :: CantPay ) , 
281- 						Ok ( _)  => ( ) 
282- 					} ; 
283- 
284- 					// AUDIT: Under no circumstances may this function panic from here onwards. 
285- 					// FIXME: ensure this at compile-time (such as by not defining a panic function, forcing 
286- 					// a linker error unless the compiler can prove it cannot be called). 
287- 					// increment nonce in storage 
288- 					<system:: Module < System > >:: inc_account_nonce ( sender) ; 
265+ 		if  let  ( Some ( sender) ,  Some ( index) )  = ( xt. sender ( ) ,  xt. index ( ) )  { 
266+ 			// check index 
267+ 			let  expected_index = <system:: Module < System > >:: account_nonce ( sender) ; 
268+ 			if  index != & expected_index { 
269+ 				return  if  index < & expected_index { 
270+ 					Err ( ApplyError :: Stale ) 
271+ 				}  else  { 
272+ 					Err ( ApplyError :: Future ) 
289273				} 
274+ 			} 
275+ 			// pay any fees 
276+ 			// TODO: propagate why can't pay 
277+ 			Payment :: make_payment ( sender,  encoded_len) . map_err ( |_| ApplyError :: CantPay ) ?; 
278+ 
279+ 			// AUDIT: Under no circumstances may this function panic from here onwards. 
280+ 			// FIXME: ensure this at compile-time (such as by not defining a panic function, forcing 
281+ 			// a linker error unless the compiler can prove it cannot be called). 
282+ 			// increment nonce in storage 
283+ 			<system:: Module < System > >:: inc_account_nonce ( sender) ; 
284+ 		} 
290285
291- 				 // Make sure to `note_extrinsic` only after we know it's going to be executed 
292- 				 // to prevent it from leaking in storage. 
293- 				 if  let  Some ( encoded)  = to_note { 
294- 					 <system:: Module < System > >:: note_extrinsic ( encoded) ; 
295- 				 } 
286+ 		// Make sure to `note_extrinsic` only after we know it's going to be executed 
287+ 		// to prevent it from leaking in storage. 
288+ 		if  let  Some ( encoded)  = to_note { 
289+ 			<system:: Module < System > >:: note_extrinsic ( encoded) ; 
290+ 		} 
296291
297- 				 // Decode parameters and dispatch 
298- 				 let  ( f,  s)  = xt. deconstruct ( ) ; 
299- 				 let  r = f. dispatch ( s. into ( ) ) . map_err ( Into :: < DispatchError > :: into) ; 
300- 				 <system:: Module < System > >:: note_applied_extrinsic ( & r,  encoded_len as  u32 ) ; 
292+ 		// Decode parameters and dispatch 
293+ 		let  ( f,  s)  = xt. deconstruct ( ) ; 
294+ 		let  r = f. dispatch ( s. into ( ) ) . map_err ( Into :: < DispatchError > :: into) ; 
295+ 		<system:: Module < System > >:: note_applied_extrinsic ( & r,  encoded_len as  u32 ) ; 
301296
302- 				match  r { 
303- 					Ok ( _)  => ApplyResult :: Success , 
304- 					Err ( e)  => ApplyResult :: DispatchError ( e) , 
305- 				} 
306- 			} 
307- 		} 
297+ 		Ok ( match  r { 
298+ 			Ok ( _)  => ApplyOutcome :: Success , 
299+ 			Err ( e)  => ApplyOutcome :: Fail ( e) , 
300+ 		} ) 
308301	} 
309302
310303	fn  final_checks ( header :  & System :: Header )  { 
0 commit comments