Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/holochain/holochain-anchors
A core pattern for storing AND FINDING data in a Holochain DHT. Anchors are a predictable hash (by using known content) from which you can attach links
https://github.com/holochain/holochain-anchors
graph-db holochain holochain-application mixin
Last synced: about 1 month ago
JSON representation
A core pattern for storing AND FINDING data in a Holochain DHT. Anchors are a predictable hash (by using known content) from which you can attach links
- Host: GitHub
- URL: https://github.com/holochain/holochain-anchors
- Owner: holochain
- License: mit
- Created: 2019-12-04T05:52:32.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-10-02T13:14:18.000Z (about 4 years ago)
- Last Synced: 2024-05-19T02:59:02.796Z (7 months ago)
- Topics: graph-db, holochain, holochain-application, mixin
- Language: Rust
- Homepage:
- Size: 37.1 KB
- Stars: 39
- Watchers: 15
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Holochain Anchors
NOTE: In [Holochain RSM](https://github.com/holochain/holochain) anchors is has been built into coreThis crate allows a [Holochain-redux](https://github.com/holochain/holochain-rust) project to easily use the anchors pattern for creating links.
## Install
Add the following to your zomes cargo toml.
```
holochain_anchors = "0.2.3"
```## Usage
Add the anchor entry def to your zome.
```rust
#[entry_def]
fn anchor_def() -> ValidatingEntryType {
holochain_anchors::anchor_definition()
}
```
Link from the `ANCHOR_TYPE`
```rust
links: [
from!(
holochain_anchors::ANCHOR_TYPE,
link_type: "my_link_type",
validation_package: || {
hdk::ValidationPackageDefinition::Entry
},validation: |_validation_data: hdk::LinkValidationData| {
Ok(())
}
)
]
```
Create an anchor and link an entry to it.
If the anchor already exists then it will use the existing anchor.
```rust
let my_entry = Entry::App(
"my_entry".into(),
MyEntry{
content: "some_content".into()
}.into()
);
let address = hdk::commit_entry(&my_entry)?;
let anchor_address = holochain_anchors::anchor("my_anchor_type".into(), "my_anchor".into())?;
hdk::link_entries(&anchor_address, &address, "my_link_type", "my_anchor")?;
```
Get all the links on that anchor.
```rust
let anchor_address = holochain_anchors::anchor("my_anchor_type".into(), "my_anchor".into())?;
hdk::utils::get_links_and_load_type(&anchor_address, LinkMatch::Exactly("my_link_type"), LinkMatch::Any)
```