If invoking a contract aborts and reverts the function, does all the changes to state revert directly?

I know it is this way for contracts on other chains but just to make sure that it is the same for concordium.


#[receive(contract = "factory", name = "collection_create", parameter = "ContractAddress", mutable)]
fn collection_create<S: HasStateApi>(
    ctx: &impl HasReceiveContext,
    host: &mut impl HasHost<State<S>, StateApiType = S>,
) -> ReceiveResult<()> {
    let owner = host.state().owner;
    let sender = ctx.sender();
    ensure!(sender.matches_account(&owner));
    let contract_address = ctx.parameter_cursor().get()?;
    let result = host.state_mut().collections.insert(contract_address);
    ensure!(result);
    let _result = host.invoke_contract(&contract_address, &{}, EntrypointName::new("initialize")?, Amount::zero()).unwrap_abort();
    Ok(())
}

So if result returns an error it should revert all changes am I right?

Yes, all changes to the called contract (and any nested calls) are reverted.

1 Like