diff --git a/packages/std/src/ado_contract/execute.rs b/packages/std/src/ado_contract/execute.rs index 8fe1962a6..efbded8ae 100644 --- a/packages/std/src/ado_contract/execute.rs +++ b/packages/std/src/ado_contract/execute.rs @@ -165,27 +165,24 @@ impl<'a> ADOContract<'a> { /// Handles receiving and verifies an AMPPkt from the Kernel before executing the appropriate messages. /// /// Calls the provided handler with the AMP packet attached within the context. - pub fn execute_amp_receive>( + pub fn execute_amp_receive( &self, ctx: ExecuteContext, mut packet: AMPPkt, - handler: ExecuteContextFunction, + handler: ExecuteContextFunction, ) -> Result { packet.verify_origin(&ctx.info, &ctx.deps.as_ref())?; let ctx = ctx.with_ctx(packet.clone()); - let msg_opt = packet.messages.pop(); - if let Some(msg_opt) = msg_opt { - let msg: M = from_binary(&msg_opt.message)?; - let response = handler(ctx, msg); - match response { - Err(e) => Err(e.into()), - Ok(response) => Ok(response), + ensure!( + packet.messages.len() == 1, + ContractError::InvalidPacket { + error: Some("Invalid packet length".to_string()) } - } else { - Err(ContractError::InvalidPacket { - error: Some("AMP Packet received with no messages".to_string()), - }) - } + ); + let msg = packet.messages.pop().unwrap(); + let msg: M = from_binary(&msg.message)?; + let response = handler(ctx, msg)?; + Ok(response) } /// Generates a message to pay a fee for a given action by the given payee