Attribute Macro frame_support::require_transactional

source ·
#[require_transactional]
Expand description

Assert the annotated function is executed within a storage transaction.

The assertion is enabled for native execution and when debug_assertions are enabled.

§Example


#[require_transactional]
fn update_all(value: u32) -> DispatchResult {
	// Update multiple storages.
	// Return `Err` to indicate should revert.
	Ok(())
}

#[transactional]
fn safe_update(value: u32) -> DispatchResult {
	// This is safe
	update_all(value)
}

fn unsafe_update(value: u32) -> DispatchResult {
	// this may panic if unsafe_update is not called within a storage transaction
	update_all(value)
}

Documentation for this macro can be found at frame_support::require_transactional.