pub struct HostFnCaller {
    pub authored_db: DbWrite<DbKindAuthored>,
    pub dht_db: DbWrite<DbKindDht>,
    pub dht_db_cache: DhtDbQueryCache,
    pub cache: DbWrite<DbKindCache>,
    pub ribosome: RealRibosome,
    pub zome_path: ZomePath,
    pub network: HolochainP2pDna,
    pub keystore: MetaLairClient,
    pub signal_tx: SignalBroadcaster,
    pub call_zome_handle: CellConductorReadHandle,
}
Expand description

A freely callable version of the host fn api, so that host functions can be called from Rust instead of Wasm

Fields§

§authored_db: DbWrite<DbKindAuthored>§dht_db: DbWrite<DbKindDht>§dht_db_cache: DhtDbQueryCache§cache: DbWrite<DbKindCache>§ribosome: RealRibosome§zome_path: ZomePath§network: HolochainP2pDna§keystore: MetaLairClient§signal_tx: SignalBroadcaster§call_zome_handle: CellConductorReadHandle

Implementations§

Create HostFnCaller for the first zome.

Create HostFnCaller for a specific zome if there are multiple.

Examples found in repository?
src/test_utils/host_fn_caller.rs (line 109)
104
105
106
107
108
109
110
    pub async fn create(
        cell_id: &CellId,
        handle: &ConductorHandle,
        dna_file: &DnaFile,
    ) -> HostFnCaller {
        Self::create_for_zome(cell_id, handle, dna_file, 0).await
    }
Examples found in repository?
src/test_utils/host_fn_caller.rs (line 269)
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
    pub async fn commit_entry<E: Into<EntryDefLocation>>(
        &self,
        entry: Entry,
        entry_def_id: E,
        visibility: EntryVisibility,
    ) -> ActionHash {
        let (ribosome, call_context, workspace_lock) = self.unpack().await;
        let input = CreateInput::new(
            entry_def_id.into(),
            visibility,
            entry,
            ChainTopOrdering::default(),
        );
        let output = host_fn::create::create(ribosome, call_context, input).unwrap();

        // Write
        workspace_lock.flush(&self.network).await.unwrap();

        output
    }

    pub async fn delete_entry<'env>(&self, input: DeleteInput) -> ActionHash {
        let (ribosome, call_context, workspace_lock) = self.unpack().await;
        let output = {
            let r = host_fn::delete::delete(ribosome, call_context, input);
            let r = r.map_err(|e| {
                debug!(%e);
                e
            });
            r.unwrap()
        };

        // Write
        workspace_lock.flush(&self.network).await.unwrap();

        output
    }

    pub async fn update_entry(
        &self,
        entry: Entry,
        original_action_address: ActionHash,
    ) -> ActionHash {
        let (ribosome, call_context, workspace_lock) = self.unpack().await;
        let input = UpdateInput {
            original_action_address,
            entry,
            chain_top_ordering: Default::default(),
        };

        let output = { host_fn::update::update(ribosome, call_context, input).unwrap() };

        // Write
        workspace_lock.flush(&self.network).await.unwrap();

        output
    }

    pub async fn get(&self, entry_hash: AnyDhtHash, options: GetOptions) -> Vec<Option<Record>> {
        let (ribosome, call_context, _) = self.unpack().await;
        let input = GetInput::new(entry_hash, options);
        host_fn::get::get(ribosome, call_context, vec![input]).unwrap()
    }

    pub async fn get_details<'env>(
        &self,
        entry_hash: AnyDhtHash,
        options: GetOptions,
    ) -> Vec<Option<Details>> {
        let (ribosome, call_context, _) = self.unpack().await;
        let input = GetInput::new(entry_hash, options);
        host_fn::get_details::get_details(ribosome, call_context, vec![input]).unwrap()
    }

    pub async fn create_link<'env>(
        &self,
        base: AnyLinkableHash,
        target: AnyLinkableHash,
        zome_index: impl Into<ZomeIndex>,
        link_type: impl Into<LinkType>,
        link_tag: LinkTag,
    ) -> ActionHash {
        let (ribosome, call_context, workspace_lock) = self.unpack().await;
        let input = CreateLinkInput::new(
            base,
            target,
            zome_index.into(),
            link_type.into(),
            link_tag,
            ChainTopOrdering::default(),
        );
        let output = { host_fn::create_link::create_link(ribosome, call_context, input).unwrap() };

        // Write
        workspace_lock.flush(&self.network).await.unwrap();

        output
    }

    pub async fn delete_link<'env>(&self, link_add_hash: ActionHash) -> ActionHash {
        let (ribosome, call_context, workspace_lock) = self.unpack().await;
        let output = {
            host_fn::delete_link::delete_link(
                ribosome,
                call_context,
                DeleteLinkInput::new(link_add_hash, ChainTopOrdering::default()),
            )
            .unwrap()
        };

        // Write
        workspace_lock.flush(&self.network).await.unwrap();

        output
    }

    pub async fn get_links<'env>(
        &self,
        base: AnyLinkableHash,
        type_query: LinkTypeFilter,
        link_tag: Option<LinkTag>,
        _options: GetLinksOptions,
    ) -> Vec<Link> {
        let (ribosome, call_context, workspace_lock) = self.unpack().await;
        let input = GetLinksInput::new(base, type_query, link_tag);
        let output = {
            host_fn::get_links::get_links(ribosome, call_context, vec![input])
                .unwrap()
                .into_iter()
                .next()
                .unwrap()
        };

        // Write
        workspace_lock.flush(&self.network).await.unwrap();

        output
    }

    pub async fn get_link_details<'env>(
        &self,
        base: AnyLinkableHash,
        type_query: LinkTypeFilter,
        tag: LinkTag,
        _options: GetLinksOptions,
    ) -> Vec<(SignedActionHashed, Vec<SignedActionHashed>)> {
        let (ribosome, call_context, workspace_lock) = self.unpack().await;
        let input = GetLinksInput::new(base, type_query, Some(tag));
        let output = {
            host_fn::get_link_details::get_link_details(ribosome, call_context, vec![input])
                .unwrap()
                .into_iter()
                .next()
                .unwrap()
        };

        // Write
        workspace_lock.flush(&self.network).await.unwrap();

        output.into()
    }

    pub async fn get_agent_activity(
        &self,
        agent: &AgentPubKey,
        query: &ChainQueryFilter,
        request: ActivityRequest,
    ) -> AgentActivity {
        let (ribosome, call_context, _) = self.unpack().await;
        let input = GetAgentActivityInput::new(agent.clone(), query.clone(), request);
        host_fn::get_agent_activity::get_agent_activity(ribosome, call_context, input).unwrap()
    }

    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()
    }
source

pub fn get_entry_type(
    &self,
    zome: impl Into<TestWasmPair<ZomeName>>,
    index: impl Into<EntryDefIndex>
) -> ScopedEntryDefIndex

source

pub fn get_entry_link(
    &self,
    zome: impl Into<TestWasmPair<ZomeName>>,
    index: impl Into<LinkType>
) -> ScopedLinkType

source

pub async fn commit_entry<E: Into<EntryDefLocation>>(
    &self,
    entry: Entry,
    entry_def_id: E,
    visibility: EntryVisibility
) -> ActionHash

source

pub async fn delete_entry<'env>(&self, input: DeleteInput) -> ActionHash

source

pub async fn update_entry(
    &self,
    entry: Entry,
    original_action_address: ActionHash
) -> ActionHash

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
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
The archived version of the pointer metadata for this type.
Converts some archived metadata to the pointer metadata for itself.
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Deserializes using the given deserializer

Returns the argument unchanged.

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Attaches the current Context to this type, returning a WithContext wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The type for metadata in pointers and references to Self.
Should always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Checks if self is actually part of its subset T (and can be converted to it).
Use with care! Same as self.to_subset but without any property checks. Always succeeds.
The inclusion map: converts self to the equivalent element of its superset.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
upcast ref
upcast mut ref
upcast boxed dyn
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more