From f42f66cde5a397313ce91f91def038be7e657071 Mon Sep 17 00:00:00 2001 From: Thomas Dinsdale-Young Date: Wed, 6 Mar 2024 14:56:27 +0100 Subject: [PATCH] Revise to follow check-effect-interact pattern. --- examples/factory/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/factory/src/lib.rs b/examples/factory/src/lib.rs index 80230620..2573f770 100644 --- a/examples/factory/src/lib.rs +++ b/examples/factory/src/lib.rs @@ -265,9 +265,13 @@ pub mod factory { let product_name = host.contract_name(product_address).or(Err(FactoryError::NonExistentProduct))?; ensure_eq!(product_name, PRODUCT_INIT_NAME, FactoryError::InvalidProduct); + // Update the state + let state = host.state_mut(); + let next_product = state.next_product; + state.next_product = next_product + 1; + state.products.insert(next_product, product_address); // Invoke the initialize entrypoint on the product passing in the index for this // product. - let next_product = host.state().next_product; host.invoke_contract( &product_address, &next_product, @@ -275,10 +279,6 @@ pub mod factory { Amount::zero(), ) .or(Err(FactoryError::InitializeFailed))?; - // Update the state - let state = host.state_mut(); - state.next_product = next_product + 1; - state.products.insert(next_product, product_address); Ok(()) }