-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
155 lines (133 loc) · 4.94 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, viewport-fit=cover"
/>
<meta name="Description" content="Put your description here." />
<base href="/" />
<script type="module">
import "reveal.js/dist/reveal.css";
import "reveal.js/dist/theme/black.css";
import "reveal.js/plugin/highlight/monokai.css";
import "@mythosthesia/reveal-course-preset/styles.css";
</script>
<title>Holochain Lesson 3</title>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h1>HDK: retrieving source chains</h1>
</section>
<!-- TODO: what to do in the recap? Probably we build it during the weekend -->
<section>
<!-- prettier-ignore -->
<fragment language="markdown" animate="by-line with-ancestry">
### query() (I)
- Retrieve the source chain for the cell that's calling "query()"
- Only way to retrieve private entries
</fragment>
<!-- prettier-ignore -->
<fragment>
<pre
class="fragment fade-in"
><code class="rust" data-noescape data-trim
animate="by-line balanced with-ancestry separate-comments trailing-comments-in-popover strike-on-error-in-comment"
>
use hdk::prelude::*;
#[hdk_extern]
fn query_my_full_chain(_: ()) -> ExternResult<Vec<Record>> {
let filter = ChainQueryFilter::new(); // We'll see more options
let my_full_chain: Vec<Record> = query(filter)?; // - Does not do any network call
// - Records are returned in ascendent
// order (from oldest to newest)
Ok(my_full_chain)
}
</code></pre>
</fragment>
</section>
<section>
<h3>query() (II)</h3>
<!-- prettier-ignore -->
<fragment>
<pre
class="fragment fade-in"
><code class="rust" data-noescape data-trim
animate="by-line balanced with-ancestry separate-comments trailing-comments-in-popover strike-on-error-in-comment"
>
use hdk::prelude::*;
#[hdk_entry_helper]
struct Comment {
comment: String
}
#[hdk_entry_defs]
#[unit_enum(UnitEntryTypes)]
enum EntryTypes {
Comment(Comment),
}
#[hdk_extern]
fn query_my_comments(_: ()) -> ExternResult<Vec<Record>> {
let comment_entry_type: EntryType = UnitEntryTypes::Comment.try_into()?; // Generated with
// "#[unit_enum()]"
let filter = ChainQueryFilter::new().entry_type(comment_entry_type); // Filter by the
// given entrytype
let all_my_comments = query(filter)?; // Only the records which create or update comments
Ok(all_my_comments)
}
#[hdk_extern]
fn query_all_links_i_created(_: ()) -> ExternResult<Vec<Record>> {
let filter = ChainQueryFilter::new().action_type(ActionType::CreateLink); // May be any kind
// of action
let all_links_i_created = query(filter)?; // Only the records whose action
// is of the "CreateLink" variant
Ok(all_links_i_created)
}
</code></pre>
</fragment>
</section>
<section>
<!-- prettier-ignore -->
<fragment language="markdown" animate="by-line with-ancestry">
### get_agent_activity()
- Retrieve the source chain actions for a given agent
- All actions are public in the DHT
- Doesn't return entries
</fragment>
<!-- prettier-ignore -->
<fragment>
<pre
class="fragment fade-in"
><code class="rust" data-noescape data-trim
animate="by-line balanced with-ancestry separate-comments trailing-comments-in-popover strike-on-error-in-comment"
>
use hdk::prelude::*;
#[hdk_extern]
fn get_comments_created_by(author: AgentPubKey) -> ExternResult<Vec<ActionHash>> {
let filter = ChainQueryFilter::new(); // Same options as "query"
let agent_activity = get_agent_activity(
author,
filter,
ActivityRequest::Full // - "ActivityRequest" can be:
// - "Full": request the list of action hashes for the full chain
// - "Status": request only the status of the chain
)?;
}
</code></pre>
</fragment>
</section>
<section>
<h1>That's it!</h1>
</section>
</div>
</div>
<script type="module">
import Reveal from "reveal.js";
import { plugins, config } from "@mythosthesia/reveal-course-preset";
let deck = new Reveal();
deck.initialize(config);
</script>
</body>
</html>