Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Links, paths, and anchors #453

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open

Links, paths, and anchors #453

wants to merge 33 commits into from

Conversation

pdaoust
Copy link
Collaborator

@pdaoust pdaoust commented Jun 6, 2024

Resolves #467

Seeking review for:

  • Succinctness of prose -- do you get lost? Is there too much information, is the complex stuff (e.g., introducing how to get a hash for linking) introduced too early?
  • Correctness of code at first glance -- I have to confess I haven't tried compiling any of it yet.

@pdaoust pdaoust requested review from mattyg, mjbrisebois and c12i June 6, 2024 22:07
Copy link

@mjbrisebois mjbrisebois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. I didn't know how to use the anchor functions until reading this.

src/pages/build/links-paths-and-anchors.md Outdated Show resolved Hide resolved
src/pages/build/links-paths-and-anchors.md Outdated Show resolved Hide resolved
Copy link
Member

@mattyg mattyg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome stuff thanks for taking this on!

src/pages/build/entries.md Show resolved Hide resolved
use hdk::prelude::*;

let my_first_id = agent_info()?.agent_initial_pubkey;
let my_current_id = agent_info()?.agent_latest_pubkey;
Copy link
Member

@mattyg mattyg Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😬 makes me want to delete agent_latest_pubkey from holochain until its actually used and deepkey is stable, since its effectively a placeholder right now.

I might just not mention it here.

let author_id = action.author();
```

### External reference
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ ❤️ ❤️

use hdi::prelude::*;

#[hdk_entry_helper]
pub struct MovieLoan {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆 love this example

pub struct MovieLoan {
movie_hash: EntryHash,
lent_to: AgentPubKey,
loan_terms: ActionHash,
Copy link
Member

@mattyg mattyg Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might make this field loan_duration or return_date timestamp so we don't need a LoanTerm entry that isn't actually created in any other snippets (and the reader isn't confused about why loan_terms is an action hash when there is no LoanTerm entry type)

Copy link
Collaborator Author

@pdaoust pdaoust Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, that's fine -- I wanted to show a struct that had a mixture of different kinds of hashes, but EntryHash and AgentPubKey is prob enough rather than implying the existence of (or defining) a LoanTerms type.


* You may safely use the hash of an action you've just written as data in another action in the same function (e.g., in a link or an entry that contains the hash in a field), as long as you're not using relaxed chain top ordering.
* The same is also true of action hashes in your function's return value.
* Don't communicate the action hash with the front end, another cell, or another peer on the network via a remote function call or [signal](/concepts/9_signals/) _from within the same function that writes it_, in case the write fails. Instead, do your communicating in a follow-up step. The easiest way to do this is by implementing [a callback called `post_commit`](https://docs.rs/hdk/latest/hdk/#internal-callbacks) which receives a vector of all the actions that the function wrote.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow amazing gotcha I've never run into this and never thought of it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super handy function -- scaffolded zomes use this trick as a way of updating front-end state on self-authored data.


### Paths
When you want to create more complex collections, you'll need to use the paths library directly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
When you want to create more complex collections, you'll need to use the paths library directly.
When you want to create more complex collections, you'll want to use the paths library directly.

* [**Private**](/build/entries/#configure-an-entry-type), stored on the author's device in their source chain and accessible to them only, or
* **Public**, stored in the graph database and accessible to all participants.

All actions are public.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth a sentence that peers store data locally in sqlite database with encryption enabled by default, but this can be disabled by compiling holochain without sqlite_encrypted (or maybe that's overkill and ignore me)

Copy link
Member

@mattyg mattyg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thrilled with this, amazing work

@pdaoust
Copy link
Collaborator Author

pdaoust commented Dec 20, 2024

@mattyg thanks so much for all the encouragement -- glad to hear it's landing 🙏🏼 I've been out of programming for so long that positive feedback is very welcome. And I think I'm getting the hang of writing Rust code (and hApp code), although there are some gnarly things along the way (e.g., holochain/holochain#4575 ).

I've tried compiling all the code samples and discovered that there were a fair few errors; would you be willing to re-review this PR and make sure my 'solutions' to the errors are all reasonably idiomatic?

imdb_id: Some("tt0060196"),
release_date: Timestamp::from(Date::Utc("1966-12-23")),
imdb_id: Some("tt0060196".to_string()),
release_date: Timestamp(-95_472_000_000_000), // 1966-12-23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to construct the timestamp from a human readable date. It looks like we can do so via chrono::DateTime<Utc> https://docs.rs/hdk/latest/hdk/prelude/struct.Timestamp.html#impl-From%3C%26DateTime%3CUtc%3E%3E-for-Timestamp

title: "The Good, the Bad, and the Ugly".to_string(),
director_hash: EntryHash::from_raw_36(vec![ /* hash of 'Sergio Leone' entry */ ]),
imdb_id: Some("tt0060196".to_string()),
release_date: Timestamp(-95_472_000_000_000),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above about constructing the timestamp

None
let links_to_movies_starting_with_g = get_links(
// A path doesn't need to have a type in order to compute its hash.
GetLinksBuilder::try_new(path_to_movies_starting_with_g.path_entry_hash()?, LinkTypes::MovieByFirstLetter)?
Copy link
Member

@mattyg mattyg Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
GetLinksBuilder::try_new(path_to_movies_starting_with_g.path_entry_hash()?, LinkTypes::MovieByFirstLetter)?
GetLinksInputBuilder::try_new(
path_to_movies_starting_with_g.path_entry_hash()?,
LinkTypes::MovieByFirstLetter
)?

);
GetLinksInputBuilder::try_new(director_entry_hash, LinkTypes::DirectorToMovie)?
.get_options(GetStrategy::Network)
..tag_prefix("year:196".as_bytes().to_owned().into())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
..tag_prefix("year:196".as_bytes().to_owned().into())
.tag_prefix("year:196".as_bytes().to_owned().into())

use movie_integrity::*;

let path_to_movies_starting_with_g = Path::from("movies_by_first_letter.g");
let links_to_movies_starting_with_g = get_links(
Copy link
Member

@mattyg mattyg Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let links_to_movies_starting_with_g = get_links(

// A path doesn't need to have a type in order to compute its hash.
GetLinksBuilder::try_new(path_to_movies_starting_with_g.path_entry_hash()?, LinkTypes::MovieByFirstLetter)?
)?;
)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
)?;

Copy link
Member

@mattyg mattyg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple issues in comments, otherwise looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Practical docs for using Links
4 participants