Struct holochain::conductor::api::CellConductorApi
source · pub struct CellConductorApi { /* private fields */ }
Expand description
The concrete implementation of CellConductorApiT
, which is used to give
Cells an API for calling back to their Conductor
.
Implementations§
source§impl CellConductorApi
impl CellConductorApi
sourcepub fn new(conductor_handle: ConductorHandle, cell_id: CellId) -> Self
pub fn new(conductor_handle: ConductorHandle, cell_id: CellId) -> Self
Instantiate from a Conductor reference and a CellId to identify which Cell this API instance is associated with
Examples found in repository?
src/test_utils/conductor_setup.rs (line 62)
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
pub async fn new(
cell_id: &CellId,
handle: &ConductorHandle,
dna_file: &DnaFile,
chc: Option<ChcImpl>,
) -> Self {
let authored_db = handle.get_authored_db(cell_id.dna_hash()).unwrap();
let dht_db = handle.get_dht_db(cell_id.dna_hash()).unwrap();
let dht_db_cache = handle.get_dht_db_cache(cell_id.dna_hash()).unwrap();
let cache = handle.get_cache_db(cell_id).unwrap();
let keystore = handle.keystore().clone();
let network = handle
.holochain_p2p()
.to_dna(cell_id.dna_hash().clone(), chc);
let triggers = handle.get_cell_triggers(cell_id).unwrap();
let cell_conductor_api = CellConductorApi::new(handle.clone(), cell_id.clone());
let ribosome = handle.get_ribosome(dna_file.dna_hash()).unwrap();
let signal_tx = handle.signal_broadcaster();
CellHostFnCaller {
cell_id: cell_id.clone(),
authored_db,
dht_db,
dht_db_cache,
cache,
ribosome,
network,
keystore,
signal_tx,
triggers,
cell_conductor_api,
}
}
More examples
src/test_utils/host_fn_caller.rs (line 142)
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 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
pub async fn create_for_zome(
cell_id: &CellId,
handle: &ConductorHandle,
dna_file: &DnaFile,
zome_index: usize,
) -> HostFnCaller {
let authored_db = handle.get_authored_db(cell_id.dna_hash()).unwrap();
let dht_db = handle.get_dht_db(cell_id.dna_hash()).unwrap();
let dht_db_cache = handle.get_dht_db_cache(cell_id.dna_hash()).unwrap();
let cache = handle.get_cache_db(cell_id).unwrap();
let keystore = handle.keystore().clone();
let network = handle
.holochain_p2p()
.to_dna(cell_id.dna_hash().clone(), None);
let zome_path = (
cell_id.clone(),
dna_file
.dna()
.integrity_zomes
.get(zome_index)
.unwrap()
.0
.clone(),
)
.into();
let ribosome = handle.get_ribosome(dna_file.dna_hash()).unwrap();
let signal_tx = handle.signal_broadcaster();
let call_zome_handle =
CellConductorApi::new(handle.clone(), cell_id.clone()).into_call_zome_handle();
HostFnCaller {
authored_db,
dht_db,
dht_db_cache,
cache,
ribosome,
zome_path,
network,
keystore,
signal_tx,
call_zome_handle,
}
}
src/core/workflow/initialize_zomes_workflow.rs (line 93)
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
async fn initialize_zomes_workflow_inner<Ribosome>(
workspace: SourceChainWorkspace,
network: HolochainP2pDna,
keystore: MetaLairClient,
args: InitializeZomesWorkflowArgs<Ribosome>,
) -> WorkflowResult<InitResult>
where
Ribosome: RibosomeT + 'static,
{
let dna_def = args.dna_def().clone();
let InitializeZomesWorkflowArgs {
ribosome,
conductor_handle,
signal_tx,
cell_id,
} = args;
let call_zome_handle =
CellConductorApi::new(conductor_handle.clone(), cell_id.clone()).into_call_zome_handle();
// Call the init callback
let result = {
let host_access = InitHostAccess::new(
workspace.clone().into(),
keystore,
network.clone(),
signal_tx,
call_zome_handle,
);
let invocation = InitInvocation { dna_def };
ribosome.run_init(host_access, invocation)?
};
// Insert the init marker
// FIXME: For some reason if we don't spawn here
// this future never gets polled again.
let ws = workspace.clone();
tokio::task::spawn(async move {
ws.source_chain()
.put(
builder::InitZomesComplete {},
None,
ChainTopOrdering::Strict,
)
.await
})
.await??;
// TODO: Validate scratch items
super::inline_validation(workspace, network, conductor_handle, ribosome).await?;
Ok(result)
}
src/conductor/cell.rs (line 124)
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
pub async fn create(
id: CellId,
conductor_handle: ConductorHandle,
space: Space,
holochain_p2p_cell: holochain_p2p::HolochainP2pDna,
managed_task_add_sender: sync::mpsc::Sender<ManagedTaskAdd>,
managed_task_stop_broadcaster: sync::broadcast::Sender<()>,
) -> CellResult<(Self, InitialQueueTriggers)> {
let conductor_api = Arc::new(CellConductorApi::new(conductor_handle.clone(), id.clone()));
// check if genesis has been run
let has_genesis = {
// check if genesis ran.
GenesisWorkspace::new(space.authored_db.clone(), space.dht_db.clone())?
.has_genesis(id.agent_pubkey().clone())
.await?
};
if has_genesis {
let (queue_triggers, initial_queue_triggers) = spawn_queue_consumer_tasks(
id.clone(),
holochain_p2p_cell.clone(),
&space,
conductor_handle.clone(),
managed_task_add_sender,
managed_task_stop_broadcaster,
)
.await;
Ok((
Self {
id,
conductor_api,
conductor_handle,
space,
holochain_p2p_cell,
queue_triggers,
init_mutex: Default::default(),
},
initial_queue_triggers,
))
} else {
Err(CellError::CellWithoutGenesis(id))
}
}
/// Performs the Genesis workflow for the Cell, ensuring that its initial
/// records are committed. This is a prerequisite for any other interaction
/// with the SourceChain
#[allow(clippy::too_many_arguments)]
pub async fn genesis<Ribosome>(
id: CellId,
conductor_handle: ConductorHandle,
authored_db: DbWrite<DbKindAuthored>,
dht_db: DbWrite<DbKindDht>,
dht_db_cache: DhtDbQueryCache,
ribosome: Ribosome,
membrane_proof: Option<MembraneProof>,
chc: Option<ChcImpl>,
) -> CellResult<()>
where
Ribosome: RibosomeT + 'static,
{
// get the dna
let dna_file = conductor_handle
.get_dna_file(id.dna_hash())
.ok_or_else(|| DnaError::DnaMissing(id.dna_hash().to_owned()))?;
let conductor_api = CellConductorApi::new(conductor_handle.clone(), id.clone());
// run genesis
let workspace = GenesisWorkspace::new(authored_db, dht_db)
.map_err(ConductorApiError::from)
.map_err(Box::new)?;
// exit early if genesis has already run
if workspace.has_genesis(id.agent_pubkey().clone()).await? {
return Ok(());
}
let args = GenesisWorkflowArgs::new(
dna_file,
id.agent_pubkey().clone(),
membrane_proof,
ribosome,
dht_db_cache,
chc,
);
genesis_workflow(workspace, conductor_api, args)
.await
.map_err(ConductorApiError::from)
.map_err(Box::new)?;
if let Some(trigger) = conductor_handle
.get_queue_consumer_workflows()
.integration_trigger(Arc::new(id.dna_hash().clone()))
{
trigger.trigger(&"genesis");
}
Ok(())
}
src/core/workflow/call_zome_workflow.rs (line 150)
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)
}
Trait Implementations§
source§impl CellConductorApiT for CellConductorApi
impl CellConductorApiT for CellConductorApi
source§fn call_zome<'life0, 'life1, 'async_trait>(
&'life0 self,
cell_id: &'life1 CellId,
call: ZomeCall
) -> Pin<Box<dyn Future<Output = ConductorApiResult<ZomeCallResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn call_zome<'life0, 'life1, 'async_trait>(
&'life0 self,
cell_id: &'life1 CellId,
call: ZomeCall
) -> Pin<Box<dyn Future<Output = ConductorApiResult<ZomeCallResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Invoke a zome function on any cell in this conductor.
A zome call on a different Cell than this one corresponds to a bridged call.
source§fn dpki_request<'life0, 'async_trait>(
&'life0 self,
_method: String,
_args: String
) -> Pin<Box<dyn Future<Output = ConductorApiResult<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn dpki_request<'life0, 'async_trait>(
&'life0 self,
_method: String,
_args: String
) -> Pin<Box<dyn Future<Output = ConductorApiResult<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Make a request to the DPKI service running for this Conductor.
TODO: decide on actual signature
source§fn keystore(&self) -> &MetaLairClient
fn keystore(&self) -> &MetaLairClient
Request access to this conductor’s keystore
source§fn signal_broadcaster(&self) -> SignalBroadcaster
fn signal_broadcaster(&self) -> SignalBroadcaster
Access the broadcast Sender which will send a Signal across every
attached app interface
source§fn get_this_dna(&self) -> ConductorApiResult<DnaFile>
fn get_this_dna(&self) -> ConductorApiResult<DnaFile>
Get the
Dna
of this cell from the RibosomeStore
source§fn get_this_ribosome(&self) -> ConductorApiResult<RealRibosome>
fn get_this_ribosome(&self) -> ConductorApiResult<RealRibosome>
Get the
RealRibosome
of this cell from the RibosomeStore
source§fn get_zome(
&self,
dna_hash: &DnaHash,
zome_name: &ZomeName
) -> ConductorApiResult<Zome>
fn get_zome(
&self,
dna_hash: &DnaHash,
zome_name: &ZomeName
) -> ConductorApiResult<Zome>
Get a
Zome
from this cell’s Dnasource§fn get_entry_def(&self, key: &EntryDefBufferKey) -> Option<EntryDef>
fn get_entry_def(&self, key: &EntryDefBufferKey) -> Option<EntryDef>
Get a
EntryDef
from the EntryDefBufferKey
source§fn into_call_zome_handle(self) -> CellConductorReadHandle
fn into_call_zome_handle(self) -> CellConductorReadHandle
Turn this into a call zome handle
source§fn post_commit_permit<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<OwnedPermit<PostCommitArgs>, SendError<()>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn post_commit_permit<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<OwnedPermit<PostCommitArgs>, SendError<()>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Get an OwnedPermit to the post commit task.
source§impl CellConductorReadHandleT for CellConductorApi
impl CellConductorReadHandleT for CellConductorApi
source§fn call_zome<'life0, 'async_trait>(
&'life0 self,
call: ZomeCall,
workspace_lock: SourceChainWorkspace
) -> Pin<Box<dyn Future<Output = ConductorApiResult<ZomeCallResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn call_zome<'life0, 'async_trait>(
&'life0 self,
call: ZomeCall,
workspace_lock: SourceChainWorkspace
) -> Pin<Box<dyn Future<Output = ConductorApiResult<ZomeCallResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Invoke a zome function on a Cell
source§fn get_zome(
&self,
dna_hash: &DnaHash,
zome_name: &ZomeName
) -> ConductorApiResult<Zome>
fn get_zome(
&self,
dna_hash: &DnaHash,
zome_name: &ZomeName
) -> ConductorApiResult<Zome>
Get a zome from this cell’s Dna
source§fn get_entry_def(&self, key: &EntryDefBufferKey) -> Option<EntryDef>
fn get_entry_def(&self, key: &EntryDefBufferKey) -> Option<EntryDef>
Get a
EntryDef
from the EntryDefBufferKey
source§fn witness_nonce_from_calling_agent<'life0, 'async_trait>(
&'life0 self,
agent: AgentPubKey,
nonce: Nonce256Bits,
expires: Timestamp
) -> Pin<Box<dyn Future<Output = ConductorApiResult<WitnessNonceResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn witness_nonce_from_calling_agent<'life0, 'async_trait>(
&'life0 self,
agent: AgentPubKey,
nonce: Nonce256Bits,
expires: Timestamp
) -> Pin<Box<dyn Future<Output = ConductorApiResult<WitnessNonceResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Try to put the nonce from a calling agent in the db. Fails with a stale result if a newer nonce exists.
source§fn find_cell_with_role_alongside_cell<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cell_id: &'life1 CellId,
role_name: &'life2 RoleName
) -> Pin<Box<dyn Future<Output = ConductorResult<Option<CellId>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn find_cell_with_role_alongside_cell<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cell_id: &'life1 CellId,
role_name: &'life2 RoleName
) -> Pin<Box<dyn Future<Output = ConductorResult<Option<CellId>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Find the first cell ID across all apps the given cell id is in that
is assigned to the given role.
source§impl Clone for CellConductorApi
impl Clone for CellConductorApi
source§fn clone(&self) -> CellConductorApi
fn clone(&self) -> CellConductorApi
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for CellConductorApi
impl Send for CellConductorApi
impl Sync for CellConductorApi
impl Unpin for CellConductorApi
impl !UnwindSafe for CellConductorApi
Blanket Implementations§
§impl<T> Any for Twhere
T: Any + ?Sized,
impl<T> Any for Twhere
T: Any + ?Sized,
§fn type_id_compat(&self) -> TypeId
fn type_id_compat(&self) -> TypeId
TODO: once 1.33.0 is the minimum supported compiler version, remove
Any::type_id_compat and use StdAny::type_id instead.
https://github.com/rust-lang/rust/issues/27745
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
§impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
§fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
Deserializes using the given deserializer
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.§impl<T> Upcastable for Twhere
T: 'static + Any + Send + Sync,
impl<T> Upcastable for Twhere
T: 'static + Any + Send + Sync,
§fn upcast_any_ref(&self) -> &(dyn Any + 'static)
fn upcast_any_ref(&self) -> &(dyn Any + 'static)
upcast ref
§fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
upcast mut ref