Skip to content

Commit

Permalink
Merge pull request #410 from Concordium/factory-pattern
Browse files Browse the repository at this point in the history
Revise factory example to follow check-effect-interact pattern.
  • Loading branch information
td202 authored Mar 7, 2024
2 parents 4acf34e + f42f66c commit e3e75e3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions examples/factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,20 +265,20 @@ 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,
EntrypointName::new_unchecked(PRODUCT_INITIALIZE_ENTRYPOINT),
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(())
}

Expand Down

0 comments on commit e3e75e3

Please sign in to comment.