-
Notifications
You must be signed in to change notification settings - Fork 28
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
There was a problem hiding this 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/identifiers.md
Outdated
use hdk::prelude::*; | ||
|
||
let my_first_id = agent_info()?.agent_initial_pubkey; | ||
let my_current_id = agent_info()?.agent_latest_pubkey; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😆 love this example
src/pages/build/identifiers.md
Outdated
pub struct MovieLoan { | ||
movie_hash: EntryHash, | ||
lent_to: AgentPubKey, | ||
loan_terms: ActionHash, |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
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)
There was a problem hiding this 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
Co-authored-by: mattyg <[email protected]>
@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 |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
..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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)? | ||
)?; | ||
)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
)?; |
There was a problem hiding this 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.
Resolves #467
Seeking review for: