1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use hdk::{
    entry_definition::ValidatingEntryType,
    entry,
    to,
    link,
};
use hdk::holochain_core_types::{
    dna::entry_types::Sharing,
};

use crate::{
    ROOT_ANCHOR_TYPE,
    ROOT_ANCHOR_LINK_TO,
    ANCHOR_TYPE,
    Anchor,
    RootAnchor,
};

/// This defines the root anchor that is used to list all anchors.
/// It must be called from your zome.
pub fn root_anchor_definition() -> ValidatingEntryType {
    entry!(
        name: ROOT_ANCHOR_TYPE,
        description: "All other anchors are linked from the root anchor so we can list all the anchors.",
        sharing: Sharing::Public,
        validation_package: || {
            hdk::ValidationPackageDefinition::Entry
        },
        validation: | _validation_data: hdk::EntryValidationData<RootAnchor>| {
            Ok(())
        },
        links: [
            to!(
                ANCHOR_TYPE,
                link_type: ROOT_ANCHOR_LINK_TO,

                validation_package: || {
                    hdk::ValidationPackageDefinition::Entry
                },

                validation: |_validation_data: hdk::LinkValidationData| {
                    Ok(())
                }
            )
        ]
    )
}

/// This defines the anchor type that is used to create arbitrary anchors.
/// It must be called from your zome.
pub fn anchor_definition() -> ValidatingEntryType {
    entry!(
        name: ANCHOR_TYPE,
        description: "Anchors are used as the base for links so linked entries can be found with a text search.",
        sharing: Sharing::Public,
        validation_package: || {
            hdk::ValidationPackageDefinition::Entry
        },
        validation: | _validation_data: hdk::EntryValidationData<Anchor>| {
            Ok(())
        }
    )
}