Skip to content

Commit

Permalink
Merge pull request #272 from Holo-Host/2020-08-03-validate-links
Browse files Browse the repository at this point in the history
TK-02545: 2020 08 03 validate links
  • Loading branch information
thedavidmeister committed Aug 7, 2020
2 parents 53cfe42 + 0674c76 commit e773d6d
Show file tree
Hide file tree
Showing 28 changed files with 2,753 additions and 12 deletions.
20 changes: 20 additions & 0 deletions crates/hdk/src/api.rs
Expand Up @@ -43,6 +43,26 @@ macro_rules! entry_def {
}
}

impl TryFrom<&$crate::prelude::Entry> for $t {
type Error = $crate::prelude::SerializedBytesError;
fn try_from(entry: &$crate::prelude::Entry) -> Result<Self, Self::Error> {
match entry {
Entry::App(sb) => Ok(Self::try_from(sb.to_owned())?),
_ => Err($crate::prelude::SerializedBytesError::FromBytes(format!(
"{:?} is not an Entry::App so has no serialized bytes",
entry
))),
}
}
}

impl TryFrom<$crate::prelude::Entry> for $t {
type Error = $crate::prelude::SerializedBytesError;
fn try_from(entry: $crate::prelude::Entry) -> Result<Self, Self::Error> {
Self::try_from(&entry)
}
}

impl From<$t> for $crate::prelude::EntryDef {
fn from(_: $t) -> Self {
$t::entry_def()
Expand Down
2 changes: 1 addition & 1 deletion crates/hdk/src/hash_path/anchor.rs
Expand Up @@ -6,7 +6,7 @@ use holochain_wasmer_guest::*;
/// "anchor"
pub const ROOT: &str = "hdk3anchor";

#[derive(PartialEq, serde::Serialize, serde::Deserialize, Debug, SerializedBytes, Clone)]
#[derive(PartialEq, SerializedBytes, serde::Serialize, serde::Deserialize, Debug, Clone)]
pub struct Anchor {
pub anchor_type: String,
pub anchor_text: Option<String>,
Expand Down
4 changes: 1 addition & 3 deletions crates/hdk/src/hash_path/path.rs
Expand Up @@ -22,9 +22,7 @@ pub const NAME: [u8; 8] = [0x68, 0x64, 0x6b, 0x2e, 0x70, 0x61, 0x74, 0x68];

/// each path component is arbitrary bytes to be hashed together in a predictable way when the path
/// is hashed to create something that can be linked and discovered by all DHT participants
#[derive(
Clone, PartialEq, Debug, Default, serde::Deserialize, serde::Serialize, SerializedBytes,
)]
#[derive(Clone, PartialEq, Debug, Default, serde::Deserialize, serde::Serialize)]
#[repr(transparent)]
pub struct Component(#[serde(with = "serde_bytes")] Vec<u8>);

Expand Down
2 changes: 2 additions & 0 deletions crates/hdk/src/prelude.rs
Expand Up @@ -44,6 +44,8 @@ pub use holochain_zome_types::entry_def::EntryVisibility;
pub use holochain_zome_types::entry_def::RequiredValidations;
pub use holochain_zome_types::link::LinkDetails;
pub use holochain_zome_types::link::Links;
pub use holochain_zome_types::validate_link_add::ValidateLinkAddCallbackResult;
pub use holochain_zome_types::validate_link_add::ValidateLinkAddData;
pub use holochain_zome_types::zome_info::ZomeInfo;
pub use holochain_zome_types::*;
pub use std::convert::TryFrom;
13 changes: 13 additions & 0 deletions crates/holochain/src/core/ribosome.rs
Expand Up @@ -23,6 +23,9 @@ use crate::core::ribosome::guest_callback::post_commit::PostCommitInvocation;
use crate::core::ribosome::guest_callback::post_commit::PostCommitResult;
use crate::core::ribosome::guest_callback::validate::ValidateInvocation;
use crate::core::ribosome::guest_callback::validate::ValidateResult;
use crate::core::ribosome::guest_callback::validate_link_add::ValidateLinkAddHostAccess;
use crate::core::ribosome::guest_callback::validate_link_add::ValidateLinkAddInvocation;
use crate::core::ribosome::guest_callback::validate_link_add::ValidateLinkAddResult;
use crate::core::ribosome::guest_callback::validation_package::ValidationPackageInvocation;
use crate::core::ribosome::guest_callback::validation_package::ValidationPackageResult;
use crate::core::ribosome::guest_callback::CallIterator;
Expand Down Expand Up @@ -80,6 +83,7 @@ impl CallContext {
pub enum HostAccess {
ZomeCall(ZomeCallHostAccess),
Validate(ValidateHostAccess),
ValidateLinkAdd(ValidateLinkAddHostAccess),
Init(InitHostAccess),
EntryDefs(EntryDefsHostAccess),
MigrateAgent(MigrateAgentHostAccess),
Expand All @@ -92,6 +96,9 @@ impl From<&HostAccess> for HostFnAccess {
match host_access {
HostAccess::ZomeCall(zome_call_host_access) => zome_call_host_access.into(),
HostAccess::Validate(validate_host_access) => validate_host_access.into(),
HostAccess::ValidateLinkAdd(validate_link_add_host_access) => {
validate_link_add_host_access.into()
}
HostAccess::Init(init_host_access) => init_host_access.into(),
HostAccess::EntryDefs(entry_defs_host_access) => entry_defs_host_access.into(),
HostAccess::MigrateAgent(migrate_agent_host_access) => migrate_agent_host_access.into(),
Expand Down Expand Up @@ -405,6 +412,12 @@ pub trait RibosomeT: Sized {
invocation: ValidateInvocation,
) -> RibosomeResult<ValidateResult>;

fn run_validate_link_add(
&self,
access: ValidateLinkAddHostAccess,
invocation: ValidateLinkAddInvocation,
) -> RibosomeResult<ValidateLinkAddResult>;

fn call_iterator<R: 'static + RibosomeT, I: 'static + Invocation>(
&self,
access: HostAccess,
Expand Down
6 changes: 3 additions & 3 deletions crates/holochain/src/core/ribosome/error.rs
Expand Up @@ -3,7 +3,7 @@

use crate::core::state::{cascade::error::CascadeError, source_chain::SourceChainError};
use crate::core::workflow::call_zome_workflow::unsafe_call_zome_workspace::error::UnsafeCallZomeWorkspaceError;
use holo_hash::HeaderHash;
use holo_hash::AnyDhtHash;
use holochain_crypto::CryptoError;
use holochain_serialized_bytes::prelude::SerializedBytesError;
use holochain_types::dna::error::DnaError;
Expand Down Expand Up @@ -44,8 +44,8 @@ pub enum RibosomeError {
/// for example a remove link ribosome call needs to find the add link in order to infer the
/// correct base and this dependent relationship exists before even subconscious validation
/// kicks in
#[error("A mandatory element is missing, header hash: {0}")]
ElementDeps(HeaderHash),
#[error("A mandatory element is missing, dht hash: {0}")]
ElementDeps(AnyDhtHash),

/// ident
#[error(transparent)]
Expand Down
1 change: 1 addition & 0 deletions crates/holochain/src/core/ribosome/guest_callback.rs
Expand Up @@ -3,6 +3,7 @@ pub mod init;
pub mod migrate_agent;
pub mod post_commit;
pub mod validate;
pub mod validate_link_add;
pub mod validation_package;
use super::HostAccess;
use crate::core::ribosome::error::RibosomeError;
Expand Down

0 comments on commit e773d6d

Please sign in to comment.