Function holochain::core::workflow::call_zome_workflow::call_zome_function_authorized
source · pub async fn call_zome_function_authorized<R>(
ribosome: R,
host_access: ZomeCallHostAccess,
invocation: ZomeCallInvocation
) -> WorkflowResult<(R, RibosomeResult<ZomeCallResponse>)>where
R: RibosomeT + 'static,
Expand description
First check if we are authorized to call the zome function. Then send to a background thread and call the zome function.
Examples found in repository?
src/test_utils/host_fn_caller.rs (line 442)
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
pub async fn call_zome_direct(&self, invocation: ZomeCallInvocation) -> ExternIO {
let (ribosome, call_context, workspace_lock) = self.unpack().await;
let (_, output) = {
let host_access = call_context.host_context();
let zcha = unwrap_to!(host_access => HostContext::ZomeCall).clone();
call_zome_function_authorized((*ribosome).clone(), zcha, invocation)
.await
.unwrap()
};
// Write
workspace_lock.flush(&self.network).await.unwrap();
unwrap_to!(output.unwrap() => ZomeCallResponse::Ok).to_owned()
}
More examples
src/core/workflow/call_zome_workflow.rs (line 161)
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
async fn call_zome_workflow_inner<Ribosome>(
workspace: SourceChainWorkspace,
network: HolochainP2pDna,
keystore: MetaLairClient,
args: CallZomeWorkflowArgs<Ribosome>,
) -> WorkflowResult<ZomeCallResult>
where
Ribosome: RibosomeT + 'static,
{
let CallZomeWorkflowArgs {
ribosome,
invocation,
signal_tx,
conductor_handle,
cell_id,
..
} = args;
let call_zome_handle =
CellConductorApi::new(conductor_handle.clone(), cell_id).into_call_zome_handle();
tracing::trace!("Before zome call");
let host_access = ZomeCallHostAccess::new(
workspace.clone().into(),
keystore,
network.clone(),
signal_tx,
call_zome_handle,
);
let (ribosome, result) =
call_zome_function_authorized(ribosome, host_access, invocation).await?;
tracing::trace!("After zome call");
let validation_result =
inline_validation(workspace.clone(), network, conductor_handle, ribosome).await;
if matches!(
validation_result,
Err(WorkflowError::SourceChainError(
SourceChainError::InvalidCommit(_)
))
) {
let scratch_records = workspace.source_chain().scratch_records()?;
if scratch_records.len() == 1 {
let lock = holochain_state::source_chain::lock_for_entry(
scratch_records[0].entry().as_option(),
)?;
if !lock.is_empty()
&& workspace
.source_chain()
.is_chain_locked(Vec::with_capacity(0))
.await?
&& !workspace.source_chain().is_chain_locked(lock).await?
{
if let Err(error) = workspace.source_chain().unlock_chain().await {
tracing::error!(?error);
}
}
}
}
validation_result?;
Ok(result)
}