You can think of anchors as an entry that every user knows the hash of. As the name implies, it acts as an 'anchor' with which we can link other entries to in order to create queries for things every user will need to access, for example, every user or post in the system.
Here you can try out a system where every post that is created gets linked to an anchor for posts.
entry_defs![ Anchor::entry_def(), ... ];
For this exercise we will be implementing the above example.
create_post: creates a post and attaches it to an anchor for posts.
- Define an anchor with
ALL_POSTSand text =
ALL_POSTS. This will already internally create the anchor for you.
- Create the post entry, and calculate its hash.
- Create a link from the anchor entry to the post entry.
get_all_postsqueries the links of the posts anchor and returns all the posts.
- Calculate the anchor entry hash.
- Get the links from the anchor entry to all the posts.
- For every target in these links, do a
getto retrieve the posts.
- Check if you are still inside the nix-shell.
Your terminal should look similar to this
- Compile and test your code:
cd tests && npm install && npm test.
- Don't stop until the tests run green.