use hdk::prelude::*;
pub fn remove_link(
query: LinkQuery,
strategy: GetStrategy,
target: AnyLinkableHash,
) -> ExternResult<ActionHash> {
match get_links(query, strategy)?
.into_iter()
.find(|link| target == link.target)
{
Some(links) => {
// this helps with zero-arc to prefetch the hash
let _ = get(links.create_link_hash.clone(), GetOptions::network())?;
delete_link(
links.create_link_hash,
GetOptions::default().with_strategy(strategy),
)
}
None => Err(wasm_error!(WasmErrorInner::Guest(
"Link does not exist".to_string()
))),
}
}