Skip to content
This repository was archived by the owner on Feb 3, 2023. It is now read-only.

Commit 9f0e375

Browse files
author
Nicolas Luck
authored
Merge pull request #932 from holochain/get-entry-options
GetEntryOptions
2 parents 930f491 + 3c103fb commit 9f0e375

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+599
-343
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
44

55
## [Unreleased]
66
### Changed
7+
- core now depends on `pretty_assertions` crate
8+
- `ChainHeader::sources()` is now `ChainHeader::provenances()`
9+
- Headers from other agents are stored in the EAV
10+
- `hdk::get_entry_results` supports return of ChainHeaders for all agents who have committed the same entry
711
- Rename the term Container and all references to it to Conductor
812
- The `holochain_container` executable has been renamed to simply `holochain`
9-
1013
- `cmd` crate (which implements the `hc` command line tool) renamed to `cli`
1114
- Encoded values in ribosome function's input/output are u64 (up from u32)
1215
- Capabilities now separated from function declarations in `define_zome!` and calling zome functions no longer uses capability name parameter [#791](https://github.com/holochain/holochain-rust/pull/779)

app_spec/test/test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ const dnaPath = path.join(__dirname, "../dist/app_spec.hcpkg")
66
const dna = Config.dna(dnaPath, 'app-spec')
77
const agentAlice = Config.agent("alice")
88
const agentBob = Config.agent("bob")
9+
const agentCarol = Config.agent("carol")
910

1011
const instanceAlice = Config.instance(agentAlice, dna)
1112
const instanceBob = Config.instance(agentBob, dna)
13+
const instanceCarol = Config.instance(agentCarol, dna)
1214

1315
const scenario1 = new Scenario([instanceAlice])
1416
const scenario2 = new Scenario([instanceAlice, instanceBob])
17+
const scenario3 = new Scenario([instanceAlice, instanceBob, instanceCarol])
1518

1619
scenario2.runTape('agentId', async (t, { alice, bob }) => {
1720
t.ok(alice.agentId)
@@ -27,6 +30,25 @@ scenario1.runTape('show_env', async (t, { alice }) => {
2730
t.equal(result.Ok.agent_id, '{"nick":"alice","key":"'+alice.agentId+'"}')
2831
})
2932

33+
scenario3.runTape('get sources', async (t, { alice, bob, carol }) => {
34+
const params = {content: 'whatever', in_reply_to: null}
35+
const address = await alice.callSync('blog', 'create_post', params).then(x => x.Ok)
36+
const address1 = await alice.callSync('blog', 'create_post', params).then(x => x.Ok)
37+
const address2 = await bob.callSync('blog', 'create_post', params).then(x => x.Ok)
38+
const address3 = await carol.callSync('blog', 'create_post', params).then(x => x.Ok)
39+
t.equal(address, address1)
40+
t.equal(address, address2)
41+
t.equal(address, address3)
42+
const sources1 = alice.call('blog', 'get_sources', {address}).Ok.sort()
43+
const sources2 = bob.call('blog', 'get_sources', {address}).Ok.sort()
44+
const sources3 = carol.call('blog', 'get_sources', {address}).Ok.sort()
45+
// NB: alice shows up twice because she published the same entry twice
46+
const expected = [alice.agentId, alice.agentId, bob.agentId, carol.agentId].sort()
47+
t.deepEqual(sources1, expected)
48+
t.deepEqual(sources2, expected)
49+
t.deepEqual(sources3, expected)
50+
})
51+
3052
scenario1.runTape('call', async (t, { alice }) => {
3153

3254
const num1 = 2

app_spec/zomes/blog/code/src/blog.rs

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ use hdk::{
55
cas::content::Address, entry::Entry, error::HolochainError, json::JsonString,
66
},
77
holochain_wasm_utils::api_serialization::{
8-
get_entry::GetEntryOptions,
8+
get_entry::{GetEntryOptions, GetEntryResultType},
99
get_links::{GetLinksOptions, GetLinksResult},
1010
},
11-
AGENT_ADDRESS,
12-
AGENT_ID_STR,
13-
DNA_NAME,
14-
DNA_ADDRESS,
11+
AGENT_ADDRESS, AGENT_ID_STR, DNA_ADDRESS, DNA_NAME,
1512
};
1613
use post::Post;
1714

@@ -33,14 +30,36 @@ pub struct Env {
3330
/// inside a zome. In this case it just creates an object with their values
3431
/// and returns it as the result.
3532
pub fn handle_show_env() -> ZomeApiResult<Env> {
36-
Ok(Env{
33+
let _dna_entry = hdk::get_entry(&DNA_ADDRESS)?;
34+
let _agent_entry = hdk::get_entry(&AGENT_ADDRESS)?;
35+
Ok(Env {
3736
dna_name: DNA_NAME.to_string(),
3837
dna_address: DNA_ADDRESS.to_string(),
3938
agent_id: AGENT_ID_STR.to_string(),
4039
agent_address: AGENT_ADDRESS.to_string(),
4140
})
4241
}
4342

43+
pub fn handle_get_sources(address: Address) -> ZomeApiResult<Vec<Address>> {
44+
if let GetEntryResultType::Single(result) = hdk::get_entry_result(
45+
&address,
46+
GetEntryOptions {
47+
headers: true,
48+
..Default::default()
49+
},
50+
)?
51+
.result
52+
{
53+
Ok(result
54+
.headers
55+
.into_iter()
56+
.map(|header| header.provenances().first().unwrap().clone().0)
57+
.collect())
58+
} else {
59+
unimplemented!()
60+
}
61+
}
62+
4463
fn check_sum_args(num1: u32, num2: u32) -> SumInput {
4564
SumInput {
4665
num1: num1,
@@ -130,23 +149,13 @@ pub fn handle_my_recommended_posts() -> ZomeApiResult<GetLinksResult> {
130149
#[cfg(test)]
131150
pub mod tests {
132151

133-
use blog::check_sum_args;
134-
use blog::SumInput;
152+
use blog::{check_sum_args, post_entry, SumInput};
153+
use hdk::holochain_core_types::entry::{entry_type::AppEntryType, AppEntryValue, Entry};
135154
use post::Post;
136-
use blog::post_entry;
137-
use hdk::holochain_core_types::entry::Entry;
138-
use hdk::holochain_core_types::entry::AppEntryValue;
139-
use hdk::holochain_core_types::entry::entry_type::AppEntryType;
140155

141156
#[test]
142157
fn check_sum_args_test() {
143-
assert_eq!(
144-
check_sum_args(1, 1),
145-
SumInput{
146-
num1: 1,
147-
num2: 1,
148-
},
149-
);
158+
assert_eq!(check_sum_args(1, 1), SumInput { num1: 1, num2: 1 },);
150159
}
151160

152161
#[test]
@@ -155,12 +164,7 @@ pub mod tests {
155164
post_entry("foos & bars".into()),
156165
Entry::App(
157166
AppEntryType::from("post"),
158-
AppEntryValue::from(
159-
Post::new(
160-
"foos & bars".into(),
161-
"now".into(),
162-
)
163-
),
167+
AppEntryValue::from(Post::new("foos & bars".into(), "now".into(),)),
164168
),
165169
)
166170
}

app_spec/zomes/blog/code/src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ pub mod post;
1515

1616
use hdk::{
1717
error::ZomeApiResult,
18-
holochain_core_types::{cas::content::Address, entry::Entry, json::JsonString, error::HolochainError},
18+
holochain_core_types::{
19+
cas::content::Address, entry::Entry, error::HolochainError, json::JsonString,
20+
},
1921
holochain_wasm_utils::api_serialization::get_links::GetLinksResult,
2022
};
2123

@@ -38,6 +40,12 @@ define_zome! {
3840
handler: blog::handle_show_env
3941
}
4042

43+
get_sources: {
44+
inputs: |address: Address|,
45+
outputs: |sources: ZomeApiResult<Vec<Address>>|,
46+
handler: blog::handle_get_sources
47+
}
48+
4149
check_sum: {
4250
inputs: |num1: u32, num2: u32|,
4351
outputs: |sum: ZomeApiResult<JsonString>|,
@@ -100,7 +108,7 @@ define_zome! {
100108
]
101109

102110
capabilities: {
103-
public (Public) [show_env, check_sum, post_address, create_post, posts_by_agent, get_post, my_posts, my_posts_as_committed, my_posts_immediate_timeout, recommend_post, my_recommended_posts]
111+
public (Public) [show_env, check_sum, get_sources, post_address, create_post, posts_by_agent, get_post, my_posts, my_posts_as_committed, my_posts_immediate_timeout, recommend_post, my_recommended_posts]
104112
}
105113

106114
}

core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ boolinator = "2.4.0"
4040
jsonrpc-ws-server = { git = "https://github.com/paritytech/jsonrpc" }
4141
jsonrpc-lite = "0.5.0"
4242
globset = "0.4.2"
43+
pretty_assertions = "0.5.1"
4344
pin-utils = "0.1.0-alpha.4"
4445

4546
[dev-dependencies]

core/src/action.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use crate::{
22
agent::state::AgentState,
33
context::Context,
4-
network::{direct_message::DirectMessage, state::NetworkState},
4+
network::{
5+
direct_message::DirectMessage, entry_with_header::EntryWithHeader, state::NetworkState,
6+
},
57
nucleus::{
68
state::{NucleusState, ValidationResult},
79
ExecuteZomeFnResponse, ZomeFnCall,
@@ -92,7 +94,7 @@ pub enum Action {
9294
// -------------
9395
/// Adds an entry to the local DHT shard.
9496
/// Does not validate, assumes entry is valid.
95-
Hold(Entry),
97+
Hold(EntryWithHeader),
9698

9799
/// Adds a link to the local DHT shard's meta/EAV storage
98100
/// Does not validate, assumes link is valid.

core/src/agent/chain_store.rs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,12 @@ pub mod tests {
304304
use holochain_cas_implementations::cas::file::FilesystemStorage;
305305
use holochain_core_types::{
306306
cas::content::AddressableContent,
307-
chain_header::{test_chain_header, test_sources, ChainHeader},
307+
chain_header::{test_chain_header, test_provenances, ChainHeader},
308308
entry::{
309309
entry_type::{test_entry_type_b, AppEntryType},
310310
test_entry, test_entry_b, test_entry_c, Entry,
311311
},
312312
json::JsonString,
313-
signature::{test_signature_b, test_signature_c, test_signatures, Signature},
314313
time::test_iso_8601,
315314
};
316315

@@ -331,8 +330,7 @@ pub mod tests {
331330
let chain_header_b = ChainHeader::new(
332331
&entry.entry_type(),
333332
&entry.address(),
334-
&test_sources(),
335-
&vec![test_signature_b()],
333+
&test_provenances("sig"),
336334
&Some(chain_header_a.address()),
337335
&None,
338336
&None,
@@ -373,8 +371,7 @@ pub mod tests {
373371
let chain_header_b = ChainHeader::new(
374372
&entry_b.entry_type(),
375373
&entry_b.address(),
376-
&test_sources(),
377-
&test_signatures(),
374+
&test_provenances("sig"),
378375
&Some(chain_header_a.address()),
379376
&None,
380377
&None,
@@ -385,8 +382,7 @@ pub mod tests {
385382
let chain_header_c = ChainHeader::new(
386383
&entry_c.entry_type(),
387384
&entry_c.address(),
388-
&test_sources(),
389-
&test_signatures(),
385+
&test_provenances("sig"),
390386
&Some(chain_header_b.address()),
391387
&Some(chain_header_a.address()),
392388
&None,
@@ -448,8 +444,7 @@ pub mod tests {
448444
let chain_header_b = ChainHeader::new(
449445
&entry.entry_type(),
450446
&entry.address(),
451-
&test_sources(),
452-
&vec![test_signature_b()],
447+
&test_provenances("sig-b"),
453448
&Some(chain_header_a.address()), // .link (to previous entry)
454449
&None, // .link_same_type (to previous entry of same type)
455450
&None,
@@ -459,8 +454,7 @@ pub mod tests {
459454
let chain_header_c = ChainHeader::new(
460455
&entry.entry_type(),
461456
&entry.address(),
462-
&test_sources(),
463-
&vec![test_signature_c()],
457+
&test_provenances("sig-c"),
464458
&Some(chain_header_b.address()),
465459
&Some(chain_header_b.address()),
466460
&None,
@@ -473,8 +467,7 @@ pub mod tests {
473467
let chain_header_d = ChainHeader::new(
474468
&entry.entry_type(),
475469
&entry.address(),
476-
&test_sources(),
477-
&vec![Signature::from("sig-d")],
470+
&test_provenances("sig-d"),
478471
&Some(chain_header_c.address()),
479472
&None,
480473
&None,
@@ -487,8 +480,7 @@ pub mod tests {
487480
let chain_header_e = ChainHeader::new(
488481
&entry.entry_type(),
489482
&entry.address(),
490-
&test_sources(),
491-
&vec![Signature::from("sig-e")],
483+
&test_provenances("sig-e"),
492484
&Some(chain_header_d.address()),
493485
&None,
494486
&None,
@@ -623,8 +615,7 @@ pub mod tests {
623615
let chain_header_f = ChainHeader::new(
624616
&entry.entry_type(),
625617
&entry.address(),
626-
&test_sources(),
627-
&vec![Signature::from("sig-f")],
618+
&test_provenances("sig"),
628619
&Some(chain_header_e.address()),
629620
&None,
630621
&None,
@@ -634,8 +625,7 @@ pub mod tests {
634625
let chain_header_g = ChainHeader::new(
635626
&entry.entry_type(),
636627
&entry.address(),
637-
&test_sources(),
638-
&vec![Signature::from("sig-g")],
628+
&test_provenances("sig"),
639629
&Some(chain_header_f.address()),
640630
&None,
641631
&None,
@@ -645,8 +635,7 @@ pub mod tests {
645635
let chain_header_h = ChainHeader::new(
646636
&entry.entry_type(),
647637
&entry.address(),
648-
&test_sources(),
649-
&vec![Signature::from("sig-g")],
638+
&test_provenances("sig"),
650639
&Some(chain_header_g.address()),
651640
&None,
652641
&None,
@@ -710,8 +699,7 @@ pub mod tests {
710699
let chain_header_i = ChainHeader::new(
711700
&entry.entry_type(),
712701
&entry.address(),
713-
&test_sources(),
714-
&vec![Signature::from("sig-i")],
702+
&test_provenances("sig"),
715703
&Some(chain_header_h.address()),
716704
&None,
717705
&None,

core/src/agent/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use holochain_core_types::{
1111
use std::sync::Arc;
1212

1313
pub fn find_chain_header(entry: &Entry, context: &Arc<Context>) -> Option<ChainHeader> {
14-
let chain = context.state().unwrap().agent().chain();
14+
let chain = context.state().unwrap().agent().chain_store();
1515
let top_header = context.state().unwrap().agent().top_chain_header();
1616
chain
1717
.iter(&top_header)

0 commit comments

Comments
 (0)