notifications/
utils.rs

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
64
65
66
67
68
use hdk::prelude::*;
use notifications_integrity::*;

pub fn create_relaxed(entry_type: EntryTypes) -> ExternResult<()> {
	HDK.with(|h| {
		let index = ScopedEntryDefIndex::try_from(&entry_type)?;
		let vis = EntryVisibility::from(&entry_type);
		let entry = Entry::try_from(entry_type)?;

		h.borrow().create(CreateInput::new(
			index,
			vis,
			entry,
			// This is used to test many conductors thrashing creates between
			// each other so we want to avoid retries that make the test take
			// a long time.
			ChainTopOrdering::Relaxed,
		))
	})?;

	Ok(())
}

pub fn create_link_relaxed<T, E>(
	base_address: impl Into<AnyLinkableHash>,
	target_address: impl Into<AnyLinkableHash>,
	link_type: T,
	tag: impl Into<LinkTag>,
) -> ExternResult<()>
where
	ScopedLinkType: TryFrom<T, Error = E>,
	WasmError: From<E>,
{
	let ScopedLinkType {
		zome_index,
		zome_type: link_type,
	} = link_type.try_into()?;
	HDK.with(|h| {
		h.borrow().create_link(CreateLinkInput::new(
			base_address.into(),
			target_address.into(),
			zome_index,
			link_type,
			tag.into(),
			ChainTopOrdering::Relaxed,
		))
	})?;

	Ok(())
}

pub fn delete_link_relaxed(address: ActionHash) -> ExternResult<()> {
	HDK.with(|h| {
		h.borrow()
			.delete_link(DeleteLinkInput::new(address, ChainTopOrdering::Relaxed))
	})?;

	Ok(())
}

pub fn delete_relaxed(address: ActionHash) -> ExternResult<()> {
	HDK.with(|h| {
		h.borrow()
			.delete(DeleteInput::new(address, ChainTopOrdering::Relaxed))
	})?;

	Ok(())
}