@@ -106,7 +106,10 @@ fn execute_block_with_state_root_handler(
106106 // execute transactions
107107 block. extrinsics . iter ( ) . enumerate ( ) . for_each ( |( i, e) | {
108108 storage:: unhashed:: put ( well_known_keys:: EXTRINSIC_INDEX , & ( i as u32 ) ) ;
109- execute_transaction_backend ( e) . unwrap_or_else ( |_| panic ! ( "Invalid transaction" ) ) ;
109+ match execute_transaction_backend ( e) {
110+ ApplyResult :: Success => ( ) ,
111+ _ => panic ! ( "Invalid transaction" ) ,
112+ } ;
110113 storage:: unhashed:: kill ( well_known_keys:: EXTRINSIC_INDEX ) ;
111114 } ) ;
112115
@@ -233,11 +236,13 @@ fn check_signature(utx: &Extrinsic) -> Result<(), ApplyError> {
233236}
234237
235238fn execute_transaction_backend ( utx : & Extrinsic ) -> ApplyResult {
236- check_signature ( utx) ?;
237- match utx {
238- Extrinsic :: Transfer ( ref transfer, _) => execute_transfer_backend ( transfer) ,
239- Extrinsic :: AuthoritiesChange ( ref new_auth) => execute_new_authorities_backend ( new_auth) ,
240- Extrinsic :: IncludeData ( _) => ApplyResult :: Success ,
239+ match check_signature ( utx) {
240+ Ok ( _) => match utx {
241+ Extrinsic :: Transfer ( ref transfer, _) => execute_transfer_backend ( transfer) ,
242+ Extrinsic :: AuthoritiesChange ( ref new_auth) => execute_new_authorities_backend ( new_auth) ,
243+ Extrinsic :: IncludeData ( _) => ApplyResult :: Success ,
244+ } ,
245+ Err ( err) => ApplyResult :: ApplyError ( err)
241246 }
242247}
243248
@@ -246,7 +251,7 @@ fn execute_transfer_backend(tx: &Transfer) -> ApplyResult {
246251 let nonce_key = tx. from . to_keyed_vec ( NONCE_OF ) ;
247252 let expected_nonce: u64 = storage:: hashed:: get_or ( & blake2_256, & nonce_key, 0 ) ;
248253 if !( tx. nonce == expected_nonce) {
249- return Err ( ApplyError :: Stale )
254+ return ApplyResult :: ApplyError ( ApplyError :: Stale )
250255 }
251256
252257 // increment nonce in storage
@@ -258,7 +263,7 @@ fn execute_transfer_backend(tx: &Transfer) -> ApplyResult {
258263
259264 // enact transfer
260265 if !( tx. amount <= from_balance) {
261- return Err ( ApplyError :: CantPay )
266+ return ApplyResult :: ApplyError ( ApplyError :: CantPay )
262267 }
263268 let to_balance_key = tx. to . to_keyed_vec ( BALANCE_OF ) ;
264269 let to_balance: u64 = storage:: hashed:: get_or ( & blake2_256, & to_balance_key, 0 ) ;
0 commit comments