Chain Action | DhtOp Name | Targeted hash basis | Payload | Metadata |
---|---|---|---|---|
create_entry(entry)
|
RegisterAgentActivity
|
Author's public key
|
Action
|
Hash of the action
|
StoreRecord
|
Hash of the action
|
Record
|
-
|
|
StoreEntry
|
Hash of the entry
|
Record
|
-
|
|
update_entry(original_action_hash, new_entry)
|
RegisterAgentActivity
|
Author's public key
|
New Action
|
Hash of the action
|
StoreRecord
|
Hash of the action
|
New Record
|
-
|
|
StoreEntry
|
Hash of the entry
|
New Record
|
-
|
|
RegisterEntryUpdate
|
Hash of the original entry
|
New action
|
Old entry is updated to new entry
|
|
RegisterRecordUpdate
|
Hash of the original action
|
New action
|
Old action is updated to new action
|
|
delete_entry(action_hash)
|
RegisterAgentActivity
|
Author's public key
|
New Action
|
Hash of the action
|
StoreRecord
|
Hash of the new action
|
New Record
|
-
|
|
RegisterEntryDelete
|
Hash of the deleted entry
|
New Action
|
Old entry deleted by new action
|
|
RegisterRecordDelete
|
Hash of the deleted action
|
New Action
|
Old action deleted by new action
|
|
create_link(base, target, tag)
|
RegisterAgentActivity
|
Author's public key
|
Action
|
Hash of the action
|
StoreRecord
|
Hash of the new action
|
Record
|
-
|
|
RegisterCreateLink
|
"Base" hash
|
Action
|
Link from the base to the target hash
|
|
delete_link(create_link_action_hash)
|
RegisterAgentActivity
|
Author's public key
|
Action
|
Hash of the action
|
StoreRecord
|
Hash of the new action
|
Record
|
-
|
|
RegisterDeleteLink
|
Hash of the deleted create link action hash
|
Action
|
Deleted link sent to tombstone
|
#[hdk_extern]
pub fn validate(op: Op) -> ExternResult<ValidateCallbackResult> {
match op.flattened::<EntryTypes, LinkTypes>()? { // "flattened" converts the complex "Op"
// structure into a much simpler "FlatOp"
FlatOp::StoreEntry(store_entry) => match store_entry {
OpEntry::CreateEntry { app_entry, action } => match app_entry { // "app_entry" is your own
// app defined EntryTypes
EntryTypes::Post(post) => match post.content.len() <= 180 { // Only posts of 180
// characters or less
// are valid
true => Ok(ValidateCallbackResult::Valid),
false => Ok(ValidateCallbackResult::Invalid(String::from("Post is too long")))
},
EntryTypes::Comment(comment) => Ok(ValidateCallbackResult::Valid),
},
OpEntry::UpdateEntry { app_entry, action, original_action_hash, original_entry_hash } =>
Ok(ValidateCallbackResult::Valid), // app_entry will be exactly the same as above
_ => Ok(ValidateCallbackResult::Valid),
},
FlatOp::StoreRecord(store_record) => match store_record {
OpRecord::CreateEntry { app_entry, action, } => Ok(ValidateCallbackResult::Valid),
OpRecord::UpdateEntry { app_entry, action, original_action_hash, original_entry_hash } =>
Ok(ValidateCallbackResult::Valid), // app_entry will be exactly the same as above
_ => Ok(ValidateCallbackResult::Valid),
},
FlatOp::RegisterUpdate(update_entry) |
FlatOp::RegisterDelete(delete_entry) |
FlatOp::RegisterCreateLink { .. } |
FlatOp::RegisterDeleteLink { .. } |
FlatOp::RegisterAgentActivity(agent_activity) => Ok(ValidateCallbackResult::Valid)
}
}
#[hdk_extern]
pub fn genesis_self_check(data: GenesisSelfCheckData) -> ExternResult<ValidateCallbackResult> {
// Check data.agent_key, data.membrane_proof
}
fn is_membrane_proof_valid(
for_agent: AgentPubKey,
membrane_proof: Option<MembraneProof>,
) -> ExternResult<ValidateCallbackResult> {
// Check that the agent is allowed to join the network
}
#[hdk_extern]
pub fn validate(op: Op) -> ExternResult<ValidateCallbackResult> { // Normal validate callback
if let FlatOp::RegisterAgentActivity(
OpActivity::CreateAgent { agent, action }
) = op.flattened::<EntryTypes, LinkTypes>()? {
let previous_action = must_get_action(action.prev_action)?; // Getting the previous record,
// which must be the
// `AgentValidationPkg`
match previous_action.action() {
Action::AgentValidationPkg(pkg) => is_membrane_proof_valid(agent, pkg.membrane_proof),
_ => Ok(ValidateCallbackResult::Invalid(
"The previous action for a `CreateAgent` action must be an `AgentValidationPkg`"
.to_string(),
))
}
}
// ... rest of the validation code
}