hdk/
chain.rs

1use crate::prelude::*;
2pub use hdi::chain::*;
3
4/// Query the _actions_ of a remote agent's chain.
5///
6/// The agent activity is only the actions of their source chain.
7/// The agent activity is held by the neighbourhood of the agent's public key, rather than a content hash like the rest of the DHT.
8///
9/// The agent activity can be filtered with [ `ChainQueryFilter` ] like a local chain query.
10pub fn get_agent_activity(
11    agent: AgentPubKey,
12    query: ChainQueryFilter,
13    request: ActivityRequest,
14) -> ExternResult<AgentActivity> {
15    HDK.with(|h| {
16        h.borrow()
17            .get_agent_activity(GetAgentActivityInput::new(agent, query, request))
18    })
19}
20
21/// Walks the source chain in ascending order (oldest to latest) filtering by action and/or entry type
22///
23/// Given an action and entry type, returns an [ `Vec<Record>` ]
24///
25// @todo document this better with examples after we make query do all the things we want.
26// @todo implement cap grant/claim usage in terms of query
27// @todo have ability to hash-bound query other agent's chains based on agent activity
28// @todo tie query into validation so we track dependencies e.g. validation packages
29// @todo decide which direction we want to iterate in (paramaterise query?)
30// @todo more expresivity generally?
31pub fn query(filter: ChainQueryFilter) -> ExternResult<Vec<Record>> {
32    HDK.with(|h| h.borrow().query(filter))
33}