diff --git a/src/pages/build/querying-source-chains.md b/src/pages/build/querying-source-chains.md index a882fd085..28ffd3206 100644 --- a/src/pages/build/querying-source-chains.md +++ b/src/pages/build/querying-source-chains.md @@ -80,69 +80,6 @@ pub fn get_all_movies_i_authored() -> Vec { } ``` -## Query another agent's source chain - -An agent can query another agent's source chain with the [`get_agent_activity`](https://docs.rs/hdk/latest/hdk/chain/fn.get_agent_activity.html) host function. - -`get_agent_activity` returns [`AgentActivity`](https://docs.rs/holochain_zome_types/latest/holochain_zome_types/query/struct.AgentActivity.html), a struct with rich info on the agent's source chain status, but it _only returns the action hashes_ of matching records; it's the job of the caller to turn them into records. - -```rust -use hdk::prelude::*; - -#[hdk_extern] -pub fn get_all_movies_authored_by_other_agent(agent: AgentPubKey) -> ExternResult)>> { - let activity = get_agent_activity( - agent, - ChainQueryFilter::new() - .entry_type(EntryType::App(UnitEntryTypes::Movie.into())) - .include_entries(true), - ActivityRequest::Full - )?; - - // Now try to retrieve the records for all of the action hashes, turning - // the whole result into an Err if any record retrieval returns an Err. - let chain_with_entries = activity.valid_activity - .iter() - .map(|a| { - let maybe_record = get(a.1, GetOptions::network())?; - // Because some records may be irretrievable if no agent is - // currently serving them, remember the action hash so we can try - // retrieving them later. - Ok((a.1, maybe_record)) - }) - .collect(); - Ok(chain_with_entries) -} -``` - -### Get source chain status summary - -`get_agent_activity` is for more than just querying an agent's source chain. It also returns the _status of the agent's source chain_, which includes evidence of [source chain forks](/resources/glossary/#fork-source-chain) and invalid actions. - -To quickly check the status without retrieving the source chain's action hashes, pass `ActivityRequest::Status` to `get_agent_activity` and look at the `status` field of the return value: - -```rust -use hdk::prelude::*; - -#[hdk_extern] -pub fn check_status_of_peer_source_chain(agent: AgentPubKey) -> ExternResult { - let activity_summary = get_agent_activity( - agent, - ChainQueryFilter::new() - .sequence_range(ChainQueryFilterRange::Unbounded), - ActivityRequest.Status - )?; - Ok(activity_summary.status) -} -``` - -[This status can be one of](https://docs.rs/holochain_zome_types/latest/holochain_zome_types/query/enum.ChainStatus.html): - -* `Empty`: No source chain activity found for the agent. -* Valid(ChainHead): The source chain is valid, with its newest action's sequence index and hash given. -* Forked(ChainFork): The source chain has been [forked](/resources/glossary/#fork-source-chain), with the sequence index and conflicting action hashes of the fork point given. -* Invalid(ChainHead): An invalid record was found at the given sequence index and action hash. - ## Query another agent's source chain for validation Validation imposes an extra constraint on source chain queries. A source chain can grow over time, including branching or forking. That means a source chain, when retrieved by agent public key alone, is a non-deterministic source of data, which you can't use in validation. Instead, you can use [`must_get_agent_activity`](https://docs.rs/hdi/latest/hdi/chain/fn.must_get_agent_activity.html), whose [filter struct](https://docs.rs/holochain_integrity_types/latest/holochain_integrity_types/chain/struct.ChainFilter.html) and return value remove non-determinism.